Skip to content

Commit 44053e2

Browse files
authored
Race pickup respawn fix (PR #306)
1 parent 458b9fe commit 44053e2

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

[gamemodes]/[race]/race/race_client.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ function initRace(vehicle, checkpoints, objects, pickups, mapoptions, ranked, du
218218
for k,v in pairs(pickup) do
219219
g_Pickups[colshape][k] = v
220220
end
221-
g_Pickups[colshape].load = true
221+
local isLoaded = not pickup.isRespawning
222+
g_Pickups[colshape].load = isLoaded
222223
if g_Pickups[colshape].type == 'vehiclechange' then
223224
g_Pickups[colshape].label = dxText:create(getVehicleNameFromModel(g_Pickups[colshape].vehicle), 0.5, 0.5)
224225
g_Pickups[colshape].label:color(255, 255, 255, 0)

[gamemodes]/[race]/race/race_server.lua

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ g_Pickups = {} -- { i = { position={x, y, z}, type=type, vehicle=vehicleID, p
1919
g_Players = {} -- { i = player }
2020
g_Vehicles = {} -- { player = vehicle }
2121

22-
local unloadedPickups = {}
2322

2423

2524
addEventHandler('onPlayerJoin', g_Root,
@@ -659,10 +658,10 @@ addEventHandler('onPlayerPickUpRacePickupInternal', g_Root,
659658
local pickup = g_Pickups[table.find(g_Pickups, 'id', pickupID)]
660659
local vehicle = g_Vehicles[source]
661660
if not pickup or not vehicle then return end
662-
if respawntime and tonumber(respawntime) >= 50 then
663-
table.insert(unloadedPickups, pickupID)
664-
clientCall(g_Root, 'unloadPickup', pickupID)
661+
if respawntime and tonumber(respawntime) >= 50 and not pickup.isRespawning then
662+
pickup.isRespawning = true
665663
TimerManager.createTimerFor("map"):setTimer(ServerLoadPickup, tonumber(respawntime), 1, pickupID)
664+
clientCall(g_Root, 'unloadPickup', pickupID)
666665
end
667666
if pickup.type == 'nitro' then
668667
addVehicleUpgrade(vehicle, 1010)
@@ -680,7 +679,8 @@ addEventHandler('onPlayerPickUpRacePickupInternal', g_Root,
680679
)
681680

682681
function ServerLoadPickup(pickupID)
683-
table.removevalue(unloadedPickups, pickupID)
682+
local pickup = g_Pickups[table.find(g_Pickups, 'id', pickupID)]
683+
pickup.isRespawning = nil
684684
clientCall(g_Root, 'loadPickup', pickupID)
685685
end
686686

@@ -744,7 +744,6 @@ function unloadAll()
744744
g_Checkpoints = {}
745745
g_Objects = {}
746746
g_Pickups = {}
747-
unloadedPickups = {}
748747
if g_CurrentRaceMode then
749748
g_CurrentRaceMode:destroy()
750749
end
@@ -1009,10 +1008,6 @@ addEventHandler('onNotifyPlayerReady', g_Root,
10091008
function()
10101009
if checkClient( false, source, 'onNotifyPlayerReady' ) then return end
10111010
setPlayerReady( source )
1012-
for i, pickupID in ipairs(unloadedPickups) do
1013-
-- outputDebugString(getPlayerName(source).." unload "..tostring(pickupID))
1014-
clientCall(source, "unloadPickup", pickupID )
1015-
end
10161011
end
10171012
)
10181013

0 commit comments

Comments
 (0)