Jump to content

Picker


#Rmad~>

Recommended Posts

أhi

i have picker I want him to make the chosen color for a car player

i make him but i have small problem

addEvent ( "onColorPickerOK" ) 
CCar = guiCreateButton(206, 130, 127, 56, "Color", false, x2) 
setElementData ( CCar, "Color", "0, 0, 255" ) 
addEventHandler( "onClientGUIClick", resourceRoot, 
function() 
    if ( source == CCar ) then 
    exports.cpicker:openPicker ( "Car Color", "#0000FF", "Car Color color picker" ) 
        end 
    end 
) 
addEventHandler ( "onColorPickerOK", root, 
function ( element, hex, r, g, b ) 
    if ( element == "Car Color" ) then 
        local r, g, b = unpack ( split ( getElementData ( CCar, "Color" ), ", " ) ) 
        r, g, b = tonumber ( r ), tonumber ( g ), tonumber ( b ) 
        hex   = "FF" .. ( { hex:gsub ( "#", "" ) } ) [ 1 ] 
        local color = r .. "," .. g .. "," .. b 
        guiSetProperty ( CCar, "NormalTextColour", hex ) 
        setElementData ( CCar, "r", color ) 
        setElementData ( CCar, "g", color ) 
        setElementData ( CCar, "b", color ) 
        triggerServerEvent("onBuy", localPlayer,r, g, b) 
        end 
    end 
) 

function Buy(r,g,b) 
     if (getPlayerMoney(source) >= 100) then 
          takePlayerMoney(source, 100)  
              local vehicle = getPedOccupiedVehicle(source) 
              setVehicleColor ( vehicle, r, g, b )  
     else 
          outputChatBox ("You Don't have $100",source,255,0,0) 
     end 
end 
addEvent("onBuy",true) 
addEventHandler("onBuy", root, Buy) 
  
function Quit() 
    local account = getPlayerAccount( source ) 
    if ( account and not isGuestAccount(account)) then 
    local r = tonumber (getElementData(source,"r")) or 0 
    setAccountData(account,"r",r) 
    local g = tonumber (getElementData(source,"g")) or 0 
    setAccountData(account,"g",g) 
    local b = tonumber (getElementData(source,"b")) or 0 
    setAccountData(account,"b",b) 
    end 
addEventHandler("onPlayerQuit", root, Quit) 
     
addEventHandler( "onPlayerLogin", root, 
function( _,acc) 
    local r = getAccountData(acc,"r") 
    local g = getAccountData(acc,"g") 
    local b = getAccountData(acc,"b") 
    if ( r and g and b ) then 
    local vehicle = getPedOccupiedVehicle(source) 
    setVehicleColor ( vehicle, r, g, b )  
    end 
end)        
  
  
    function login () 
    local account = getPlayerAccount( source ) 
    if ( account and not isGuestAccount(account)) then 
    local r = getAccountData( account,"r" ) 
    local g = getAccountData( account,"g" ) 
    local b = getAccountData( account,"b" ) 
    local vehicle = getPedOccupiedVehicle(source) 
    setVehicleColor ( vehicle, r, g, b )        
    end 
    end 
    end 
    end     
    addEventHandler ("onPlayerPickUpRacePickup", root, login) 
    addEventHandler ("onPlayerVehicleEnter", root, login) 
  

the problems i have when i buy color it's buying so good but if i buy another time it's still same color not changing

onPlayerPickUpRacePickup --bad argument got nil

onPlayerVehicleEnter -- bad argument got nil

the problems i have when i buy color it's buying so good but if i buy another time it's still same color not changing

I have another request when I want to change the color sets the color of the car, such as a friendly freeroam

Link to comment
  • Moderators

A lot of little errors and missing stuff:

server:

function Buy(r, g, b) 
    if getPlayerMoney(source) >= 100 then 
        takePlayerMoney(source, 100) 
        local vehicle = getPedOccupiedVehicle(source) 
        setVehicleColor(vehicle, r, g, b) 
        setElementData(source,"r", r) 
        setElementData(source,"g", g) 
        setElementData(source,"b", b) 
    else 
        outputChatBox ("You Don't have $100", source, 255, 0, 0) 
    end 
end 
addEvent("onBuy",true) 
addEventHandler("onBuy", root, Buy) 
  
