Jump to content

[Solved] Save Color From Picker


HunT

Recommended Posts

Hi all. I need help for save the colors car and HeadLight from colorPicker.

Botton

elseif (source == Color) then 
        setTimer (openColorPicker,50,1) 

colorPicker

function openColorPicker() 
    editingVehicle = getPedOccupiedVehicle(localPlayer) 
    if (editingVehicle) then 
        colorPicker.openSelect(colors) 
    end 
end 
  
function closedColorPicker() 
    local r1, g1, b1, r2, g2, b2 = getVehicleColor(editingVehicle, true) 
    server.setVehicleColor(editingVehicle, r1, g1, b1, r2, g2, b2) 
    local r, g, b = getVehicleHeadLightColor(editingVehicle) 
    server.setVehicleHeadLightColor(editingVehicle, r, g, b) 
    editingVehicle = nil 
end 
  
function updateColor() 
    if (not colorPicker.isSelectOpen) then return end 
    local r, g, b = colorPicker.updateTempColors() 
    if (editingVehicle and isElement(editingVehicle)) then 
        local r1, g1, b1, r2, g2, b2 = getVehicleColor(editingVehicle, true) 
        if (guiCheckBoxGetSelected(checkColor1)) then 
            r1, g1, b1 = r, g, b 
        end 
        if (guiCheckBoxGetSelected(checkColor2)) then 
            r2, g2, b2 = r, g, b 
        end 
        if (guiCheckBoxGetSelected(checkColor3)) then 
            setVehicleHeadLightColor(editingVehicle, r, g, b) 
        end 
        setVehicleColor(editingVehicle, r1, g1, b1, r2, g2, b2) 
    end 
end 
addEventHandler("onClientRender", root, updateColor) 

The colorPicker Work but i now want save the r1, g1, b1, r2, g2, b2 "onPlayerQuit" or "onPlayerSpawn"

idk how :|

Type getAccountData & setAccountData ?

Type : Server

function setColorPicker (editingVehicle, r1, g1, b1, r2, g2, b2) 
--IDK-- 
addEvent( "onspawn", true ) 
addEventHandler ("onspawn", getRootElement(), setColorPicker ) 

Type client :

function onspawn () 
triggerServerEvent ('onspawn', getLocalPlayer() ) 
end 
addEventHandler ("onClientPlayerSpawn", getLocalPlayer(), onspawn) 

Tnx :|

Edited by Guest
Link to comment

why use onClientPlayerSpawn just to trigger a serverside event?

Use onPlayerSpawn instead: https://wiki.multitheftauto.com/wiki/OnPlayerSpawn

But you can't really save the colors onPlayerSpawn or onPlayerQuit because the player will not be in a vehicle in either of these events

What you can do is check the colorpicker and right when a player chooses a color for a vehicle send the vehicle name + colors as parameters in a server event and afterwards use setAccountData with a key like "vehicles."..vehName and then save the rgb colors

Just an idea

Link to comment

Type ? :|

ServerSide

function setColorPicker (editingVehicle, r1, g1, b1, r2, g2, b2) 
    local account = getPlayerAccount(source) 
    --IDK-- 
     
    addEventHandler ("onPlayerSpawn", getLocalPlayer(),  setColorPicker) 

Edit :

or with

  
local playeraccount = getPlayerAccount(source) 
setAccountData(playeraccount, "r1", tonumber(r1)) 
            local r1 = getAccountData ( playeraccount, "r1" ) 
  

Link to comment

Neither.

onPlayerSpawn does not have a vehicle or the RGB Colors as parameters..

and the only way to get it is to use getPedOccupiedVehicle and then getVehicleColor(theVehicle, true)

BUT: You can't expect getPedOccupiedVehicle to return a vehicle element WHEN THE PLAYER SPAWNS. Players most likely spawn on foot.

So you need to reconsider the event. Use something else

Link to comment
Neither.

onPlayerSpawn does not have a vehicle or the RGB Colors as parameters..

and the only way to get it is to use getPedOccupiedVehicle and then getVehicleColor(theVehicle, true)

BUT: You can't expect getPedOccupiedVehicle to return a vehicle element WHEN THE PLAYER SPAWNS. Players most likely spawn on foot.

So you need to reconsider the event. Use something else

It's very hard for me :| . .i use the basic color 0-126 :roll:

Tnx Anyway

Link to comment

Hunterix vs RGB Round 2

Ok the colorPicker is hard for me :mrgreen: But i made the normal RGB1 and RGB2

1.gui client

botton1 = guiCreateButton(172,192,73,18,"Set ColoR",false,bigWindow)         
    edit1 = guiCreateEdit(39,224,47,18,"",false,bigWindow) 
    edit2 = guiCreateEdit(97,224,47,18,"",false,bigWindow)   
    edit3 = guiCreateEdit(156,224,47,18,"",false,bigWindow)  
    edit4 = guiCreateEdit(216,224,47,18,"",false,bigWindow)  
    edit5 = guiCreateEdit(275,224,47,18,"",false,bigWindow) 
    edit6 = guiCreateEdit(334,224,47,18,"",false,bigWindow) 

=

175.png

onClientGUIClick :

if (source == botton1) then 
    color1 =  guiGetText(edit1) 
    color2 =  guiGetText(edit2) 
    color3 =  guiGetText(edit3) 
    color4 =  guiGetText(edit4) 
    color5 =  guiGetText(edit5) 
    color6 =  guiGetText(edit6)  
    triggerServerEvent ("SetCarColor", getLocalPlayer(), color1, color2, color3, color4, color5, color6) 

Trigger Event :

