Pikachu Posted August 27, 2012 Posted August 27, 2012 Script Name: Team Winning Script Problem: WARNING: [gameplay]\Winning\teams.lua:16: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil] Maybe there are some other problems in my script, because i couldn't test it yet due to console error. Tell me if there are some other problems with my script. Script Code(Paste bin or code tags): local poisonTeam = getTeamFromName ( "Poison" ) local ninjaTeam = getTeamFromName ( "Ninja" ) local poisonPlayers = getPlayersInTeam ( poisonTeam ) local ninjaPlayers = getPlayersInTeam ( ninjaTeam ) function Winning() alivePlayers = getAlivePlayers () if alivePlayers == poisonPlayers then outPutChatBox("Poison Team won the round!", 255, 25, 0) elseif alivePlayers == ninjaPlayers then outPutChatBox("Ninja Team won the round!", 255, 25, 0) elseif alivePlayers == nil then outPutChatBox("#00ff00[#ffffffThe round was a tie!#00ff00]", 255, 255, 255, true) end end addEventHandler("onPlayerWasted", alivePlayers, Winning) Script Explanation(What is it supposed to do): When the player dies, it scans if there are alive players in each team. If the team's players are dead, it outputs a message in chatbox adverting that, the team with alive players won the round. If there are no alive players in both team, it outputs a message to advert that the round was a tie.
Pikachu Posted August 28, 2012 Author Posted August 28, 2012 console error fixed but it won't output a message
Castillo Posted August 28, 2012 Posted August 28, 2012 local poisonTeam = getTeamFromName ( "Poison" ) local ninjaTeam = getTeamFromName ( "Ninja" ) function Winning ( ) local poisonPlayers = countPlayersInTeam ( poisonTeam ) local ninjaPlayers = countPlayersInTeam ( ninjaTeam ) if ( ninjaPlayers == 0 ) then outputChatBox ( "Poison Team won the round!", 255, 25, 0 ) elseif ( poisonPlayers == 0 ) then outputChatBox ( "Ninja Team won the round!", 255, 25, 0 ) elseif ( poisonPlayers == 0 and ninjaPlayers == 0 ) then outputChatBox ( "#00ff00[#ffffffThe round was a tie!#00ff00]", 255, 255, 255, true ) end end addEventHandler ( "onPlayerWasted", root, Winning ) Try that.
TAPL Posted August 28, 2012 Posted August 28, 2012 Try local poisonTeam = getTeamFromName("Poison") local ninjaTeam = getTeamFromName("Ninja") function Winning () local poisonPlayers = #getAlivePlayersInTeam(poisonTeam) or 0 local ninjaPlayers = #getAlivePlayersInTeam(ninjaTeam) or 0 if (ninjaPlayers == 0) then outputChatBox("Poison Team won the round!", root, 255, 25, 0) elseif (poisonPlayers == 0) then outputChatBox("Ninja Team won the round!", root, 255, 25, 0) elseif (poisonPlayers == 0 and ninjaPlayers == 0) then outputChatBox("#00ff00[#ffffffThe round was a tie!#00ff00]", root, 255, 255, 255, true) end end addEventHandler("onPlayerWasted", root, Winning) function getAlivePlayersInTeam(theTeam) local theTable = { } local players = getPlayersInTeam(theTeam) for i,v in pairs(players) do if not isPedDead(v) then theTable[#theTable+1]=v end end return theTable end
Castillo Posted August 28, 2012 Posted August 28, 2012 Oh, yeah, I forgot that it had to be alive players.
Pikachu Posted September 15, 2012 Author Posted September 15, 2012 Tested it and it's not working at all Well, i want it to output the message when a team wins at Mate's BaseMode 1.0
TAPL Posted September 15, 2012 Posted September 15, 2012 Tested it and it's not working at all Well, i want it to output the message when a team wins at Mate's BaseMode 1.0 The BaseMode has their way to get the Alive players, the Alive player has element data the teams also has element data, but i don't remember the team one, also this can be done in another way. Try this local poisonTeam = getTeamFromName("Poison") local ninjaTeam = getTeamFromName("Ninja") function Winning () local poisonPlayers = #getAlivePlayersInTeam(poisonTeam) or 0 local ninjaPlayers = #getAlivePlayersInTeam(ninjaTeam) or 0 if (ninjaPlayers == 0) then outputChatBox("Poison Team won the round!", root, 255, 25, 0) elseif (poisonPlayers == 0) then outputChatBox("Ninja Team won the round!", root, 255, 25, 0) elseif (poisonPlayers == 0 and ninjaPlayers == 0) then outputChatBox("#00ff00[#ffffffThe round was a tie!#00ff00]", root, 255, 255, 255, true) end end addEventHandler("onPlayerWasted", root, Winning) function getAlivePlayersInTeam(theTeam) local theTable = { } local players = getPlayersInTeam(theTeam) for i,v in pairs(players) do if getElementData(v, "IsSpawned") ~= 1 then theTable[#theTable+1]=v end end return theTable end
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