function Quit() 
    local account = getPlayerAccount( source ) 
    if account and not isGuestAccount(account) then 
        local r = getElementData(source,"r") or 0 
        local g = getElementData(source,"g") or 0 
        local b = getElementData(source,"b") or 0 
        setAccountData(account, "r", r) 
        setAccountData(account, "g", g) 
        setAccountData(account, "b", b) 
    end 
end 
addEventHandler("onPlayerQuit", root, Quit) 
  
addEventHandler( "onPlayerLogin", root, 
function(_, acc) 
    local r = getAccountData(acc, "r") 
    local g = getAccountData(acc, "g") 
    local b = getAccountData(acc, "b") 
    if r and g and b then 
        local vehicle = getPedOccupiedVehicle(source) 
        setVehicleColor ( vehicle, r, g, b ) 
        setElementData(source,"r", r) 
        setElementData(source,"g", g) 
        setElementData(source,"b", b) 
    end 
end)       
  
  
function updateVehicleColor() 
    local account = getPlayerAccount( source ) 
    if account and not isGuestAccount(account) then 
        local r = getElementData(source, "r") or 0 
        local g = getElementData(source, "g") or 0 
        local b = getElementData(source, "b") or 0 
        local vehicle = getPedOccupiedVehicle(source) 
        setVehicleColor(vehicle, r, g, b) 
    end 
end     
addEventHandler ("onPlayerPickUpRacePickup", root, updateVehicleColor) 
addEventHandler ("onPlayerVehicleEnter", root, updateVehicleColor) 
  

client:

local CCar = guiCreateButton(206, 130, 127, 56, "Color", false) 
  
addEventHandler( "onClientGUIClick", resourceRoot, 
function() 
    if ( source == CCar ) then 
        exports.cpicker:openPicker(localPlayer, "#0000FF", "Car Color color picker") 
    end 
end 
) 
  
addEvent ("onColorPickerOK", true ) 
addEventHandler ("onColorPickerOK", root, 
function ( element, hex, r, g, b ) 
    if ( element == localPlayer ) then 
        local r, g, b = tonumber ( r ), tonumber ( g ), tonumber ( b ) 
        triggerServerEvent("onBuy", localPlayer, r, g, b) 
    end 
end 
) 

Link to comment
A lot of little errors and missing stuff:

server:

function Buy(r, g, b) 
    if getPlayerMoney(source) >= 100 then 
        takePlayerMoney(source, 100) 
        local vehicle = getPedOccupiedVehicle(source) 
        setVehicleColor(vehicle, r, g, b) 
        setElementData(source,"r", r) 
        setElementData(source,"g", g) 
        setElementData(source,"b", b) 
    else 
        outputChatBox ("You Don't have $100", source, 255, 0, 0) 
    end 
end 
addEvent("onBuy",true) 
addEventHandler("onBuy", root, Buy) 
  
function Quit() 
    local account = getPlayerAccount( source ) 
    if account and not isGuestAccount(account) then 
        local r = getElementData(source,"r") or 0 
        local g = getElementData(source,"g") or 0 
        local b = getElementData(source,"b") or 0 
        setAccountData(account, "r", r) 
        setAccountData(account, "g", g) 
        setAccountData(account, "b", b) 
    end 
end 
addEventHandler("onPlayerQuit", root, Quit) 
  
addEventHandler( "onPlayerLogin", root, 
function(_, acc) 
    local r = getAccountData(acc, "r") 
    local g = getAccountData(acc, "g") 
    local b = getAccountData(acc, "b") 
    if r and g and b then 
        local vehicle = getPedOccupiedVehicle(source) 
        setVehicleColor ( vehicle, r, g, b ) 
        setElementData(source,"r", r) 
        setElementData(source,"g", g) 
        setElementData(source,"b", b) 
    end 
end)       
  
  
function updateVehicleColor() 
    local account = getPlayerAccount( source ) 
    if account and not isGuestAccount(account) then 
        local r = getElementData(source, "r") or 0 
        local g = getElementData(source, "g") or 0 
        local b = getElementData(source, "b") or 0 
        local vehicle = getPedOccupiedVehicle(source) 
        setVehicleColor(vehicle, r, g, b) 
    end 
end     
addEventHandler ("onPlayerPickUpRacePickup", root, updateVehicleColor) 
addEventHandler ("onPlayerVehicleEnter", root, updateVehicleColor) 
  

client:

local CCar = guiCreateButton(206, 130, 127, 56, "Color", false) 
  
