Klesh Posted October 31, 2011 Share Posted October 31, 2011 Hello Community, i've try to do a script, this script it saves the team, when you quit and login, you are in the same team you left when you quit the game, so here is the code: function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local playerteam = getPlayerTeam ( source ) setAccountData ( playeraccount, "xsrpg.team", playerteam ) end end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local playerteam = getAccountData ( playeraccount, "xsrpg.team" ) if ( playerteam ) then setPlayerTeam ( source, playermoney ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHander ( "onPlayerLogin" getRootElement ( ), onPlayerLogin ) The team not saved. Note: The team is created by admin with the panel! Link to comment
Castillo Posted October 31, 2011 Share Posted October 31, 2011 (edited) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local playerTeam = getPlayerTeam ( source ) if playerTeam then local playerTeam = getTeamName(playerTeam) setAccountData ( playeraccount, "xsrpg.team", playerTeam ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local playerTeam = getAccountData ( playeraccount, "xsrpg.team" ) if ( playerTeam ) then setPlayerTeam ( source, getTeamFromName(playerTeam) ) end end end addEventHandler ( "onPlayerLogin" getRootElement ( ), onPlayerLogin ) Edited October 31, 2011 by Guest Link to comment
Klesh Posted October 31, 2011 Author Share Posted October 31, 2011 The player not saves the team, the team it saves, but the player is not in the team! Link to comment
Castillo Posted October 31, 2011 Share Posted October 31, 2011 Copy my code again, I just noticed you put a wrong name for event handler. Link to comment
Klesh Posted October 31, 2011 Author Share Posted October 31, 2011 Checked and tested, i see the error, but the being not save the team, where is the fail? I copy your code! Not saved! Link to comment
TAPL Posted November 1, 2011 Share Posted November 1, 2011 addEventHandler ( "onPlayerLogin" getRootElement ( ), onPlayerLogin ) correct addEventHandler ( "onPlayerLogin", getRootElement(), onPlayerLogin ) also you have two local playerTeam idk if this make problem or not but change it better function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local playerTeam = getPlayerTeam ( source ) if playerTeam then local playerTeamName = getTeamName(playerTeam) setAccountData ( playeraccount, "xsrpg.team", playerTeamName ) end end end addEventHandler ( "onPlayerQuit",getRootElement (), onPlayerQuit ) function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local playerTeam = getAccountData ( playeraccount, "xsrpg.team" ) if ( playerTeam ) then setPlayerTeam ( source, getTeamFromName(playerTeam) ) end end end addEventHandler ( "onPlayerLogin", getRootElement(), onPlayerLogin ) Link to comment
12p Posted November 1, 2011 Share Posted November 1, 2011 No it doesn't. Btw you can improve scripts using some less lines for the variable settings, or making their names smaller: function onPlayerQuit ( ) local acc = getPlayerAccount ( source ) if ( acc ) and not isGuestAccount ( acc ) then if getPlayerTeam ( source ) then setAccountData ( acc, "xsrpg.team", getTeamName ( playerTeam ) ) end end end addEventHandler ( "onPlayerQuit",getRootElement (), onPlayerQuit ) function onPlayerLogin (_, cc ) if ( acc ) then local pTeam = getAccountData ( acc, "xsrpg.team" ) if ( pTeam ) then setPlayerTeam ( source, getTeamFromName ( pTeam ) ) end end end addEventHandler ( "onPlayerLogin", getRootElement(), onPlayerLogin ) Link to comment
TAPL Posted November 1, 2011 Share Posted November 1, 2011 you forgot thing function onPlayerLogin (_, cc ) function onPlayerLogin (_, acc ) also this will be less function onPlayerQuit ( ) local acc = getPlayerAccount ( source ) if ( acc ) and not isGuestAccount ( acc ) then if getPlayerTeam ( source ) then setAccountData ( acc, "xsrpg.team", getTeamName ( playerTeam ) ) end end end addEventHandler ( "onPlayerQuit",root, onPlayerQuit ) function onPlayerLogin (_, acc ) if ( acc ) then local pTeam = getAccountData ( acc, "xsrpg.team" ) if ( pTeam ) then setPlayerTeam ( source, getTeamFromName ( pTeam ) ) end end end addEventHandler ( "onPlayerLogin",root, onPlayerLogin ) Link to comment
12p Posted November 1, 2011 Share Posted November 1, 2011 There's something with the code I gave LOL Also, why to use parenthesis? function onPlayerQuit ( ) local acc = getPlayerAccount ( source ) if acc and not isGuestAccount ( acc ) then if getPlayerTeam ( source ) then setAccountData ( acc, "xsrpg.team", getTeamName ( getPlayerTeam ( source ) ) ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) function onPlayerLogin ( _, acc ) if acc then --Is this necessary in fact? local pTeam = getAccountData ( acc, "xsrpg.team" ) if pTeam then setPlayerTeam ( source, getTeamFromName ( pTeam ) ) end end end addEventHandler ( "onPlayerLogin",root, 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