Jump to content

[HELP] Why not working get, and setAccountData?


Tokio

Recommended Posts

Posted

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?

My servers:

Fun:

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Derby(DD):

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

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.

Posted

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

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
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?

My servers:

Fun:

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Derby(DD):

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted
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 )

 

Experienced MTA developer for 4 years. | MTA خبرة 4 سنين في برمجة

ليس عليك اسعاد الجميع ,
ولكن عليك بإن لا تؤذي أحداً 

=========
You do not have to make everyone happy,
But you should not hurt anyone

 

Want to contact with me?

 

Discord: JustCarry#2616 (Always there)
Skype: Live:JustCarry10 (Not always)

Posted (edited)

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

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
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 

My servers:

Fun:

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Derby(DD):

n-560x95_FFFFFF_FFFFFF_000000_000000.png

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