Imposter Posted July 20, 2012 Posted July 20, 2012 I want to see if the player's account contains the value of civilian and if it does then it sets his team as civilian. thanks! function onConnect () local theTeam = getAccountData ( source, "hisTeam" ) if source then if theTeam=="" then setPlayerTeam ( source, civilianTeam ) if theTeam==("Civilians") then setPlayerTeam ( source, civilianTeam ) end else outputChatBox ( "ERROR!" ) end end end addEventHandler ( "onPlayerLogin" , getRootElement(), onConnect )
Castillo Posted July 20, 2012 Posted July 20, 2012 'source' of onPlayerLogin is the player that logged in, not his/her account.
Imposter Posted July 20, 2012 Author Posted July 20, 2012 'source' of onPlayerLogin is the player that logged in, not his/her account. I referenced the wiki getAccountData and thats what it says, what am i supposed to use, getElementRoot() ?
AMARANT Posted July 20, 2012 Posted July 20, 2012 You again didn't get the 'source' of this function. The first argument of the function getAccountData should be 'account' object and not a 'source'. In your case 'source' is a connected player. function onConnect () local account = getPlayerAccount ( source ) local theTeam = getAccountData ( account, "hisTeam" ) if source then if theTeam=="" then setPlayerTeam ( source, civilianTeam ) if theTeam==("Civilians") then setPlayerTeam ( source, civilianTeam ) end else outputChatBox ( "ERROR!" ) end end end addEventHandler ( "onPlayerLogin" , getRootElement(), onConnect )
Imposter Posted July 20, 2012 Author Posted July 20, 2012 You again didn't get the 'source' of this function. The first argument of the function getAccountData should be 'account' object and not a 'source'. In your case 'source' is a connected player. function onConnect () local account = getPlayerAccount ( source ) local theTeam = getAccountData ( account, "hisTeam" ) if source then if theTeam=="" then setPlayerTeam ( source, civilianTeam ) if theTeam==("Civilians") then setPlayerTeam ( source, civilianTeam ) end else outputChatBox ( "ERROR!" ) end end end addEventHandler ( "onPlayerLogin" , getRootElement(), onConnect ) on the debugscript, im getting an error, "WARNING:[roleplay]\CivilianTeam\server.lua:3: Bad arguement @ 'getAccountData' [Expected account at arguement 1, got boolean]" this error is coming still even from using your code server side code: function onConnect () local playerAccount = getPlayerAccount(source) local theTeam = getAccountData ( playerAccount, "hisTeam" ) if source then if theTeam=="" then setPlayerTeam ( source, civilianTeam ) if theTeam==("Civilians") then setPlayerTeam ( source, civilianTeam ) end else outputChatBox ( "ERROR!" ) end end end addEventHandler ( "onPlayerLogin" , getRootElement(), onConnect ) function onLeave () local playerAccount = getPlayerAccount(source) local playerTeam = getPlayerTeam ( source ) if playerTeam then setAccountData ( playerAccount, "hisTeam" , playerTeam ) end end addEventHandler ( "onPlayerQuit" , getRootElement(), onLeave ) function onResourceStart() civilianTeam = createTeam ( "Civilians", 255, 255, 255 ) outputChatBox ( "Civilian Team Created!" ) onConnect() end addEventHandler ( "onResourceStart" , getRootElement(), onResourceStart )
robhol Posted July 20, 2012 Posted July 20, 2012 So, getPlayerAccount returns false. What does that tell you? Have you tried using one of the function handler arguments instead?
AMARANT Posted July 20, 2012 Posted July 20, 2012 NooP that error means that there is no such a data "hisTeam" in your player account. You can get a data from an account only in case it was set in it once.
robhol Posted July 20, 2012 Posted July 20, 2012 NooP that error means that there is no such a data "hisTeam" in your player account. You can get a data from an account only in case it was set in it once. No.
AMARANT Posted July 20, 2012 Posted July 20, 2012 robhol I'm sorry, you were right. "getPlayerAccount" returns false. That was exactly what you wrote above. He could use function handler arguments (thePreviousAccount,theCurrentAccount) but the code I gave to him works fine for me. I always get a player element from this funciton from 'source'
Imposter Posted July 20, 2012 Author Posted July 20, 2012 robhol I'm sorry, you were right. "getPlayerAccount" returns false. That was exactly what you wrote above. He could use function handler arguments (thePreviousAccount,theCurrentAccount) but the code I gave to him works fine for me. I always get a player element from this funciton from 'source' I tried both, they both work, but i find the way you told me more comfortable
KrSoFA Posted July 20, 2012 Posted July 20, 2012 I want to see if the player's account contains the value of civilian and if it does then it sets his team as civilian. thanks! function onConnect () local theTeam = getAccountData ( source, "hisTeam" ) if source then if theTeam=="" then setPlayerTeam ( source, civilianTeam ) if theTeam==("Civilians") then setPlayerTeam ( source, civilianTeam ) end else outputChatBox ( "ERROR!" ) end end end addEventHandler ( "onPlayerLogin" , getRootElement(), onConnect ) addEventHandler ( "onPlayerLogin" , getRootElement(), function() local histeam = getAccountData ( source, "hisTeam" ) if histeam and histeam == "Civilians" then setPlayerTeam ( source, civilianTeam ) else outputChatBox ( "ERROR!",source ) end end )
KrSoFA Posted July 20, 2012 Posted July 20, 2012 That won't work. addEventHandler ( "onPlayerLogin" , getRootElement(), function() local acc = getPlayerAccount(source) if acc then local histeam = getAccountData ( acc, "hisTeam" ) if histeam and tostring(histeam) == "Civilians" then setPlayerTeam ( source, civilianTeam ) else outputChatBox ( "ERROR!",source ) end end end ) Updated
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