From 8f45376baff6de6c9b1f169062040d72c1d63058 Mon Sep 17 00:00:00 2001 From: Nexius Date: Mon, 17 Nov 2025 12:30:38 +0300 Subject: [PATCH 1/3] Improve validations, add missed ones --- amx/client/client.lua | 24 +++++++++++++----------- amx/server/natives/a_mta.lua | 24 +++++++++++++----------- amx/server/natives/a_objects.lua | 2 +- amx/server/natives/a_samp.lua | 2 +- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/amx/client/client.lua b/amx/client/client.lua index 7f8115e..f1be058 100644 --- a/amx/client/client.lua +++ b/amx/client/client.lua @@ -72,12 +72,12 @@ function destroyGlobalElements() DestroyMenu(id) end - for id, textdraw in pairs(g_TextDraws) do - destroyTextDraw(textdraw) + for id, textlabel in pairs(g_TextLabels) do + Delete3DTextLabel(textlabel) end - for id, textlabel in pairs(g_TextLabels) do - destroyTextLabel(textlabel) + for id, textdraw in pairs(g_TextDraws) do + destroyTextDraw(textdraw) end table.each(g_Blips, destroyElement) @@ -473,7 +473,7 @@ end function CreatePlayerObject(objID, model, x, y, z, rX, rY, rZ) g_PlayerObjects[objID] = createObject(model, x, y, z, rX, rY, rZ) - if g_PlayerObjects[objID] == false then + if not g_PlayerObjects[objID] then g_PlayerObjects[objID] = createObject(1337, x, y, z, rX, rY, rZ) -- Create a dummy object anyway since createobject can also be used to make camera attachments setElementAlpha(g_PlayerObjects[objID], 0) setElementCollisionsEnabled(g_PlayerObjects[objID], false) @@ -491,6 +491,8 @@ end function MovePlayerObject(objID, x, y, z, speed, rX, rY, rZ) local obj = g_PlayerObjects[objID] + if not obj then return 0 end + local distance = getDistanceBetweenPoints3D(x, y, z, getElementPosition(obj)) local time = distance / speed * 1000 @@ -697,7 +699,7 @@ function SetVehicleParamsForPlayer(vehicle, isObjective, doorsLocked) end local vehInfo = g_Vehicles[vehID] if isObjective then - if vehInfo.blip then + if isElement(vehInfo.blip) then destroyElement(vehInfo.blip) vehInfo.blip = nil end @@ -1874,7 +1876,7 @@ function sendWeapons() end function RemovePlayerMapIcon(blipID) - if g_Blips[blipID] then + if isElement(g_Blips[blipID]) then destroyElement(g_Blips[blipID]) g_Blips[blipID] = nil return true @@ -1883,7 +1885,7 @@ function RemovePlayerMapIcon(blipID) end function SetPlayerMapIcon(blipID, x, y, z, type, r, g, b, a, style) - if g_Blips[blipID] then + if isElement(g_Blips[blipID]) then destroyElement(g_Blips[blipID]) g_Blips[blipID] = nil end @@ -1981,7 +1983,7 @@ function TogglePlayerClock(toggle) end function createListDialog(titleText, message, button1txt, button2txt) - if listWindow then + if isElement(listWindow) then removeEventHandler('onClientGUIClick', getRootElement(), OnListDialogButton1Click) -- Remove handlers so they are not registered more than once removeEventHandler('onClientGUIClick', getRootElement(), OnListDialogButton2Click) destroyElement(listWindow) -- Assuming listWindow is the parent of everything, it should remove the whole hierarchy @@ -2019,7 +2021,7 @@ function createListDialog(titleText, message, button1txt, button2txt) end function createInputDialog(titleText, message, button1txt, button2txt) - if inputWindow then + if isElement(inputWindow) then removeEventHandler('onClientGUIClick', getRootElement(), OnInputDialogButton1Click) -- Remove handlers so they are not registered more than once removeEventHandler('onClientGUIClick', getRootElement(), OnInputDialogButton2Click) destroyElement(inputWindow) -- Assuming inputWindow is the parent of everything, it should remove the whole hierarchy @@ -2053,7 +2055,7 @@ function createInputDialog(titleText, message, button1txt, button2txt) end function createMessageDialog(titleText, message, button1txt, button2txt) - if msgWindow then + if isElement(msgWindow) then removeEventHandler('onClientGUIClick', getRootElement(), OnMessageDialogButton1Click) -- Remove handlers so they are not registered more than once removeEventHandler('onClientGUIClick', getRootElement(), OnMessageDialogButton2Click) destroyElement(msgWindow) -- Assuming msgWindow is the parent of everything, it should remove the whole hierarchy diff --git a/amx/server/natives/a_mta.lua b/amx/server/natives/a_mta.lua index a79bad4..493c903 100644 --- a/amx/server/natives/a_mta.lua +++ b/amx/server/natives/a_mta.lua @@ -374,10 +374,11 @@ end function GetMarkerIcon(amx, marker) local icon = getMarkerIcon(marker) - if icon == false then return -1 end - if icon == 'none' then return 0 end - if icon == 'arrow' then return 1 end - if icon == 'finish' then return 2 end + if icon then + if icon == 'none' then return 0 end + if icon == 'arrow' then return 1 end + if icon == 'finish' then return 2 end + end return -1 end @@ -395,7 +396,7 @@ function GetMarkerTarget(amx, marker, refX, refY, refZ) return false end local x, y, z = getMarkerTarget(marker) - if x == false then return false end + if not x then return false end writeMemFloat(amx, refX, x) writeMemFloat(amx, refY, y) writeMemFloat(amx, refZ, z) @@ -404,12 +405,13 @@ end function GetMarkerType(amx, marker) local mtype = getMarkerType(marker) - if mtype == false then return -1 end - if mtype == 'checkpoint' then return 0 end - if mtype == 'ring' then return 1 end - if mtype == 'cylinder' then return 2 end - if mtype == 'arrow' then return 3 end - if mtype == 'corona' then return 4 end + if mtype then + if mtype == 'checkpoint' then return 0 end + if mtype == 'ring' then return 1 end + if mtype == 'cylinder' then return 2 end + if mtype == 'arrow' then return 3 end + if mtype == 'corona' then return 4 end + end return -1 end diff --git a/amx/server/natives/a_objects.lua b/amx/server/natives/a_objects.lua index 8052718..3182a0e 100644 --- a/amx/server/natives/a_objects.lua +++ b/amx/server/natives/a_objects.lua @@ -1,6 +1,6 @@ function CreateObject(amx, model, x, y, z, rX, rY, rZ, drawDistance) local obj = createObject(model, x, y, z, rX, rY, rZ) - if obj == false then + if not obj then obj = createObject(1337, x, y, z, rX, rY, rZ) -- Create a dummy object anyway since createobject can also be used to make camera attachments setElementAlpha(obj, 0) setElementCollisionsEnabled(obj, false) diff --git a/amx/server/natives/a_samp.lua b/amx/server/natives/a_samp.lua index 7e94be2..da4cd67 100644 --- a/amx/server/natives/a_samp.lua +++ b/amx/server/natives/a_samp.lua @@ -336,7 +336,7 @@ end function AddStaticVehicleEx(amx, model, x, y, z, angle, color1, color2, respawnDelay, addSiren) local vehicle = createVehicle(model, x, y, z, 0, 0, angle) - if (vehicle == false) then + if not vehicle then return INVALID_VEHICLE_ID end From a088229e0c5a9fe52ab63a08bbeabd0aa01b1120 Mon Sep 17 00:00:00 2001 From: Nexius Date: Mon, 17 Nov 2025 12:32:29 +0300 Subject: [PATCH 2/3] Switch weapon to 0 when spawn and remove unused weapon function --- amx/server/events.lua | 1 + amx/server/util.lua | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/amx/server/events.lua b/amx/server/events.lua index c5a64ac..6ef7704 100644 --- a/amx/server/events.lua +++ b/amx/server/events.lua @@ -296,6 +296,7 @@ function spawnPlayerBySelectedClass(player, x, y, z, r) giveWeapon(player, weapon[1], weapon[2], true) end end + setPedWeaponSlot(player, 0) clientCall(player, 'destroyClassSelGUI') setPlayerHudComponentVisible(player, 'area_name', g_ShowZoneNames) if playerdata.blip then diff --git a/amx/server/util.lua b/amx/server/util.lua index 2271ae0..1df4dd7 100644 --- a/amx/server/util.lua +++ b/amx/server/util.lua @@ -343,15 +343,6 @@ function isPedDead(player) return x == 0 and y == 0 and z == 0 end -function giveWeapons(player, weapons, currentslot) - for slot, weapon in pairs(weapons) do - giveWeapon(player, weapon.id, weapon.ammo) - end - if currentslot then - setPedWeaponSlot(player, currentslot) - end -end - function isTimer(timer) return timer and table.find(getTimers(), timer) and true end From 20779e2e8b92343ae86c939e7c84faadf6600df7 Mon Sep 17 00:00:00 2001 From: Nexius Date: Mon, 17 Nov 2025 23:28:32 +0300 Subject: [PATCH 3/3] Correct behavior when /votemap reloads amx script --- amx/client/client.lua | 6 ++++++ amx/server/events.lua | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/amx/client/client.lua b/amx/client/client.lua index f1be058..5c92228 100644 --- a/amx/client/client.lua +++ b/amx/client/client.lua @@ -139,6 +139,7 @@ function startClassSelection(classInfo) addEventHandler('onClientGUIClick', g_ClassSelectionInfo.gui.btnRight, ClassSelRight) addEventHandler('onClientGUIClick', g_ClassSelectionInfo.gui.btnSpawn, ClassSelSpawn) showCursor(true) + removeEventHandler('onClientRender', root, renderClassSelText) addEventHandler('onClientRender', root, renderClassSelText) end @@ -155,6 +156,10 @@ function ClassSelSpawn() end function renderClassSelText() + if not g_ClassSelectionInfo then + return + end + drawShadowText(g_AMXVersion, 20, screenHeight - 170, tocolor(39, 171, 250), 1, 'default-bold', 1, 230) drawShadowText('Use left and right arrow keys to select class.', 20, screenHeight - 150, tocolor(240, 240, 240)) drawShadowText('Press SHIFT when ready to spawn.', 20, screenHeight - 136, tocolor(240, 240, 240)) @@ -162,6 +167,7 @@ function renderClassSelText() if not g_ClassSelectionInfo[0] or not g_ClassSelectionInfo.selectedclass then return end + drawShadowText('Class ' .. g_ClassSelectionInfo.selectedclass .. ' weapons:', 20, screenHeight - 110, tocolor(240, 240, 240)) local weapon, ammo, linenum, line linenum = 0 diff --git a/amx/server/events.lua b/amx/server/events.lua index 6ef7704..a557d69 100644 --- a/amx/server/events.lua +++ b/amx/server/events.lua @@ -24,6 +24,7 @@ function gameModeInit(player) ShowPlayerMarker(false, player, g_PlayerMarkersMode) setPlayerHudComponentVisible(player, 'area_name', g_ShowZoneNames) setPlayerHudComponentVisible(player, 'vehicle_name', false) -- SA-MP doesn't show vehicle names when entering vehicles + setPlayerNametagShowing(player, false) SetPlayerColor(false, player, r, g, b) setElementData(player, 'Score', 0) toggleAllControls(player, false, true, false) @@ -128,7 +129,6 @@ function joinHandler(player) procCallOnAll('OnPlayerConnect', playerID) end - setPlayerNametagShowing(player, false) end addEventHandler('onPlayerJoin', root, joinHandler)