Jump to content

account.xml


kevin11

Recommended Posts

hey a friend made a color script for youre name, how can i save it into account.xml?

with setaccountdata blabla

function nameTagColor2 ( redT,greenT,blueT, r, g, b )
   setPlayerNametagColor ( source, redT,greenT,blueT )
end
addEvent( "nameTag", true )
addEventHandler ( "nameTag", getRootElement(), nameTagColor2)

Edited by Guest
Link to comment

:shock: i tried some things but still doesnt really work:( anyone knows how?

dont laugh but im bad in this here is what i did

function onPlayerQuit ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
           local nametagColor = getPlayerNametagColor ( source )
           setAccountData ( playeraccount, "nameColor", nametagColor )
     end
end
 
function onPlayerLogin ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
           local nametagColor = getAccountData ( playeraccount, "nameColor" )
           if ( nametagColor ) then
                 setPlayerNametagColor ( thePlayer, r, g, b )
           end
     end
end
 
function onPlayerSpawn ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
           local nametagColor = getAccountData ( playeraccount, "nameColor" )
           if ( nametagColor ) then
                 setPlayerNametagColor ( thePlayer, r, g, b )
           end
     end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )
addEventHandler ( "onPlayerSpawn", getRootElement ( ), onPlayerSpawn )

Edited by Guest
Link to comment
anyone?

Yes, you.

Do you think colour is just 1 value? It is for drawing functions (client-side) but not for name. Why don't you try to think for a second or two? Look at setPlayerNametagColor function parameters at wiki and ask yourself: "What should I save that I can load/use later in setPlayerNametagColor?" I'm sure you can answer this question within time of 1 second after seeing setPlayerNametagColor parameters.

Link to comment
anyone?

Yes, you.

Do you think colour is just 1 value? It is for drawing functions (client-side) but not for name. Why don't you try to think for a second or two? Look at setPlayerNametagColor function parameters at wiki and ask yourself: "What should I save that I can load/use later in setPlayerNametagColor?" I'm sure you can answer this question within time of 1 second after seeing setPlayerNametagColor parameters.

k u can also try saying it at a normal way :| im just asking :x

Link to comment

This is so obvious that I'm sure you wouldn't have to make a new thread to ask this question. Do you still wonder how to save it? I'll be willing to write these few lines for you if you're still having problems.

Link to comment
This is so obvious that I'm sure you wouldn't have to make a new thread to ask this question. Do you still wonder how to save it? I'll be willing to write these few lines for you if you're still having problems.

ok ty (im trying to learn lua )

