Jump to content

Color save


Desaster

Recommended Posts

hello ,

it me again asking for help I hope you don't get annoyed from me :)

I made this could you tell me what is the problem ?

----------------------------------------Color Saver-------------------------------------- 
function onPlayerQuit ( ) 
      -- when a player leaves, store his current money amount in his account data 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in 
            local veh = getElementData (source, "hisCar1") 
            local rgb = getVehicleColor(veh) -- get the player money 
            setAccountData ( playeraccount, "color", rgb ) -- save it in his account 
      end 
end 
  
function onPlayerLogin (_, playeraccount ) 
      -- when a player logins, retrieve his money amount from his account data and set it 
      if ( playeraccount ) then 
            local color = getAccountData ( playeraccount, "color" ) 
            local veh = getElementData (source, "hisCar1") 
            -- make sure there was actually a value saved under this key (check if playermoney is not false). 
            -- this will for example not be the case when a player plays the gametype for the first time 
            if ( color ) then 
                  setVehicleColor ( veh, color, 0 ) 
            end 
      end 
end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 

Link to comment
function onPlayerQuit ( ) 
      -- when a player leaves, store his current money amount in his account data 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in 
            local veh = getElementData (source, "hisCar1") 
            local r, g, b = getVehicleColor(veh) -- get the player money 
            setAccountData ( playeraccount, "color", ""..r, g, b ) -- save it in his account 
      end 
end 
  
function onPlayerLogin (_, playeraccount ) 
      -- when a player logins, retrieve his money amount from his account data and set it 
      if ( playeraccount ) then 
            local r, g, b = getAccountData ( playeraccount, "color" ) 
            local veh = getElementData (source, "hisCar1") 
            -- make sure there was actually a value saved under this key (check if playermoney is not false). 
            -- this will for example not be the case when a player plays the gametype for the first time 
            if ( color ) then 
                  setVehicleColor ( veh, r, g, b, 255 ) 
            end 
      end 
end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 

still don't work :P

maybe the problem is that the vehicle will be spawned after ?

Link to comment

You can't receive several returns from getAccountData. getAccountData returns always a string. Thus, the first version is almost correct.

If you take a look at the wiki page, you'll find that the non-rgb version requires each of the four available vehicle colors:

bool setVehicleColor ( vehicle theVehicle, int color1, int color2, int color3, int color4 ) 

==> Line 20 of the first version should look like this:

setVehicleColor ( veh, color, 0, 0, 0 ) 

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