Tokio

[HELP] Why not working get, and setAccountData?

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?

Share this post


Link to post

I think one of the if-statements is false.
Just put an outputDebugString/outputChatBox in every line, counting up.
That way you can see where the script stops.

Share this post


Link to post

Use source instead of thePlayer. Also, getPlayerNametagColor returns 3 values (r, g, b), so you can't save the data this way.
 

  • Like 1

Share this post


Link to post
12 minutes ago, DNL291 said:

Use source instead of thePlayer. Also, getPlayerNametagColor returns 3 values (r, g, b), so you can't save the data this way.
 

then how to save?

Share this post


Link to post
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

Share this post


Link to post

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

Share this post


Link to post
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 

Share this post


Link to post

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.