Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.

Commit 4d1fad4

Browse files
committed
Fixed second match not starting after first match has ended, fixed event error with parachute resource, fixed table ipairs error, fixed alive count not being propagated to players
1 parent b039b25 commit 4d1fad4

7 files changed

Lines changed: 69 additions & 53 deletions

File tree

battlegrounds/gui/inventory_s.lua

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -273,47 +273,49 @@ function onItemFromLootToInventory(itemName,loot)
273273
if newAmmoAmount then
274274
setWeaponAmmo(client,weaponID,newAmmoAmount)
275275
end
276-
277-
for i, item in ipairs(lootpointData[loot]) do
278-
if item[1] == itemName then
279-
if item[1] == "11.43x23mm Cartridge" then
280-
refreshInventory()
281-
refreshLoot(loot,"")
282-
return
283-
elseif item[1] == "9x18mm Cartridge" then
284-
refreshInventory()
285-
refreshLoot(loot,"")
286-
return
287-
elseif item[1] == "9x19mm Cartridge" then
288-
refreshInventory()
289-
refreshLoot(loot,"")
290-
return
291-
elseif item[1] == ".303 British Cartridge" then
292-
refreshInventory()
293-
refreshLoot(loot,"")
294-
return
295-
elseif item[1] == "7.62x39mm Cartridge" then
296-
refreshInventory()
297-
refreshLoot(loot,"")
298-
return
299-
elseif item[1] == "5.56x45mm Cartridge" then
300-
refreshInventory()
301-
refreshLoot(loot,"")
302-
return
303-
elseif item[1] == "7.62x54mm Cartridge" then
304-
refreshInventory()
305-
refreshLoot(loot,"")
306-
return
307-
elseif item[1] == "1866 Slug" then
308-
refreshInventory()
309-
refreshLoot(loot,"")
310-
return
311-
elseif item[1] == "12 Gauge Pellet" then
312-
refreshInventory()
313-
refreshLoot(loot,"")
314-
return
315-
else
316-
item[2] = item[2]-1
276+
277+
if lootpointData[loot] then
278+
for i, item in ipairs(lootpointData[loot]) do
279+
if item[1] == itemName then
280+
if item[1] == "11.43x23mm Cartridge" then
281+
refreshInventory()
282+
refreshLoot(loot,"")
283+
return
284+
elseif item[1] == "9x18mm Cartridge" then
285+
refreshInventory()
286+
refreshLoot(loot,"")
287+
return
288+
elseif item[1] == "9x19mm Cartridge" then
289+
refreshInventory()
290+
refreshLoot(loot,"")
291+
return
292+
elseif item[1] == ".303 British Cartridge" then
293+
refreshInventory()
294+
refreshLoot(loot,"")
295+
return
296+
elseif item[1] == "7.62x39mm Cartridge" then
297+
refreshInventory()
298+
refreshLoot(loot,"")
299+
return
300+
elseif item[1] == "5.56x45mm Cartridge" then
301+
refreshInventory()
302+
refreshLoot(loot,"")
303+
return
304+
elseif item[1] == "7.62x54mm Cartridge" then
305+
refreshInventory()
306+
refreshLoot(loot,"")
307+
return
308+
elseif item[1] == "1866 Slug" then
309+
refreshInventory()
310+
refreshLoot(loot,"")
311+
return
312+
elseif item[1] == "12 Gauge Pellet" then
313+
refreshInventory()
314+
refreshLoot(loot,"")
315+
return
316+
else
317+
item[2] = item[2]-1
318+
end
317319
end
318320
end
319321
end

battlegrounds/handlers/client/damage_c.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ function onBattleGroundsPlayerDamage(attacker,weapon,bodypart,loss)
1111
cancelEvent()
1212
triggerServerEvent("mtabg_onBattleGroundsPlayerDamage",localPlayer,attacker,weapon,bodypart,loss)
1313
end
14-
addEventHandler("onClientPlayerDamage",localPlayer,onBattleGroundsPlayerDamage)
14+
addEventHandler("onClientPlayerDamage",root,onBattleGroundsPlayerDamage)

battlegrounds/handlers/server/damage_s.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ local finalRank = 0
7777
function killBattleGroundsPlayer(player,killer,headshot)
7878
if not player then player = source end
7979
local x,y,z = getElementPosition(player)
80-
local deadPlayerTable = {}
8180
pedCol = false
8281
killPed(player)
8382
if not isElementInWater(player) then
@@ -88,7 +87,7 @@ function killBattleGroundsPlayer(player,killer,headshot)
8887
local dimension = getElementDimension(player)
8988
ped = createPed(skin,6000,6000,0,rotZ)
9089
pedCol = createColSphere(6000,6000,0,1.5)
91-
deadPlayerTable[pedCol] = {}
90+
lootpointData[pedCol] = {}
9291
killPed(ped)
9392
setElementDimension(ped,dimension)
9493
setTimer(destroyDeadPlayer,600000,1,ped,pedCol)
@@ -108,7 +107,7 @@ function killBattleGroundsPlayer(player,killer,headshot)
108107
end
109108
if pedCol then
110109
for k, data in ipairs(playerDataInfo[player]) do
111-
table.insert(deadPlayerTable[pedCol],{data[2],data[3]})
110+
table.insert(lootpointData[pedCol],{data[2],data[3]})
112111
end
113112
end
114113
setTimer(setElementPosition,500,1,player,6000,6000,0)
@@ -139,8 +138,8 @@ function killBattleGroundsPlayer(player,killer,headshot)
139138
homeScreenDimension = homeScreenDimension+1
140139
finalRank = gameCache["playerAmount"]
141140
gameCache["playerAmount"] = gameCache["playerAmount"]-1
142-
setElementData(player,"participatingInGame",false)
143141
if isElement(killer) then
142+
setElementData(player,"participatingInGame",false)
144143
checkForWinner(killer)
145144
for i, players in ipairs(getElementsByType("player")) do
146145
if getElementData(players,"participatingInGame") then
@@ -149,16 +148,17 @@ function killBattleGroundsPlayer(player,killer,headshot)
149148
end
150149
triggerClientEvent(player,"mtabg_showEndscreen",player,finalRank,homeScreenDimension)
151150
else
152-
if gameCache["playerAmount"] > 1 then
151+
if gameCache["playerAmount"] <= 1 then
152+
setElementData(player,"participatingInGame",false)
153153
for i, players in ipairs(getElementsByType("player")) do
154154
if getElementData(players,"participatingInGame") then
155-
outputSideChat("Player "..getPlayerName(player).." has died - "..gameCache["playerAmount"].." left",players,255,255,255)
155+
checkForWinner(players)
156156
end
157157
end
158158
else
159159
for i, players in ipairs(getElementsByType("player")) do
160160
if getElementData(players,"participatingInGame") then
161-
checkForWinner(players)
161+
outputSideChat("Player "..getPlayerName(player).." has died - "..gameCache["playerAmount"].." left",players,255,255,255)
162162
end
163163
end
164164
end