function ColorCar ( color1, color2, color3, color4, color5, color6) 
local playeraccount = getPlayerAccount(source) 
if playeraccount == "guest" then 
outputChatBox ( "Register First !", source, 255, 200, 0 ) 
else 
setAccountData(playeraccount, "color1", tonumber(color1)) 
setAccountData(playeraccount, "color2", tonumber(color2)) 
setAccountData(playeraccount, "color3", tonumber(color3)) 
setAccountData(playeraccount, "color4", tonumber(color4)) 
setAccountData(playeraccount, "color5", tonumber(color5)) 
setAccountData(playeraccount, "color6", tonumber(color6)) 
            local color1 = getAccountData ( playeraccount, "color1" ) 
            local color2 = getAccountData ( playeraccount, "color2" ) 
            local color3 = getAccountData ( playeraccount, "color3" ) 
            local color4 = getAccountData ( playeraccount, "color4" ) 
            local color5 = getAccountData ( playeraccount, "color5" ) 
            local color6 = getAccountData ( playeraccount, "color6" ) 
playerVehicle = getPedOccupiedVehicle ( source ) 
setVehicleColor ( playerVehicle, color1, color2, color3, color4, color5, color6) 
    outputChatBox("Car color Changed !",source,255,200,0) 
end 
end 
addEvent( "SetCarColor", true ) 
addEventHandler ( "SetCarColor", getRootElement(), ColorCar) 

And This work Perfect.

This is internal.db

185.png

And This is Color :

186.png

And i made the onPlayerSpawn serverside :

function setstats ( playerSource,  color1, color2, color3, color4, color5, color6) 
if ( playerSource ) then 
playerVehicle = getPlayerOccupiedVehicle ( source ) 
local account = getPlayerAccount(source) 
            local color1 = getAccountData ( account, "color1" ) 
            local color2 = getAccountData ( account, "color2" ) 
            local color3 = getAccountData ( account, "color3" ) 
            local color4 = getAccountData ( account, "color4" ) 
            local color5 = getAccountData ( account, "color5" ) 
            local color6 = getAccountData ( account, "color6" ) 
             
            if ( playerVehicle ) then 
             
color1, color2, color3, color4, color5, color6 = getVehicleColor ( playerVehicle ) 
setVehicleColor ( playerVehicle, color1, color2, color3, color4, color5, color6) 
end 
end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), setstats ) 

In race map with respawn work perfect . . .but "on next map" the get/set color no work :cry:

WHY

help please :| Tnx

Link to comment
addEvent("onRaceStateChanging",true) 
addEventHandler("onRaceStateChanging",root, 
function (new, old) 
if (new == "GridCountdown") then 
    for i,v in pairs(getElementsByType("player")) do 
        if isPedInVehicle(v) then 
            local account = getPlayerAccount(v) 
            if not account or isGuestAccount(account) then return end 
            local color1 = getAccountData ( account, "color1" ) 
            local color2 = getAccountData ( account, "color2" ) 
            local color3 = getAccountData ( account, "color3" ) 
            local color4 = getAccountData ( account, "color4" ) 
            local color5 = getAccountData ( account, "color5" ) 
            local color6 = getAccountData ( account, "color6" ) 
            local playerVehicle = getPedOccupiedVehicle(v) 
            setVehicleColor ( playerVehicle, color1, color2, color3, color4, color5, color6) 
            end 
        end 
    end 
end) 

Try that.

Link to comment
addEvent("onRaceStateChanging",true) 
addEventHandler("onRaceStateChanging",root, 
function (new, old) 
if (new == "GridCountdown") then 
    for i,v in pairs(getElementsByType("player")) do 
        if isPedInVehicle(v) then 
            local account = getPlayerAccount(v) 
            if not account or isGuestAccount(account) then return end 
            local color1 = getAccountData ( account, "color1" ) 
            local color2 = getAccountData ( account, "color2" ) 
            local color3 = getAccountData ( account, "color3" ) 
            local color4 = getAccountData ( account, "color4" ) 
            local color5 = getAccountData ( account, "color5" ) 
            local color6 = getAccountData ( account, "color6" ) 
            local playerVehicle = getPedOccupiedVehicle(v) 
            setVehicleColor ( playerVehicle, color1, color2, color3, color4, color5, color6) 
            end 
        end 
    end 
end) 

Try that.

OH yep work Tnx Castillo :mrgreen:

Waiting 1 2 seconds for set the colors . . .But Work.

Other Solution for remove the 1 2 seconds without color? :roll:

Link to comment
That's the best way I know, is when the countdown starts (everyone has a vehicle for then).

ok realy tnx Castillo u save me :fadein: the rgb stress me :mrgreen:

i now made the easy script for set the normal black color car "onPlayerJoin" or Login.

Tnx Again.

Link to comment

Like BinSlayer said, you just needed an other event. When a player spawns, his vehicle gets created and then is warped into it, this triggers onPlayerVehicleEnter.

This should do it:

addEventHandler("onPlayerVehicleEnter",root, 
function (theVehicle, seat, jacked ) 
   local account = getPlayerAccount(source) 
   if not account or isGuestAccount(account) then return end 
   local color1 = getAccountData ( account, "color1" ) 
   local color2 = getAccountData ( account, "color2" ) 
   local color3 = getAccountData ( account, "color3" ) 
   local color4 = getAccountData ( account, "color4" ) 
   local color5 = getAccountData ( account, "color5" ) 
   local color6 = getAccountData ( account, "color6" ) 
   setVehicleColor ( theVehicle, color1, color2, color3, color4, color5, color6) 
end) 

Link to comment
it is?

getAccountData returns strings afaik and setVehicleColor requires integers

I'm surprised it works

I would have thought you needed to tonumber it

Work Perfect (with onPlayerVehicleEnter :mrgreen: )

I use this for set the LightColor and wheels :

153.png

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