Imposter Posted July 20, 2012 Share 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 ) Link to comment
Castillo Posted July 20, 2012 Share Posted July 20, 2012 'source' of onPlayerLogin is the player that logged in, not his/her account. Link to comment
Imposter Posted July 20, 2012 Author Share 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() ? Link to comment
AMARANT Posted July 20, 2012 Share 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 ) Link to comment
Imposter Posted July 20, 2012 Author Share 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 ) Link to comment
robhol Posted July 20, 2012 Share Posted July 20, 2012 So, getPlayerAccount returns false. What does that tell you? Have you tried using one of the function handler arguments instead? Link to comment
AMARANT Posted July 20, 2012 Share 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. Link to comment
robhol Posted July 20, 2012 Share 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. Link to comment
AMARANT Posted July 20, 2012 Share 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' Link to comment
Imposter Posted July 20, 2012 Author Share 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 Link to comment
KrSoFA Posted July 20, 2012 Share 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 ) Link to comment
KrSoFA Posted July 20, 2012 Share 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 Link to comment
AMARANT Posted July 20, 2012 Share Posted July 20, 2012 Actually I thought that the problem is solved 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