Jump to content

setElementData, Color


Klesh

Recommended Posts

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) 
  
  

Link to comment

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

Link to comment

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.

Link to comment

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
Link to comment

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) 

Link to comment

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
Link to comment

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