battlegrounds/handlers/server/permissions.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ addEventHandler("onPlayerCommand",root,restrictCommands)
1919

2020
local function stopExternalParachuteResource()
2121
local parachuteResource = getResourceFromName("parachute")
22+
local realParachuteR = getResourceFromName("parachutes")
2223
if parachuteResource and getResourceState(parachuteResource) == "running" then
2324
stopResource(parachuteResource)
2425
end
26+
if getResourceState(realParachuteR) == "running" then
27+
restartResource(parachuteResource)
28+
end
2529
end
2630
addEventHandler("onResourceStart",resourceRoot,stopExternalParachuteResource)

battlegrounds/hud/hud_c.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ addEvent("mtabg_onClientBattleGroundsAnnounceMatchStart",true)
260260
addEventHandler("mtabg_onClientBattleGroundsAnnounceMatchStart",root,onClientBattleGroundsAnnounceMatchStart)
261261

262262
function onClientBattleGroundsSetAliveCount(amount)
263-
playerAmount = tonumber(amount)
263+
playerAmount = amount
264264
end
265265
addEvent("mtabg_onClientBattleGroundsSetAliveCount",true)
266266
addEventHandler("mtabg_onClientBattleGroundsSetAliveCount",root,onClientBattleGroundsSetAliveCount)

battlegrounds/init/spawn_players.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,23 @@ function startCountDown(forcedStart, quickTick)
132132
if gameCache["status"] then return end
133133
if isTimer(spawnItemsTimer) then killTimer(spawnItemsTimer) end
134134
gameCache["playingField"] = 0
135-
if gameCache["initialPlayerAmount"] < 1 and not forcedStart then
135+
if gameCache["initialPlayerAmount"] < 2 and not forcedStart then
136136
for i, players in ipairs(getElementsByType("player")) do
137137
if getElementData(players,"inLobby") then
138138
triggerClientEvent(players,"mtabg_onClientBattleGroundsAnnounceMatchStart",players,"More players needed")
139139
end
140140
end
141141
return
142142
end
143+
if forcedStart then
144+
gameCache["initialPlayerAmount"] = 0
145+
for i, players in ipairs(getElementsByType("player")) do
146+
if getElementData(players,"inLobby") then
147+
gameCache["initialPlayerAmount"] = gameCache["initialPlayerAmount"]+1
148+
triggerClientEvent(players,"mtabg_onClientBattleGroundsSetStatus",players,false,gameCache["initialPlayerAmount"])
149+
end
150+
end
151+
end
143152
spawnItemsTimer = setTimer(function()
144153
if firstTimeLoot then
145154
refreshLootSpots()
@@ -199,7 +208,7 @@ function startCountDown(forcedStart, quickTick)
199208
end
200209
end
201210
elseif gameCache["countdown"] == 0 then
202-
if gameCache["initialPlayerAmount"] > 1 then
211+
if gameCache["initialPlayerAmount"] > 1 or forcedStart then
203212
startGame()
204213
firstTimeLoot = true
205214
killTimer(spawnItemsTimer)
@@ -247,7 +256,7 @@ function startGame()
247256
attachElements(playerCol,player,0,0,0)
248257
setElementData(player,"participatingInGame",true)
249258
gameCache["playerAmount"] = gameCache["initialPlayerAmount"]
250-
triggerClientEvent(player,"mtabg_onClientBattleGroundsSetStatus",player,gameCache["playerAmount"],true,gameCache["countdown"])
259+
triggerClientEvent(player,"mtabg_onClientBattleGroundsSetAliveCount",player,gameCache["playerAmount"])
251260
setElementData(player,"inLobby",false)
252261
giveWeapon(player,46,1,true)
253262
setPedWeaponSlot(player,11)
@@ -329,6 +338,7 @@ function resetGameCache()
329338
gameCache["playerAmount"] = 0
330339
gameCache["countdown"] = 300
331340
gameCache["playingField"] = 0 -- = Dimension (Dimension 500 is reserved for home screen!)
341+
outputDebugString("MTA:BG Game Cache has been reset")
332342
end
333343
addEvent("mtabg_resetGameCache",true)
334344
addEventHandler("mtabg_resetGameCache",root,resetGameCache)

parachutes.zip

46 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)