Johns Posted March 1, 2017 Share Posted March 1, 2017 hi some time ago castillo give a script that saves team why it no work? he said he have no time to test. function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) if not (isGuestAccount (getPlayerAccount (source))) then local accountData = getAccountData (theCurrentAccount, "team") if (accountData) then setPlayerTeam(source,accountData) end end end addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) function onQuit (quitType, reason, responsibleElement,thePreviousAccount) if not (isGuestAccount (getPlayerAccount (source))) then account = getPlayerAccount (source) if (account) then local team = getPlayerTeam(source) local teamname = getTeamName(team) setAccountData (account, "team", teamname) end end end addEventHandler ("onPlayerQuit", getRootElement(), onQuit) function onLogout(prevAccount) if not (isGuestAccount (getPlayerAccount (source))) then account = getPlayerAccount (source) if (account) then local team = getPlayerTeam(source) local teamname = getTeamName(team) setAccountData (account, "team", teamname) end end end addEventHandler("onPlayerLogout", getRootElement(), onLogout) Link to comment
itHyperoX Posted March 1, 2017 Share Posted March 1, 2017 function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) if not (isGuestAccount (getPlayerAccount (source))) then local accountData = getAccountData (theCurrentAccount, "team") if (accountData) then setPlayerTeam(source,accountData) end end end addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) function onQuit (quitType, reason, responsibleElement,thePreviousAccount) if not (isGuestAccount (getPlayerAccount (source))) then account = getPlayerAccount (source) if (account) then local team = getPlayerTeam(source) local teamname = getTeamName(team) setAccountData (account, "team", teamname) end end end addEventHandler ("onPlayerQuit", getRootElement(), onQuit) addEventHandler("onPlayerLogout", getRootElement(), onQuit) Link to comment
Mr.Loki Posted March 2, 2017 Share Posted March 2, 2017 (edited) 46 minutes ago, TheMOG said: function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) if not (isGuestAccount (getPlayerAccount (source))) then local accountData = getAccountData (theCurrentAccount, "team") if (accountData) then setPlayerTeam(source,accountData) end end end addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) setPlayerTeam requires a team not a string. function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) if not (isGuestAccount (getPlayerAccount (source))) then local playerTeam = getTeamFromName(getAccountData (theCurrentAccount, "team")) if playerTeam then setPlayerTeam(source,playerTeam) end end end addEventHandler ("onPlayerLogin", root, playerLogin) Edited March 2, 2017 by Mr.Loki Link to comment
Johns Posted March 2, 2017 Author Share Posted March 2, 2017 thanks you both it works Link to comment
Johns Posted March 2, 2017 Author Share Posted March 2, 2017 another thing showed up, when i restart server it doesnt save anymore why Link to comment
Abdul KariM Posted March 3, 2017 Share Posted March 3, 2017 add this on your code function SaveTeam ( ) local aPlayersTable = getElementsByType ( "player" ) if ( #aPlayersTable ~= 0 ) then if ( eventName == "onResourceStart" ) then for _ , aPlayers in ipairs ( aPlayersTable ) do local playersAccount = getPlayerAccount ( aPlayers ) if ( playersAccount ) and not ( isGuestAccount ( playersAccount ) ) then local aPlayersTeam = getTeamFromName ( getAccountData ( playersAccount , "team" ) ) if ( aPlayersTeam ) then setPlayerTeam ( aPlayers , aPlayersTeam ) end end end elseif ( eventName == "onResourceStop" ) then for _ , aPlayers in ipairs ( aPlayersTable ) do local playersAccount = getPlayerAccount ( aPlayers ) if ( playersAccount ) and not ( isGuestAccount ( playersAccount ) ) then local playerTeam = getPlayerTeam ( aPlayers ) if ( playerTeam ) then setAccountData ( playersAccount , "team" , getTeamName ( playerTeam ) ) end end end end end end addEventHandler ( "onResourceStart", resourceRoot , SaveTeam ) addEventHandler ( "onResourceStop", resourceRoot , SaveTeam ) 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