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

Commit

Permalink
Fixed second match not starting after first match has ended, fixed ev…
Browse files Browse the repository at this point in the history
…ent error with parachute resource, fixed table ipairs error, fixed alive count not being propagated to players
  • Loading branch information
mtadayz committed Sep 26, 2017
1 parent b039b25 commit 4d1fad4
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 53 deletions.
84 changes: 43 additions & 41 deletions battlegrounds/gui/inventory_s.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,47 +273,49 @@ function onItemFromLootToInventory(itemName,loot)
if newAmmoAmount then
setWeaponAmmo(client,weaponID,newAmmoAmount)
end

for i, item in ipairs(lootpointData[loot]) do
if item[1] == itemName then
if item[1] == "11.43x23mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "9x18mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "9x19mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == ".303 British Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "7.62x39mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "5.56x45mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "7.62x54mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "1866 Slug" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "12 Gauge Pellet" then
refreshInventory()
refreshLoot(loot,"")
return
else
item[2] = item[2]-1

if lootpointData[loot] then
for i, item in ipairs(lootpointData[loot]) do
if item[1] == itemName then
if item[1] == "11.43x23mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "9x18mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "9x19mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == ".303 British Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "7.62x39mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "5.56x45mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "7.62x54mm Cartridge" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "1866 Slug" then
refreshInventory()
refreshLoot(loot,"")
return
elseif item[1] == "12 Gauge Pellet" then
refreshInventory()
refreshLoot(loot,"")
return
else
item[2] = item[2]-1
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion battlegrounds/handlers/client/damage_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ function onBattleGroundsPlayerDamage(attacker,weapon,bodypart,loss)
cancelEvent()
triggerServerEvent("mtabg_onBattleGroundsPlayerDamage",localPlayer,attacker,weapon,bodypart,loss)
end
addEventHandler("onClientPlayerDamage",localPlayer,onBattleGroundsPlayerDamage)
addEventHandler("onClientPlayerDamage",root,onBattleGroundsPlayerDamage)
14 changes: 7 additions & 7 deletions battlegrounds/handlers/server/damage_s.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ local finalRank = 0
function killBattleGroundsPlayer(player,killer,headshot)
if not player then player = source end
local x,y,z = getElementPosition(player)
local deadPlayerTable = {}
pedCol = false
killPed(player)
if not isElementInWater(player) then
Expand All @@ -88,7 +87,7 @@ function killBattleGroundsPlayer(player,killer,headshot)
local dimension = getElementDimension(player)
ped = createPed(skin,6000,6000,0,rotZ)
pedCol = createColSphere(6000,6000,0,1.5)
deadPlayerTable[pedCol] = {}
lootpointData[pedCol] = {}
killPed(ped)
setElementDimension(ped,dimension)
setTimer(destroyDeadPlayer,600000,1,ped,pedCol)
Expand All @@ -108,7 +107,7 @@ function killBattleGroundsPlayer(player,killer,headshot)
end
if pedCol then
for k, data in ipairs(playerDataInfo[player]) do
table.insert(deadPlayerTable[pedCol],{data[2],data[3]})
table.insert(lootpointData[pedCol],{data[2],data[3]})
end
end
setTimer(setElementPosition,500,1,player,6000,6000,0)
Expand Down Expand Up @@ -139,8 +138,8 @@ function killBattleGroundsPlayer(player,killer,headshot)
homeScreenDimension = homeScreenDimension+1
finalRank = gameCache["playerAmount"]
gameCache["playerAmount"] = gameCache["playerAmount"]-1
setElementData(player,"participatingInGame",false)
if isElement(killer) then
setElementData(player,"participatingInGame",false)
checkForWinner(killer)
for i, players in ipairs(getElementsByType("player")) do
if getElementData(players,"participatingInGame") then
Expand All @@ -149,16 +148,17 @@ function killBattleGroundsPlayer(player,killer,headshot)
end
triggerClientEvent(player,"mtabg_showEndscreen",player,finalRank,homeScreenDimension)
else
if gameCache["playerAmount"] > 1 then
if gameCache["playerAmount"] <= 1 then
setElementData(player,"participatingInGame",false)
for i, players in ipairs(getElementsByType("player")) do
if getElementData(players,"participatingInGame") then
outputSideChat("Player "..getPlayerName(player).." has died - "..gameCache["playerAmount"].." left",players,255,255,255)
checkForWinner(players)
end
end
else
for i, players in ipairs(getElementsByType("player")) do
if getElementData(players,"participatingInGame") then
checkForWinner(players)
outputSideChat("Player "..getPlayerName(player).." has died - "..gameCache["playerAmount"].." left",players,255,255,255)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions battlegrounds/handlers/server/permissions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ addEventHandler("onPlayerCommand",root,restrictCommands)