addEventHandler( "onClientGUIClick", resourceRoot, 
function() 
    if ( source == CCar ) then 
        exports.cpicker:openPicker(localPlayer, "#0000FF", "Car Color color picker") 
    end 
end 
) 
  
addEvent ("onColorPickerOK", true ) 
addEventHandler ("onColorPickerOK", root, 
function ( element, hex, r, g, b ) 
    if ( element == localPlayer ) then 
        local r, g, b = tonumber ( r ), tonumber ( g ), tonumber ( b ) 
        triggerServerEvent("onBuy", localPlayer, r, g, b) 
    end 
end 
) 

nothing happened ...

Link to comment
  • Moderators

I need more informations (errors on server and client side). just saying nothing happened doesn't help at all ...

EDIT: Try this client instead:

local CCar = guiCreateButton(206, 130, 127, 56, "Color", false) 
  
addEventHandler( "onClientGUIClick", CCar, function() 
    exports.cpicker:openPicker ( localPlayer, "#0000FF", "Car Color color picker" ) 
end) 
  
addEvent ( "onColorPickerOK", true ) 
addEventHandler ( "onColorPickerOK", root, function ( element, hex, r, g, b ) 
    if ( element == localPlayer ) then 
        local r, g, b = tonumber ( r ), tonumber ( g ), tonumber ( b ) 
        triggerServerEvent("onBuy", localPlayer, r, g, b) 
    end 
end) 

Edited by Guest
Link to comment
when i click nothing happened

And on what are you clicking on ? the CCar button or the color picker ?

You are not really helping me atm. Please tell me the steps you do and which one fails.

i click the CCar button and he take money from my and open the color picker

when i click ok in the color picker it's Should change the color but he is not changing -- no errors

Link to comment
  • Moderators
i click the CCar button and he take money from my and open the color picker

WRONG ! When you click the CCar button, it opens the color picker immediatly without taking money.

It will take your money only when you selected a color.

So here is a simple question: Why are you giving false informations ?

And another one: Do you really want me to help you ?

I just tried the code on my local server, and it's perfectly working ...

Please show me your meta.xml and tell me the 2 files name (ex: XXX.lua and YYY.lua) in which you put the two part of this script.

EDIT: I didn't test the quit and login part of this script but there is no reason it won't work.

Link to comment

oh shit sorry dud

i forget to try this post

I need more informations (errors on server and client side). just saying nothing happened doesn't help at all ...

EDIT: Try this client instead:

local CCar = guiCreateButton(206, 130, 127, 56, "Color", false) 
  
addEventHandler( "onClientGUIClick", CCar, function() 
    exports.cpicker:openPicker ( localPlayer, "#0000FF", "Car Color color picker" ) 
end) 
  
addEvent ( "onColorPickerOK", true ) 
addEventHandler ( "onColorPickerOK", root, function ( element, hex, r, g, b ) 
    if ( element == localPlayer ) then 
        local r, g, b = tonumber ( r ), tonumber ( g ), tonumber ( b ) 
        triggerServerEvent("onBuy", localPlayer, r, g, b) 
    end 
end) 

it's working now thx

and i im sorry,

Link to comment
  • Moderators
i know what i say are you want video to believe ?

No you don't let's read again together:

i click the CCar button and he take money from my
Here you said that it was taking your money when you press the CCar button (which is not true).

and now you just said this:

then i click ok button it's don't do anything my money still same ..!

So you first said that your money was taken and then you say that your money is still the same ....

And I'll repeat again, it's working for me so here is the problem (I knew it was a coming from your meta.xml):

Use " instead of ': (and don't close the tag twice: type="client"/> cache="false"/>)

<script src="shop.lua" type="client"/> 
<script src="server.lua" type="server" /> 

Link to comment
i know what i say are you want video to believe ?

No you don't let's read again together:

i click the CCar button and he take money from my
Here you said that it was taking your money when you press the CCar button (which is not true).

and now you just said this:

then i click ok button it's don't do anything my money still same ..!

So you first said that your money was taken and then you say that your money is still the same ....

And I'll repeat again, it's working for me so here is the problem (I knew it was a coming from your meta.xml):

Use " instead of ': (and don't close the tag twice: type="client"/> cache="false"/>)

<script src="shop.lua" type="client"/> 
<script src="server.lua" type="server" /> 

i now it's my bad i forgat to try your post ^

i im sorry for block your time

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