Pikachu Posted August 27, 2012 Share 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. Link to comment
Jaysds1 Posted August 28, 2012 Share Posted August 28, 2012 try this: http://pastebin.com/QyuUW7Fq Link to comment
Pikachu Posted August 28, 2012 Author Share Posted August 28, 2012 console error fixed but it won't output a message Link to comment
Castillo Posted August 28, 2012 Share 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. Link to comment
TAPL Posted August 28, 2012 Share 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 Link to comment
Castillo Posted August 28, 2012 Share Posted August 28, 2012 Oh, yeah, I forgot that it had to be alive players. Link to comment
Pikachu Posted September 15, 2012 Author Share 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 Link to comment
TAPL Posted September 15, 2012 Share 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 Link to comment
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