freudo Posted August 31, 2017 Posted August 31, 2017 If the remaining players have the same team, I want to end the game. Can you help me? This code only one player send to winner element. if #game[gameID].players <= 1 then endGame(gameID, game[gameID].players[1]) end I wrote this code, but I'm not sure. if game[gameID].players and getElementData(game[gameID].players, "gang") then endGame(gameID, game[gameID].players) end Thanks.
aka Blue Posted August 31, 2017 Posted August 31, 2017 (edited) Loop game[gameID].players and check the team of every player. If is the same, execute endGame. Edited August 31, 2017 by aka Blue
freudo Posted August 31, 2017 Author Posted August 31, 2017 local playerGame = getElementData(source, "player:game") or false if playerGame and playerGame[1] then local gameID = playerGame[1] for k,v in ipairs(game[gameID].players) do if v == source then table.remove(game[gameID].players, k) end end if #game[gameID].players <= 1 then endGame(gameID, game[gameID].players[1]) end end full code, anyone help me?
Master_MTA Posted August 31, 2017 Posted August 31, 2017 (edited) 34 minutes ago, barikat said: local playerGame = getElementData(source, "player:game") or false if playerGame and playerGame[1] then local gameID = playerGame[1] for k,v in ipairs(game[gameID].players) do if v == source then table.remove(game[gameID].players, k) end end if #game[gameID].players <= 1 then endGame(gameID, game[gameID].players[1]) end end full code, anyone help me? who is the source? source local playerGame = getElementData(source, "player:game") or false show us your full code with your event we can't help you without it Edited August 31, 2017 by Master_MTA
freudo Posted September 1, 2017 Author Posted September 1, 2017 function endGame(id, winner) if isElement(winner) then outputChatBox(getPlayerName(winner).." has won the game!", root, 255,255,255,true) end end function onPlayerWasted(totalAmmo, killer, killerWeapon) local playerGame = getElementData(source, "player:game") or false if playerGame and playerGame[1] then local gameID = playerGame[1] for k,v in ipairs(game[gameID].players) do if v == source then table.remove(game[gameID].players, k) end end if getElementData(source,"gang") then for k,v in ipairs(getElementsByType ( "player" )) do if getElementData(v,"gang") == getElementData(source, "gang") then endGame(gameID, game[gameID].players[v]) end end else if #game[gameID].players <= 1 then endGame(gameID, game[gameID].players[1]) end end end end I wrote this, but it does not work.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now