Skip to content

Commit 428b15b

Browse files
committed
Fix a typo in GetPVarString causing the native to not work properly. Implement a regex so strings can be colored, thanks to xLuxy for the pattern. Properly cast variables inside GetVehicleParamsEx so scripts work properly.
1 parent 3ae22b0 commit 428b15b

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

amx/server/syscalls.lua

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,8 @@ function GetPVarString(amx, player, varname, outbuf, length)
783783
return 0
784784
end
785785

786-
if #value[2] < maxlength then
787-
writeMemString(amx, outbuf, value)
786+
if #value[2] < length then
787+
writeMemString(amx, outbuf, value[2])
788788
else
789789
writeMemString(amx, outbuf, string.sub(value, 0, length - 1))
790790
end
@@ -1064,13 +1064,31 @@ function SendClientMessage(amx, player, r, g, b, a, message)
10641064
message = message:gsub('/' .. samp, '/' .. mta)
10651065
end
10661066
end
1067-
outputChatBox(message, player, r, g, b)
1067+
1068+
--replace colors
1069+
message = result:gsub("(=?{[0-9A-Fa-f]*})",
1070+
function(colorMatches)
1071+
colorMatches = colorMatches:gsub("[{}]+", "") --replace the curly brackets with nothing
1072+
colorMatches = '#' .. colorMatches --Append to the beginning
1073+
return colorMatches
1074+
end)
1075+
1076+
outputChatBox(message, player, r, g, b, true)
10681077
end
10691078

10701079
function SendClientMessageToAll(amx, r, g, b, a, message)
10711080
if (amx.proc == 'OnPlayerConnect' and message:match('joined')) or (amx.proc == 'OnPlayerDisconnect' and message:match('left')) then
10721081
return
10731082
end
1083+
1084+
--replace colors
1085+
message = result:gsub("(=?{[0-9A-Fa-f]*})",
1086+
function(colorMatches)
1087+
colorMatches = colorMatches:gsub("[{}]+", "") --replace the curly brackets with nothing
1088+
colorMatches = '#' .. colorMatches --Append to the beginning
1089+
return colorMatches
1090+
end)
1091+
10741092
for i,data in pairs(g_Players) do
10751093
SendClientMessage(amx, data.elem, r, g, b, a, message)
10761094
end
@@ -1081,11 +1099,11 @@ function SendDeathMessage(amx, killer, victim, reason)
10811099
end
10821100

10831101
function SendPlayerMessageToAll(amx, sender, message)
1084-
outputChatBox(getPlayerName(sender) .. ' ' .. message, root, 255, 255, 255)
1102+
outputChatBox(getPlayerName(sender) .. ' ' .. message, root, 255, 255, 255, true)
10851103
end
10861104

10871105
function SendPlayerMessageToPlayer(amx, playerTo, playerFrom, message)
1088-
outputChatBox(getPlayerName(playerFrom) .. ' ' .. message, playerTo, 255, 255, 255)
1106+
outputChatBox(getPlayerName(playerFrom) .. ' ' .. message, playerTo, 255, 255, 255, true)
10891107
end
10901108

10911109
function SendRconCommand(amx, command)
@@ -1823,8 +1841,18 @@ function format(amx, outBuf, outBufSize, fmt, ...)
18231841
i = i - 1
18241842
end
18251843
end
1844+
18261845
fmt = fmt:gsub('(%%[%-%d%.]*)%*(%a)', '%1%2')
18271846
local result = fmt:format(unpack(args))
1847+
1848+
--replace colors
1849+
result = result:gsub("(=?{[0-9A-Fa-f]*})",
1850+
function(colorMatches)
1851+
colorMatches = colorMatches:gsub("[{}]+", "") --replace the curly brackets with nothing
1852+
colorMatches = '#' .. colorMatches --Append to the beginning
1853+
return colorMatches
1854+
end)
1855+
18281856
if #result+1 <= outBufSize then
18291857
writeMemString(amx, outBuf, result)
18301858
end
@@ -2270,13 +2298,13 @@ end
22702298
function GetVehicleParamsEx(amx, vehicle, refEngine, refLights, refAlarm, refDoors, refBonnet, refBoot, refObjective)
22712299
local vehicleID = getElemID(vehicle)
22722300

2273-
amx.memDAT[refEngine] = getVehicleEngineState(vehicle)
2274-
amx.memDAT[refLights] = getVehicleOverrideLights(vehicle) == 2 and true or false
2275-
amx.memDAT[refAlarm] = g_Vehicles[vehicleID].alarm
2276-
amx.memDAT[refDoors] = isVehicleLocked(vehicle)
2301+
amx.memDAT[refEngine] = getVehicleEngineState(vehicle) and 1 or 0 --Lua expects this to be an int, so cast it
2302+
amx.memDAT[refLights] = getVehicleOverrideLights(vehicle) == 2 and 1 or 0
2303+
amx.memDAT[refAlarm] = g_Vehicles[vehicleID].alarm and 1 or 0
2304+
amx.memDAT[refDoors] = isVehicleLocked(vehicle) and 1 or 0
22772305
amx.memDAT[refBonnet] = getVehicleDoorOpenRatio(vehicle, 0) > 0
22782306
amx.memDAT[refBoot] = getVehicleDoorOpenRatio(vehicle, 1) > 0
2279-
amx.memDAT[refObjective] = g_Vehicles[vehicleID].objective or false
2307+
amx.memDAT[refObjective] = g_Vehicles[vehicleID].objective or 0
22802308

22812309
return 1
22822310
end

0 commit comments

Comments
 (0)