Jump to content

[HELP] Why not working get, and setAccountData?


Tokio

Recommended Posts

This is the code:

function onPlayerQuit ( thePlayer)
local playeraccount = getPlayerAccount ( thePlayer )
local accName = getAccountName ( getPlayerAccount ( thePlayer ) )
	if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then
		if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
            local nametagszin = getPlayerNametagColor ( thePlayer )
            setAccountData ( playeraccount, "ntszin", nametagszin )
		end
	end
end
 
function onPlayerLogin (_, playeraccount )
local playeraccount = getPlayerAccount ( thePlayer )
local accName = getAccountName ( getPlayerAccount ( thePlayer ) )
	if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then
		if ( playeraccount ) then
            local nametagszin = getAccountData ( playeraccount, "ntszin" )
            if ( nametagszin ) then
				setPlayerNametagColor ( thePlayer, r, g, b )
            end
      end
end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

No error(s)/warning(s) in debugscript 3.. :S What wrong?

Link to comment
3 minutes ago, 50cent said:

then how to save?

function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
local accName = getAccountName ( playeraccount )
	if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
		if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then
            local r,g,b = getPlayerNametagColor ( source )
            setAccountData ( playeraccount, "ntszin", r..","..g..","..b )
		end
	end
end
 
function onPlayerLogin (_, playeraccount )
local accName = getAccountName ( playeraccount )
	if ( playeraccount ) then
		if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then
            local nametagszin = getAccountData ( playeraccount, "ntszin" )
            if ( nametagszin ) then
				local r, g, b = unpack( split( nametagszin, "," ) )
				setPlayerNametagColor ( source, r, g, b )
            end
		end
	end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

 

  • Thanks 1
Link to comment
  • Moderators

You can also save this way:

	-- saving
	local r,g,b = getPlayerNametagColor( source )
	setAccountData( playeraccount, "ntszin", toJSON({ r,g,b }) )
	
	-- getting
	local nametagC = getAccountData( playeraccount, "ntszin" )
	if nametagC then
		local r,g,b = unpack(fromJSON( nametagC ))
	end

Also, you can remove the first if-statement in the "onPlayerLogin" event since the account parameter will always be returned.

Edited by DNL291
  • Like 1
Link to comment
16 minutes ago, iMr.WiFi..! said:

function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
local accName = getAccountName ( playeraccount )
	if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
		if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then
            local r,g,b = getPlayerNametagColor ( source )
            setAccountData ( playeraccount, "ntszin", r..","..g..","..b )
		end
	end
end
 
function onPlayerLogin (_, playeraccount )
local accName = getAccountName ( playeraccount )
	if ( playeraccount ) then
		if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then
            local nametagszin = getAccountData ( playeraccount, "ntszin" )
            if ( nametagszin ) then
				local r, g, b = unpack( split( nametagszin, "," ) )
				setPlayerNametagColor ( source, r, g, b )
            end
		end
	end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

 

Thank you :D 

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...