local function stopExternalParachuteResource()
local parachuteResource = getResourceFromName("parachute")
local realParachuteR = getResourceFromName("parachutes")
if parachuteResource and getResourceState(parachuteResource) == "running" then
stopResource(parachuteResource)
end
if getResourceState(realParachuteR) == "running" then
restartResource(parachuteResource)
end
end
addEventHandler("onResourceStart",resourceRoot,stopExternalParachuteResource)
2 changes: 1 addition & 1 deletion battlegrounds/hud/hud_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ addEvent("mtabg_onClientBattleGroundsAnnounceMatchStart",true)
addEventHandler("mtabg_onClientBattleGroundsAnnounceMatchStart",root,onClientBattleGroundsAnnounceMatchStart)

function onClientBattleGroundsSetAliveCount(amount)
playerAmount = tonumber(amount)
playerAmount = amount
end
addEvent("mtabg_onClientBattleGroundsSetAliveCount",true)
addEventHandler("mtabg_onClientBattleGroundsSetAliveCount",root,onClientBattleGroundsSetAliveCount)
Expand Down
16 changes: 13 additions & 3 deletions battlegrounds/init/spawn_players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,23 @@ function startCountDown(forcedStart, quickTick)
if gameCache["status"] then return end
if isTimer(spawnItemsTimer) then killTimer(spawnItemsTimer) end
gameCache["playingField"] = 0
if gameCache["initialPlayerAmount"] < 1 and not forcedStart then
if gameCache["initialPlayerAmount"] < 2 and not forcedStart then
for i, players in ipairs(getElementsByType("player")) do
if getElementData(players,"inLobby") then
triggerClientEvent(players,"mtabg_onClientBattleGroundsAnnounceMatchStart",players,"More players needed")
end
end
return
end
if forcedStart then
gameCache["initialPlayerAmount"] = 0
for i, players in ipairs(getElementsByType("player")) do
if getElementData(players,"inLobby") then
gameCache["initialPlayerAmount"] = gameCache["initialPlayerAmount"]+1
triggerClientEvent(players,"mtabg_onClientBattleGroundsSetStatus",players,false,gameCache["initialPlayerAmount"])
end
end
end
spawnItemsTimer = setTimer(function()
if firstTimeLoot then
refreshLootSpots()
Expand Down Expand Up @@ -199,7 +208,7 @@ function startCountDown(forcedStart, quickTick)
end
end
elseif gameCache["countdown"] == 0 then
if gameCache["initialPlayerAmount"] > 1 then
if gameCache["initialPlayerAmount"] > 1 or forcedStart then
startGame()
firstTimeLoot = true
killTimer(spawnItemsTimer)
Expand Down Expand Up @@ -247,7 +256,7 @@ function startGame()
attachElements(playerCol,player,0,0,0)
setElementData(player,"participatingInGame",true)
gameCache["playerAmount"] = gameCache["initialPlayerAmount"]
triggerClientEvent(player,"mtabg_onClientBattleGroundsSetStatus",player,gameCache["playerAmount"],true,gameCache["countdown"])
triggerClientEvent(player,"mtabg_onClientBattleGroundsSetAliveCount",player,gameCache["playerAmount"])
setElementData(player,"inLobby",false)
giveWeapon(player,46,1,true)
setPedWeaponSlot(player,11)
Expand Down Expand Up @@ -329,6 +338,7 @@ function resetGameCache()
gameCache["playerAmount"] = 0
gameCache["countdown"] = 300
gameCache["playingField"] = 0 -- = Dimension (Dimension 500 is reserved for home screen!)
outputDebugString("MTA:BG Game Cache has been reset")
end
addEvent("mtabg_resetGameCache",true)
addEventHandler("mtabg_resetGameCache",root,resetGameCache)
Binary file modified parachutes.zip
Binary file not shown.

0 comments on commit 4d1fad4

Please sign in to comment.