Skip to content

Commit 6173e73

Browse files
committed
Decouple pickups and remove some getElemAmx usage
1 parent 7a0b640 commit 6173e73

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

amx/server/amx.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ function loadAMX(fileName, res)
120120

121121
g_LoadedAMXs[amx.name] = amx
122122

123-
amx.pickups = {}
124123
amx.objects = {}
125124
amx.playerobjects = {}
126125
amx.timers = {}
@@ -166,7 +165,13 @@ function destroyGlobalElements()
166165
if vehinfo.respawntimer then
167166
killTimer(vehinfo.respawntimer)
168167
vehinfo.respawntimer = nil
169-
removeElem(g_Vehicles, vehinfo.elem)
168+
end
169+
end
170+
171+
for i, elemtype in ipairs({g_Vehicles, g_Pickups}) do
172+
for id, data in pairs(elemtype) do
173+
removeElem(elemtype, data.elem)
174+
destroyElement(data.elem)
170175
end
171176
end
172177
end
@@ -178,13 +183,14 @@ function unloadAMX(amx, notifyClient)
178183
procCallInternal(amx, 'OnGameModeExit')
179184
fadeCamera(root, false, 0)
180185
ShowPlayerMarkers(amx, false)
186+
destroyGlobalElements()
181187
elseif amx.type == 'filterscript' then
182188
procCallInternal(amx, 'OnFilterScriptExit')
183189
end
184190

185191
amxUnload(amx.cptr)
186192

187-
for i,elemtype in ipairs({'pickups', 'objects', 'gangzones','bots','markers','textlabels','textdraws'}) do
193+
for i,elemtype in ipairs({'objects', 'gangzones','bots','markers','textlabels','textdraws'}) do
188194
for id,data in pairs(amx[elemtype]) do
189195
removeElem(amx, elemtype, data.elem)
190196
destroyElement(data.elem)

amx/server/events.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ addEventHandler('onVehicleEnter', root,
427427
addEventHandler('onVehicleStartEnter', root,
428428
function(player, seat, jacked)
429429
local vehID = getElemID(source)
430-
local amx = getElemAMX(source)
431-
if not amx then
430+
if not vehID then
432431
return
433432
end
434433
if isPed(player) then
@@ -437,7 +436,7 @@ addEventHandler('onVehicleStartEnter', root,
437436
return
438437
end
439438
local playerID = getElemID(player)
440-
procCallInternal(amx, 'OnPlayerEnterVehicle', playerID, vehID, seat ~= 0 and 1 or 0)
439+
procCallOnAll('OnPlayerEnterVehicle', playerID, vehID, seat ~= 0 and 1 or 0)
441440
end
442441
)
443442

@@ -471,9 +470,8 @@ addEventHandler('onVehicleExit', root,
471470

472471
addEventHandler('onVehicleStartExit', root,
473472
function(player, seat, jacked, door)
474-
local amx = getElemAMX(source)
475473
local vehID = getElemID(source)
476-
if not amx then
474+
if not vehID then
477475
return
478476
end
479477

@@ -509,9 +507,8 @@ addEventHandler('onVehicleExplode', root,
509507

510508
addEventHandler('onVehicleDamage', root,
511509
function(loss)
512-
local amx = getElemAMX(source)
513510
local vehID = getElemID(source)
514-
if not amx then
511+
if not vehID then
515512
return
516513
end
517514

@@ -593,8 +590,7 @@ addEventHandler('onPickupUse', root,
593590
return
594591
end
595592

596-
local amx = getElemAMX(pickup)
597-
procCallInternal(amx, 'OnPlayerPickUpPickup', getElemID(player), getElemID(pickup))
593+
procCallOnAll('OnPlayerPickUpPickup', getElemID(player), getElemID(pickup))
598594

599595
if model == 370 then
600596
-- Jetpack pickup

amx/server/syscalls.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ function AddPlayerClothes(amx, player, type, index)
201201
end
202202

203203
local function housePickup()
204-
local amx = getElemAMX(source)
205-
procCallInternal(amx, 'OnPlayerPickUpPickup', getElemID(player), getElemID(source))
204+
procCallOnAll('OnPlayerPickUpPickup', getElemID(player), getElemID(source))
206205
cancelEvent()
207206
end
208207
function AddStaticPickup(amx, model, type, x, y, z)
@@ -234,7 +233,7 @@ function AddStaticPickup(amx, model, type, x, y, z)
234233
-- house pickups don't disappear on pickup
235234
addEventHandler('onPickupUse', pickup, housePickup, false)
236235
end
237-
return addElem(amx, 'pickups', pickup)
236+
return addElem(g_Pickups, pickup)
238237
end
239238

240239
function AddStaticVehicle(amx, model, x, y, z, angle, color1, color2)
@@ -422,7 +421,7 @@ function DestroyObject(amx, object)
422421
end
423422

424423
function DestroyPickup(amx, pickup)
425-
removeElem(amx, 'pickups', pickup)
424+
removeElem(g_Pickups, pickup)
426425
destroyElement(pickup)
427426
end
428427

0 commit comments

Comments
 (0)