Jump to content

setElementData, Color


Klesh

Recommended Posts

Posted

I was do this code, and is a buy command, the thing is dont set the vehicle color, it saves too.

function colorHandler ( thePlayer, commandName, col1, col2, col3 ) 
    if (playerVehicle) then 
        playerVehicle = getPedOccupiedVehicle(thePlayer) 
        account = getPlayerAccount(thePlayer) 
        setAccountData("color.data", account) 
        exCol1, exCol2, exCol3 = getVehicleColor(thePlayer) 
            if not col1 then col1 = exCol1 end 
            if not col2 then col2 = exCol2 end 
            if not col3 then col3 = exCol3 end 
        setVehicleColor(playerVehicle , col1, col2, col3) 
    else 
        outputChatBox("[Error]: You use /bc [color1 color2 color3]", thePlayer, 255,0 ,0, true) 
        outputChatBox("You can use 3 colors with /bc command", thePlayer, 255, 0, 0, true) 
        outputChatBox("[Error]: This command only works when the player is in the vehicle.", thePlayer, 255, 0, 0, true) 
    end 
  
            if (isPedInVehicle(thePlayer)) then 
                if (getPlayerMoney(thePlayer) ~= 10000) 
                    takePlayerMoney(thePlayer, 10000) 
                    playSoundFrontEnd(thePlayer, 46) 
                    outputChatBox("#2E9AFE[shop]: #FFFFFF" ..getPlayerName(thePlayer).. "#2E9AFE has bought vehicle colors. (/bc)", root, 255, 255, 255, true) 
                else 
                    outputChatBox("[Error]: You don't have enought money to buy.", thePlayer, 255, 0, 0, true) 
                end 
            else 
             outputChatBox("[Error]: This command only works when the player is in the vehicle", thePlayer, 255, 0, 0, true) 
            end 
end                   
) 
addCommnandHandler("bc", colorHandler) 
  
  

Posted

That's just a TOTAL MESS.

function colorHandler ( thePlayer, commandName, r, g, b ) 
    if (not isPedInVehicle(thePlayer)) then outputChatBox("[Error]: This command only works when you're in a vehicle", thePlayer, 255, 0, 0, true) return end 
    if (tonumber(r) and tonumber(g) and tonumber(b)) then 
        local playerVehicle = getPedOccupiedVehicle(thePlayer) 
        local account = getPlayerAccount(thePlayer) 
        if (getPlayerMoney(thePlayer) >= 10000) then 
            takePlayerMoney(thePlayer, 10000) 
            playSoundFrontEnd(thePlayer, 46) 
            setVehicleColor(playerVehicle, tonumber(r), tonumber(g), tonumber(b)) 
            setAccountData(account, "color.data", toJSON({r, g, b})) 
            outputChatBox("#2E9AFE[shop]: #FFFFFF" ..getPlayerName(thePlayer).. "#2E9AFE has bought vehicle colors. (/bc)", root, 255, 255, 255, true) 
        else 
            outputChatBox("[Error]: You don't have enough money.", thePlayer, 255, 0, 0, true)         
        end 
    else 
        outputChatBox("[Error]: Syntax: /bc [r g b]", thePlayer, 255,0 ,0, true) 
    end 
end 
addCommandHandler("bc", colorHandler) 

See if it works (not tested).

Posted

Error "Bad "vehicle" pointer @ getVehicleColor1()"

The command executes good but the color doesnt set, badArgument setVehicleColor.

Posted

Alredy fixed, you missed something, you set setVehicleColor(thePlayer, true), i changed to setVehicleColor(playerVehicle)

but thanks.

Posted

What are you talking about?

My script is correct: setVehicleColor(playerVehicle, tonumber®, tonumber(g), tonumber(b))

Do you see a "thePlayer" or "true" there? I really don't.

Posted

See old code, this one: local r, g, b = getVehicleColor(playerVehicle) and you put local r, g, b = getVehicleColor(thePlayer, true)

Posted

Now im trying to save that data, making a server-side with this:

