JanKy Posted August 29, 2018 Share Posted August 29, 2018 Hello, and sorry for asking so many questions. ( Yeah, i feel bad for making so many mistakes ) But i am trying to save a player's team name and rank in that team, before quiting, and load it back up when he joins. Here's my try : function saveBeforeQuit () oldTeam = getElementData(thePlayer,"gang"); idkrang = getElementData(thePlayer,"gang_leader"); end addEventHandler ( "onPlayerQuit", root, saveBeforeQuit) function loadOnJoin () if oldTeam ~= "None" and getElementData(thePlayer,"gang") ~= "None" then setElementData(thePlayer,"gang",oldTeam) setElementData(thePlayer,"gang_leader",idkrang) else setElementData(thePlayer,"gang","None") setElementData(thePlayer,"gang_leader","not") end end addEventHandler ( "onPlayerJoin", getRootElement(), loadOnJoin ) ( Where "gang_leader" stands for the rank ) And i get the following errors : Bad argument @ 'getElementData' [Expected element at argument 1, got nil] Bad argument @ 'setElementData' [Expected element at argument 1, got nil] Bad argument @ 'setElementData' [Expected element at argument 1, got nil] I tried adding "source" instead of "thePlayer" but in that case, whenever a player joins, their team is set to the player that left before. Link to comment
Abdul KariM Posted August 30, 2018 Share Posted August 30, 2018 use accountData or sql 1 1 Link to comment
JanKy Posted August 30, 2018 Author Share Posted August 30, 2018 Oh, damn, thank you ^^. Here's how i did it. function onPlayerQuit ( ) local playeraccount = getPlayerAccount(source) setAccountData ( playeraccount, "dayzteam", getElementData(source,"gang") ) setAccountData ( playeraccount, "dayzrank", getElementData(source,"gang_leader") ) end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local oldTeam = getAccountData ( playeraccount, "dayzteam") local oldRank = getAccountData ( playeraccount, "dayzrank") setElementData(source,"gang",oldTeam) setElementData(source,"gang_leader",oldRank) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 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