itHyperoX Posted December 28, 2016 Share Posted December 28, 2016 (edited) Hi. I just started writing an admin system, but i already have a problem. Here is the admin level give system, which is working perfect. addCommandHandler("setalevel", function(player,cmd,...) if tonumber(getElementData(player, "admin.level")) >= 5 then local arguments = {...} if #arguments < 2 then outputChatBox(short.." /" .. cmd .. " [Name] [Level]",player, 255, 194, 14, true) else local targetPlayer = exports.serverExport:findPlayer(arguments[1], nil, 1, player) local currlevel = (tonumber(getElementData(targetPlayer, "admin.level"))) local szint = arguments[2] if targetPlayer then setElementData(targetPlayer, "admin.level",tonumber(szint)) outputChatBox(adminsz.." #6CB8FD"..getPlayerName(player).." #ffffffmegváltoztatta #6CB8FD"..getPlayerName(targetPlayer).." #ffffffadminisztrátori szintjét. #008531["..currlevel.." => "..szint.."]",root,255,255,255,true) outputChatBox(adminsz.." #ffffffSikeresen megváltoztattad #6CB8FD" .. getPlayerName(targetPlayer) .. " #ffffffadminszintjét. #008531["..currlevel.." => "..szint.."]",player,255,255,255,true) else outputChatBox("Player not found.",player) end end end end ) The problem is, when the player left the server, or just logging out, then loggin in, the player dont have he's admin level. What im using for saving: addEventHandler("onPlayerLogin", getRootElement(), function() outputChatBox(getPlayerName(source).."=> You successfully logged in.",source) setElementData(source, "admin.level") end ) addEventHandler("onPlayerLogout", root, function() setElementHealth(source, 100) outputChatBox("You logged out", source) setElementData(source, "admin.level") end ) I'm using the default MTA login, (/login /register etc etc...) whats the problem? Thanks any help. Edited December 28, 2016 by MilOG fggdgg Link to comment
Arran Posted December 28, 2016 Share Posted December 28, 2016 20 minutes ago, MilOG said: addEventHandler("onPlayerLogin", getRootElement(), function() outputChatBox(getPlayerName(source).."=> You successfully logged in.",source) setElementData(source, "admin.level") end ) addEventHandler("onPlayerLogout", root, function() setElementHealth(source, 100) outputChatBox("You logged out", source) setElementData(source, "admin.level") end ) Don't you get a debug warning from setElementData? You're missing argument 3 which is setting what argument 2 should be. It needs to be setElementData(source, "admin.level", adminLevelHere) however your "setalevel" command doesn't save their admin level any where. Add this to "setalevel": setAccountData(getAccountPlayer(targetPlayer), "admin.level", tonumber(szint)) Then when they login get it and set it like this: setElementData(source, "admin.level", tonumber(getAccountData(getPlayerAccount(source), "admin.level")))) 1 Link to comment
itHyperoX Posted December 28, 2016 Author Share Posted December 28, 2016 still no working. no debug error. Link to comment
Senpai Posted December 30, 2016 Share Posted December 30, 2016 I think you should get the element data... getElementData(source, "admin.level") on player login 1 Link to comment
itHyperoX Posted December 30, 2016 Author Share Posted December 30, 2016 not workin dude, but thanks Link to comment
myonlake Posted December 30, 2016 Share Posted December 30, 2016 Like Arran explained, here it is, done exactly like he said. addEventHandler("onPlayerLogin", getRootElement(), function(_, account) outputChatBox(getPlayerName(source).."=> You successfully logged in.",source) setElementData(source, "admin.level", getAccountData(account, "admin.level") or 0) end ) addEventHandler("onPlayerLogout", root, function(account) setElementHealth(source, 100) outputChatBox("You logged out", source) setAccountData(account, "admin.level", getElementData(source, "admin.level") or 0) removeElementData(source, "admin.level") end ) And yes, it does work. Not sure what you're doing wrong. 1 Link to comment
itHyperoX Posted December 30, 2016 Author Share Posted December 30, 2016 (edited) Not working dude.. http://imgur.com/a/6c2Cl Edited December 30, 2016 by MilOG eee Link to comment
myonlake Posted December 30, 2016 Share Posted December 30, 2016 (edited) 10 minutes ago, MilOG said: Not working dude.. http://imgur.com/a/6c2Cl Unable to reproduce either of those errors. That's some different script. There is no such thing as getAccountPlayer in that code anyway, lol. I've now tested the script twice with and without a proper account and I haven't received any errors whatsoever. Which server and client version do you have? Edited December 30, 2016 by myonlake Link to comment
itHyperoX Posted December 30, 2016 Author Share Posted December 30, 2016 (edited) the lates edit: rlly working with logout, maybe thats why not savind the level when reconnecting, because no "onPlayerQuit"? Edited December 30, 2016 by MilOG ww Link to comment
myonlake Posted December 30, 2016 Share Posted December 30, 2016 1 minute ago, MilOG said: the lates Well, I am unable to reproduce the error. Please see the line 936 of the codeServer_commands.lua file and figure it out. Link to comment
itHyperoX Posted December 30, 2016 Author Share Posted December 30, 2016 (edited) rlly working with logout, maybe thats why not savind the level when reconnecting, because no "onPlayerQuit"? Sorry for double post. I think i found the problem why not saving.. function dc ( account ) setElementHealth(source, 100) outputChatBox("You logged out", source) setAccountData(account, "admin.level", getElementData(source, "admin.level") or 0) removeElementData(source, "admin.level") end addEventHandler ( "onPlayerQuit", root, dc ) Whats the problem? Last problem edit: Fixed, thank you all guys your help! Finally working. Edited December 30, 2016 by MilOG soem world Link to comment
myonlake Posted December 30, 2016 Share Posted December 30, 2016 56 minutes ago, MilOG said: rlly working with logout, maybe thats why not savind the level when reconnecting, because no "onPlayerQuit"? Sorry for double post. I think i found the problem why not saving.. function dc ( account ) setElementHealth(source, 100) outputChatBox("You logged out", source) setAccountData(account, "admin.level", getElementData(source, "admin.level") or 0) removeElementData(source, "admin.level") end addEventHandler ( "onPlayerQuit", root, dc ) Whats the problem? Last problem edit: Fixed, thank you all guys your help! Finally working. That won't work. Use this. function saveAdminLevel( account ) local account = eventName == 'onPlayerLogout' and account or getPlayerAccount( source ) if ( account ) and ( not isGuestAccount( account ) ) then setElementHealth( source, 100 ) setAccountData( account, 'admin.level', getElementData( source, 'admin.level' ) or 0 ) removeElementData( source, 'admin.level' ) outputChatBox( "You logged out", source ) end end addEventHandler( 'onPlayerLogout', root, saveAdminLevel ) addEventHandler( 'onPlayerQuit', root, saveAdminLevel ) Reason why, is because onPlayerQuit doesn't return an account as the first argument. 1 Link to comment
itHyperoX Posted December 30, 2016 Author Share Posted December 30, 2016 Yeh i know dude. Thanks for your help! btw i fixed like this: addEventHandler("onPlayerLogout", root, function(account) setElementHealth(source, 100) setAccountData(account, "admin.level", getElementData(source, "admin.level") or 0) removeElementData(source, "admin.level") kickPlayer(source, "Rendszer", "Kijelentkeztél.") end ) addEventHandler("onPlayerQuit", root, function ( ) local account = getPlayerAccount(source) if (account) and not (isGuestAccount(account)) then triggerEvent("onPlayerLogout", source, account) end end) Link to comment
Senpai Posted December 30, 2016 Share Posted December 30, 2016 (edited) addEventHandler("onPlayerLogout", root, function(account) setElementHealth(source, 100) setAccountData(account, "admin.level", getElementData(source, "admin.level") or 0) removeElementData(source, "admin.level") kickPlayer(source, "Rendszer", "Kijelentkeztél.") end ) ah you used getElementData Edited December 30, 2016 by Senpai Link to comment
myonlake Posted December 31, 2016 Share Posted December 31, 2016 4 hours ago, MilOG said: Yeh i know dude. Thanks for your help! btw i fixed like this: addEventHandler("onPlayerLogout", root, function(account) setElementHealth(source, 100) setAccountData(account, "admin.level", getElementData(source, "admin.level") or 0) removeElementData(source, "admin.level") kickPlayer(source, "Rendszer", "Kijelentkeztél.") end ) addEventHandler("onPlayerQuit", root, function ( ) local account = getPlayerAccount(source) if (account) and not (isGuestAccount(account)) then triggerEvent("onPlayerLogout", source, account) end end) Nice. You're welcome. 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