Jump to content

Little help with admin level


itHyperoX

Recommended Posts

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 by MilOG
fggdgg
Link to comment
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"))))

  • Like 1
Link to comment

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.

  • Like 1
Link to comment
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 by myonlake
Link to comment

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 :D

edit:

Fixed, thank you all guys your help! Finally working. :)

Edited by MilOG
soem world
Link to comment
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 :D

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.

  • Like 1
Link to comment

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
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 :D

Edited by Senpai
Link to comment
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...