Bleidex Posted June 3, 2011 Posted June 3, 2011 Warning on Line 13 Bad Argument @ 'setPlayerTeam' Can't get what is wrong. teamRed = createTeam ( "Red", 255, 0, 0 ) teamBlue = createTeam ( "Blue", 0, 0, 255 ) function loging () triggerClientEvent ( "OnPlayerLogingIn", getRootElement(), startTheWindow ) end addEventHandler ( "onPlayerLogin", getRootElement(), loging ) function playerContinue ( thePlayer ) local playersRed = countPlayersInTeam ( teamRed ) local playersBlue = countPlayersInTeam ( teamBlue ) if playersRed == playersBlue then setPlayerTeam ( thePlayer, teamRed ) elseif playersRed > playersBlue then setPlayerTeam ( thePlayer, teamBlue ) elseif playersRed < playersBlue then setPlayerTeam ( thePlayer, teamRed ) end end addEvent ( "OnPlayerPressingButton", true ) addEventHandler ( "OnPlayerPressingButton", getRootElement(), playerContinue )
Aibo Posted June 3, 2011 Posted June 3, 2011 you should post the part that triggers this event, obviously thePlayer is not what you expect it to be. ?
Bleidex Posted June 3, 2011 Author Posted June 3, 2011 full serverside script: teamRed = createTeam ( "Red", 255, 0, 0 ) teamBlue = createTeam ( "Blue", 0, 0, 255 ) function loging () triggerClientEvent ( "OnPlayerLogingIn", getRootElement(), startTheWindow ) end addEventHandler ( "onPlayerLogin", getRootElement(), loging ) function playerContinue ( thePlayer ) local playersRed = countPlayersInTeam ( teamRed ) local playersBlue = countPlayersInTeam ( teamBlue ) if playersRed == playersBlue then setPlayerTeam ( thePlayer, teamRed ) elseif playersRed > playersBlue then setPlayerTeam ( thePlayer, teamBlue ) elseif playersRed < playersBlue then setPlayerTeam ( thePlayer, teamRed ) end end addEvent ( "OnPlayerPressingButton", true ) addEventHandler ( "OnPlayerPressingButton", getRootElement(), playerContinue ) function playerWin ( rank ) if rank ~=1 then return end local playerName = getPlayerName ( source ) local playerTeam = getPlayerTeam ( source ) local playerAccount = getPlayerAccount ( source ) local playerMoney = getAccountData ( playerAccount, "Cash" ) or 0 local playerWins = getAccountData ( playerAccount, "Wins" ) or 0 local teamPlayers = getPlayersInTeam ( playerTeam ) setAccountData ( playerAccount, "Cash", tonumber(playerMoney) + get('FirstPlaceMoney') ) setAccountData ( playerAccount , "Wins", tonumber(playerWins) + 1 ) for playerKey, playerValue in ipairs ( teamPlayers ) do teamAccount = getPlayerAccount ( playerValue ) teamCash = getAccountData ( teamAccount, "Cash" ) or 0 teamWins = getAccountData ( teamAccount, "teamWins" ) or 0 setAccountData ( teamAccount, "Cash", tonumber(teamCash) + get('TeamFirstPlaceMoney') ) setAccountData ( teamAccount, "teamWins", tonumber(teamWins) + 1 ) end end addEventHandler ( "onPlayerFinish", getRootElement(), playerWin ) function playerSecond ( rank ) if rank ~=2 then return end local playerName = getPlayerName ( source ) local playerTeam = getPlayerTeam ( source ) local playerAccount = getPlayerAccount ( source ) local playerMoney = getAccountData ( playerAccount, "Cash" ) or 0 local playerSecondPlaces = getAccountData ( playerAccount, "SecondPlaces" ) or 0 local teamPlayers = getPlayersInTeam ( playerTeam ) setAccountData ( playerAccount, "Cash", tonumber(playerMoney) + get('SecondPlaceMoney') ) setAccountData ( playerAccount , "SecondPlaces", tonumber(playerSecondPlaces) + 1 ) for playerKey, playerValue in ipairs ( teamPlayers ) do teamAccount = getPlayerAccount ( playerValue ) teamCash = getAccountData ( teamAccount, "Cash" ) or 0 teamThirdPlaces = getAccountData ( teamAccount, "teamSecondPlaces" ) or 0 setAccountData ( teamAccount, "Cash", tonumber(teamCash) + get('TeamSecondPlaceMoney') ) setAccountData ( teamAccount, "teamSecondPlaces", tonumber(teamSecondPlaces) + 1 ) end end addEventHandler ( "onPlayerFinish", getRootElement(), playerSecond ) function playerThird ( rank ) if rank ~=3 then return end local playerName = getPlayerName ( source ) local playerTeam = getPlayerTeam ( source ) local playerAccount = getPlayerAccount ( source ) local playerMoney = getAccountData ( playerAccount, "Cash" ) or 0 local playerThirdPlaces = getAccountData ( playerAccount, "ThirdPlaces" ) or 0 local teamPlayers = getPlayersInTeam ( playerTeam ) setAccountData ( playerAccount, "Cash", tonumber(playerMoney) + get('ThirdPlaceMoney') ) setAccountData ( playerAccount , "ThirdPlaces", tonumber(playerThirdPlaces) + 1 ) for playerKey, playerValue in ipairs ( teamPlayers ) do teamAccount = getPlayerAccount ( playerValue ) teamCash = getAccountData ( teamAccount, "Cash" ) or 0 teamThirdPlaces = getAccountData ( teamAccount, "teamThirdPlaces" ) or 0 setAccountData ( teamAccount, "Cash", tonumber(teamCash) + get('TeamThirdPlaceMoney') ) setAccountData ( teamAccount, "teamThirdPlaces", tonumber(teamThirdPlaces) + 1 ) end end addEventHandler ( "onPlayerFinish", getRootElement(), playerThird ) function playerFinish ( rank ) if rank <3 then local playerName = getPlayerName ( source ) local playerTeam = getPlayerTeam ( source ) local playerAccount = getPlayerAccount ( source ) local playerMoney = getAccountData ( playerAccount, "Cash" ) or 0 local mapsFinished = getAccountData ( playerAccount, "MapsFinished" ) or 0 local teamPlayers = getPlayersInTeam ( playerTeam ) setAccountData ( playerAccount, "Cash", tonumber(playerMoney) + get('MoneyForFinish') ) setAccountData ( playerAccount , "MapsFinished", tonumber(mapsFinished) + 1 ) end end addEventHandler ( "onPlayerFinish", getRootElement(), playerFinish ) clientside: function window( ) GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Memo = {} GUIEditor_Label = {} GUIEditor_Image = {} GUIEditor_Window[1] = guiCreateWindow(219,170,593,467,"Red vs Blue Racing!",false) GUIEditor_Memo[1] = guiCreateMemo(32,185,529,223,"Press F9 for more help.\n\nRules:\n\nTODO...",false,GUIEditor_Window[1]) GUIEditor_Button[1] = guiCreateButton(36,434,523,23,"Continue",false,GUIEditor_Window[1]) addEventHandler ( "onClientGUIClick", GUIEditor_Button[1], continuePressedButton, false ) GUIEditor_Label[1] = guiCreateLabel(35,414,517,17,"By clicking 'Continue' you accept the rules and braking the rules will get you punished.",false,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[1],255,255,255) guiLabelSetVerticalAlign(GUIEditor_Label[1],"top") guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false) guiSetVisible(GUIEditor_Window[1], false) end function startTheWindow( ) window( ) if ( GUIEditor_Window[1] ~= nil ) then guiSetVisible ( GUIEditor_Window[1], true ) else outputChatBox ( "ERROR." ) end showCursor(true) end addEvent ( "OnPlayerLogingIn", true ) addEventHandler ( "OnPlayerLogingIn", getRootElement(), startTheWindow ) function continuePressedButton(button,state) if button == "left" and state == "up" then guiSetVisible(GUIEditor_Window[1], false) showCursor(false) triggerServerEvent ( "OnPlayerPressingButton", getRootElement(), playerContinue ) end end
proracer Posted June 3, 2011 Posted June 3, 2011 Try this: function playerContinue ( ) local playersRed = countPlayersInTeam ( teamRed ) local playersBlue = countPlayersInTeam ( teamBlue ) for i,v in ipairs ( getElementsByType ( 'player' ) ) do if playersRed == playersBlue then setPlayerTeam ( v, teamRed ) elseif playersRed > playersBlue then setPlayerTeam ( v, teamBlue ) elseif playersRed < playersBlue then setPlayerTeam ( v, teamRed ) end end end addEvent ( "OnPlayerPressingButton", true ) addEventHandler ( "OnPlayerPressingButton", getRootElement(), playerContinue )
Aibo Posted June 3, 2011 Posted June 3, 2011 in client script line 35 should be: triggerServerEvent ( "OnPlayerPressingButton", getLocalPlayer()) because right now you're triggering event from the root, and passing a nil argument playerContinue (you dont need to put function name in when triggering the event) and serverside part should be: function playerContinue () local playersRed = countPlayersInTeam ( teamRed ) local playersBlue = countPlayersInTeam ( teamBlue ) if playersRed == playersBlue then setPlayerTeam ( source, teamRed ) elseif playersRed > playersBlue then setPlayerTeam ( source, teamBlue ) elseif playersRed < playersBlue then setPlayerTeam ( source, teamRed ) end end addEvent ( "OnPlayerPressingButton", true ) addEventHandler ( "OnPlayerPressingButton", getRootElement(), playerContinue ) ?
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