function onPlayerLogin ( _, thePlayer, account ) 
    local account = getPlayerAccount(thePlayer) 
    local pColor = getAccountData(account, "color.data") 
    if (pColor) then 
        local color = getAccountData("color.data") 
        local r, g, b = unpack(fromJSON(color)) 
        triggerClientEvent(thePlayer,"colorv", thePlayer, "",r,g,b) 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
addEventHandler("onPlayerWasted", getRootElement(), onPlayerLogin) 

addEvent("colorv", true) added in the other script, is the same of up of the topic.

The question, what event handler i can add to get the color when the map is changing?

and when the vehicle take the pickup vehicle change. Thanks for any help.

Posted

The player element of the wasted player triggered by "onPlayerWasted" is 'source'.

Use: "onPlayerPickUpRacePickup" -> Check if the pickup type is "vehiclechange".

And "onVehicleEnter" for when the map starts.

Posted (edited)

I was try with that :

function onPlayerLogin ( _, thePlayer, account, r, g, b ) 
    local account = getPlayerAccount(thePlayer) 
    local pColor = getAccountData(account, "color.data") 
    if (pColor) then 
        local color = getAccountData("color.data") 
        local r, g, b = unpack(fromJSON(color)) 
        triggerClientEvent(thePlayer,"colorv", thePlayer, "",r,g,b) 
        if (color) then 
            local playerVehicle = (getPedOccupiedVehicle(thePlayer) 
            setVehicleColor(playerVehicle, tonumber(r), tonumber(g), tonumber(b), color) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
addEventHandler("onPlayerWasted", thePlayer, onPlayerLogin) 
addEventHandler("onPlayerPickUpRacePickUp", getRootElement, onPlayerLogin) 
addEventHandler("onVehicleEnter", thePlayer, onPlayerLogin) 

When player pickups a vehiclechange, the color purchased on bc command is not saving, or when playerjoins, what code is wrong.

Edited by Guest
Posted

Try this:

function loadVehicleColor ( thePlayer ) 
    local account = getPlayerAccount(thePlayer) 
    local pColor = getAccountData(account, "color.data") 
    if (pColor) then 
        local r, g, b = unpack(fromJSON(pColor)) 
        triggerClientEvent(thePlayer,"colorv", thePlayer, "",r,g,b) 
        local playerVehicle = getPedOccupiedVehicle(thePlayer) 
        if (playerVehicle) then 
            setVehicleColor(playerVehicle, tonumber(r), tonumber(g), tonumber(b)) 
        end 
    end 
end 
  
addEventHandler("onPlayerLogin", getRootElement(), function () loadVehicleColor(source) end) 
addEventHandler("onPlayerWasted", getRootElement(), function () loadVehicleColor(source) end) 
  
addEventHandler("onPlayerPickUpRacePickUp", getRootElement(), 
function (pickupID, pickupType, vehicleModel) 
    if (pickupType == "vehiclechange") then 
        loadVehicleColor(source) 
    end 
end) 
  
addEventHandler("onVehicleEnter", getRootElement(), function (thePlayer) loadVehicleColor(thePlayer) end) 

Posted (edited)

Color saves only when starts another map, but not when player takes a pickup.

Now i see only was fixed:

local r, g, b = unpack(fromJSON(color)) to local r, g, b = unpack(fromJSON(pcolor)) 
  

and

addEventHandler("onVehicleEnter", getRootElement(), function (thePlayer) loadVehicleColor(thePlayer) end) 

Edited by Guest
Posted

Yes i know, i'm not blind what i mean is the color no load when the vehicle change, only that.

PS: Thanks a lot for help me in this script. :D

Im Just learning lua, you have wiki on your head. :lol:

Posted

I was put the file to client, where is the bc command and the event, but in debugscript 3 shows bad argument, isPedInVehicle.

Posted (edited)

Ok, changed, then debug says colorv must be in client, then i put this on client.

addEvent("colorv", true) 
addEventHandler("colorv", root, colorHandler) 
  

the same thing, ispedinvehicle bad argument.

Edited by Guest

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