Link to comment
function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local nametagColor = getPlayerNametagColor ( source ) --INCORRECT! Delete it!
--It only saves the RED color value in "nametagColor" variable, skipping Green and Blue one, so:
local r, g, b = getPlayerNametagColor ( source ) -- is correct
--Then, you can't save just 3 variables as a single account data, it requires a workaround:
local nametagColor = { r, g, b } --we put everything in a table { }..
local dataToSave = toJSON( nametagColor ) -- .. and then transform the table using [url=https://wiki.multitheftauto.com/wiki/ToJSON]toJSON[/url] function.
-- now we've got a table of colors in a string form so we can..
setAccountData ( playeraccount, "nameColor", dataToSave ) -- ..save it eventually
end
end
 
function onPlayerLogin ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local nametagColor = getAccountData ( playeraccount, "nameColor" )
if ( nametagColor ) then
setPlayerNametagColor ( thePlayer, r, g, b ) --INCORRECT! Remove the line!
--Look, you don't have "r", "g", "b" declared yet, you only have "nametagColor" one so we make a reverse transformation: ..
local colorTable = fromJSON( nametagColor ) --..put out string back into table form using [url=https://wiki.multitheftauto.com/wiki/FromJSON]fromJSON[/url] function..
local r, g, b = unpack( colorTable ) --.. and get all 3 values from it with [url=http://www.lua.org/manual/5.1/manual.html#pdf-unpack]unpack[/url] function
-- so now we've got RGB values for using in setPlayerNametagColor()
setPlayerNametagColor ( thePlayer, r, g, b ) -- Now it's correct.
end
end
end

( same for onPlayerSpawn() )

Of course this code can be shortened, but you must understand what each line does before trying to optimize.

P.S. Yep, sorry. A mistype at line 23.

Edited by Guest
Link to comment

50p can u fix it for me :P ur pro

function onPlayerQuit ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
        local r, g, b = getPlayerNametagColor ( source ) 
        local nametagColor = { r, g, b }
        local dataToSave = toJSON( nametagColor )
           setAccountData ( playeraccount, "nameColor", dataToSave )
     end
end
 
function onPlayerLogin ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
           local nametagColor = getAccountData ( playeraccount, "nameColor" )
           if ( nametagColor ) then
                 local colorTable = fromJSON( nametagColor )
                 local r, g, b = unpack( fromJSON )
                 setPlayerNametagColor ( thePlayer, r, g, b )
           end
     end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

Link to comment

I've been having problems with toJSON and fromJSON (even with JSON data in C#, that's why my SDK doesn't have any classes to help with returned data from MTA server).

Just save every channel separately or: Where is thePlayer variable coming from?

Antibrid, how can you unpack a function (tip: fromJSON, line 23)? Also, why do you create 3 separate variables which are used once (go straight to table)? Why not simply:

local nameColor = { getPlayerNametagColor( source ) };

Link to comment
at line 17 you should unpack colorTable i'd say.

My fail, fixed in code above. He just copied and stuck with that error.

@50p: everything comes of the script kevin11 posted, thePlayer as well. I just tried to explain the errors he had and show a way to avoid. Using 3 variables is only for visibility purposes.

Of course this code can be shortened, but you must understand what each line does before trying to optimize.
Link to comment
at line 17 you should unpack colorTable i'd say.

My fail, fixed in code above. He just copied and stuck with that error.

@50p: everything comes of the script kevin11 posted, thePlayer as well. I just tried to explain the errors he had and show a way to avoid. Using 3 variables is only for visibility purposes.

Of course this code can be shortened, but you must understand what each line does before trying to optimize.

Fair enough but I didn't ask you about thePlayer. If you're fixing code, fix it so it works or don't fix it and give tips so that author can try to fix it himself. When you're giving sample code, don't copy & paste original code but show the sample code only. That way he learns and tries to implement the code in his script. I know many people don't like my way of teaching but after all they're thankful and actually learn something, not just getting the code, disappearing from the forum and coming back for more code when in need. Anyway, let's just wait for topic's author to reply.

Link to comment

is this better???? can anyone just fix it so i can see what i did wrong:S

function onPlayerQuit ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
           local nametagColor = getPlayerNametagColor ( source )
                 setPlayerNametagColor ( thePlayer, "r" )
                 setPlayerNametagColor ( thePlayer, "g" )
                 setPlayerNametagColor ( thePlayer, "b" )
     end
end
 
function onPlayerLogin ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
           local nametagColor = getAccountData ( playeraccount, "nameColor" )
           if ( nametagColor ) then
                 setPlayerNametagColor ( thePlayer, "r" )
                 setPlayerNametagColor ( thePlayer, "g" )
                 setPlayerNametagColor ( thePlayer, "b" )
           end
     end
end
 
function onPlayerSpawn ( )
     local playeraccount = getPlayerAccount ( source )
     if ( playeraccount ) then
           local nametagColor = getAccountData ( playeraccount, "nameColor" )
           if ( nametagColor ) then
                 setPlayerNametagColor ( thePlayer, "r" )
                 setPlayerNametagColor ( thePlayer, "g" )
                 setPlayerNametagColor ( thePlayer, "b" )
           end
     end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )
addEventHandler ( "onPlayerSpawn", getRootElement ( ), onPlayerSpawn )

Link to comment

ok well, i checked all those codes and edited it by myself and works it, saves the player tag color and when login it loads the saved one. here is code :)

function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local r, g, b = getPlayerNametagColor ( source )
setAccountData ( playeraccount, "ColorRed", r )
setAccountData ( playeraccount, "ColorGreen", g )
setAccountData ( playeraccount, "ColorBlue", b )			
end
end
 
function onPlayerLogin ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local tagColorRed = getAccountData ( playeraccount, "ColorRed" )
local tagColorGreen = getAccountData ( playeraccount, "ColorGreen" )			
local tagColorBlue = getAccountData ( playeraccount, "ColorBlue" )			
if tagColorRed and tagColorGreen and tagColorBlue then
setPlayerNametagColor ( source, tagColorRed, tagColorGreen, tagColorBlue )
end
end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

Greetings Castillo

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