Jump to content

saving colors


kevin11

Recommended Posts

solidsnake14 made this ones

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
 
function onPlayerSpawn ( )
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 
 
function onPlayerWasted ( )
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
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )
addEventHandler ( "onPlayerWasted", getRootElement ( ), onPlayerWasted )
addEventHandler ( "onPlayerSpawn", getRootElement ( ), onPlayerSpawn )

AND i was making kinda the same but then saving car colors 1-2

function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local r, g, b = getVehicleColor ( source )
setAccountData ( playeraccount, "vehColorRed", r )
setAccountData ( playeraccount, "vehColorGreen", g )
setAccountData ( playeraccount, "vehColorBlue", b )         
end
end
 
function onPlayerLogin ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local vehColorRed = getAccountData ( playeraccount, "ColorRed" )
local vehColorGreen = getAccountData ( playeraccount, "ColorGreen" )         
local vehColorBlue = getAccountData ( playeraccount, "ColorBlue" )         
if vehColorRed and vehColorGreen and vehColorBlue then
setVehicleColor ( source, vehColorRed, vehColorGreen, vehColorBlue )
end
end
end
 
function onPlayerSpawn ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local vehColorRed = getAccountData ( playeraccount, "ColorRed" )
local vehColorGreen = getAccountData ( playeraccount, "ColorGreen" )         
local vehColorBlue = getAccountData ( playeraccount, "ColorBlue" )         
if vehColorRed and vehColorGreen and vehColorBlue then
setVehicleColor ( source, vehColorRed, vehColorGreen, vehColorBlue )
end
end
end 
 
function onPlayerWasted ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local r, g, b = getVehicleColor ( source )
setAccountData ( playeraccount, "vehColorRed", r )
setAccountData ( playeraccount, "vehColorGreen", g )
setAccountData ( playeraccount, "vehColorBlue", b )         
end
end
 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )
addEventHandler ( "onPlayerWasted", getRootElement ( ), onPlayerWasted )
addEventHandler ( "onPlayerSpawn", getRootElement ( ), onPlayerSpawn )

but its not working it gives the error bad eventhandler (no lines or anything)

can anyone help, because tag color and veh color may not overwrite each other

if soeone dies i get this error

warning: 30-38: bad argument @ setvehiclecolor

Link to comment

Ok, first thing I notice is you seem to be using "setVehicleColor" wrong.

It does not go by r, g, b.

Each car has different colour 'boxes' and each argument given to "setVehicleColor" is the colour ID for each box, not the RGB values for just one 'box'.

Also, your trying to set the vehicle colour of the player? this obviously won't work.

Study this page: https://wiki.multitheftauto.com/wiki/SetVehicleColor

An example from me, for the usage of setVehicleColor is:

local myCar = createVehicle(496, 0, 0, 0)
function MyCarColour(myCar)
setVehicleColor(myCar, 3)
end

^The example above would spawn a Blista Compact(496) at the co-ords of 0,0,0 (x,y,z) and then set the vehicle's colour to red.

Edited by Guest
Link to comment

here it is, should work ( at least in my server did :) )

server.lua

function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local c1 = nil
local c2 = nil
local c1,c2,c3,c4 = getVehicleColor (getPedOccupiedVehicle(source))
setAccountData (playeraccount, "carcolor1", c1)
setAccountData (playeraccount, "carcolor2", c2)
end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
 
function onPlayerLogin ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local c1 = nil
local c2 = nil
local c1 = getAccountData ( playeraccount, "carcolor1" )
local c2 = getAccountData ( playeraccount, "carcolor2" )         
if c1 and c2 then
		veh = getPedOccupiedVehicle(source)
if veh then
setVehicleColor ( veh, c1, c2, 0, 0 )
end
end
end
end
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin )

Link to comment

The code in the post above will work, but only if they're in a car AS SOON AS the player logs in (which has a really slim chance of being possible by common practice, as if the player has any reason to login they'd do that first. unless you make your own event (if you use a custom login system) and trigger it when they login.)

It will also only work if the car has two colours (which most don't).

Edited by Guest
Link to comment
The code in the post above will work, but only if they're in a car AS SOON AS the player logs in (which has a really slim chance of being possible by common practice, as if the player has any reason to login they'd do that first, unless you make your own event (if you use a custom login system) and trigger it when they login.

It will also only work if the car has two colours (which most don't).

i just made an example of how to do it.

Link to comment

hes not 14 :roll:

anyway

i added wasted (save) and changed login to spawn

i get this error server.lua:18: bad argument @ 'getvehiclecolor'

function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local c1 = nil
local c2 = nil
local c1,c2,c3,c4 = getVehicleColor (getPedOccupiedVehicle(source))
setAccountData (playeraccount, "carcolor1", c1)
setAccountData (playeraccount, "carcolor2", c2)
end
end
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit )
 
function onPlayerWasted ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local c1 = nil
local c2 = nil
local c1,c2,c3,c4 = getVehicleColor (getPedOccupiedVehicle(source))
setAccountData (playeraccount, "carcolor1", c1)
setAccountData (playeraccount, "carcolor2", c2)
end
end
addEventHandler ( "onPlayerWasted", getRootElement ( ), onPlayerWasted )
 
function onPlayerSpawn ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) then
local c1 = nil
local c2 = nil
local c1 = getAccountData ( playeraccount, "carcolor1" )
local c2 = getAccountData ( playeraccount, "carcolor2" )         
if c1 and c2 then
        veh = getPedOccupiedVehicle(source)
if veh then
setVehicleColor ( veh, c1, c2, 0, 0 )
end
end
end
end
addEventHandler ( "onPlayerSpawn", getRootElement ( ), onPlayerSpawn )

Link to comment

getPedOccupiedVehicle doesn't know what source is, you, for that matter, the entire function doesn't know what source is.

You need to do something like

local player = getPedOccupiedVehicle(sourcePlayer)
getVehicleColor(player)

or

function SetCarColor(sourcePlayer) -- Or GetCarColor, depends what the function is doing.
getVehicleColor(sourcePlayer)

You need to study the basics of creating functions and depending on what your code is doing is how you know what arguments to give to the function.

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