Jump to content

setElementData, Color


Klesh

Recommended Posts

Server - Side

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 for 10000$. (/bc)", root, 255, 255, 255, true) 
        else 
            outputChatBox("[Error]: You don't have enough money to buy.", thePlayer, 255, 0, 0, true)         
        end 
    else 
        outputChatBox("[Error]: Syntax: /bc [r g b]", thePlayer, 255,0 ,0, true) 
    end 
end 
addCommandHandler("bc", colorHandler) 
  
  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) 
  

client-side

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

Link to comment

That's the full client side?? that's useless, the whole script is SERVER SIDE.

I don't even know why you was triggering to the client side, it's just USELESS.

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 for 10000$. (/bc)", root, 255, 255, 255, true) 
        else 
            outputChatBox("[Error]: You don't have enough money to buy.", thePlayer, 255, 0, 0, true)         
        end 
    else 
        outputChatBox("[Error]: Syntax: /bc [r g b]", thePlayer, 255,0 ,0, true) 
    end 
end 
addCommandHandler("bc", colorHandler) 
  
  function loadVehicleColor ( thePlayer ) 
        local account = getPlayerAccount(thePlayer) 
        local pColor = getAccountData(account, "color.data") 
        if (pColor) then 
            local r, g, b = unpack(fromJSON(pColor)) 
            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

Something wrong, with onPlayerPickUpRacePickUp, no loads the color, you right, the event is usseless, thanks about that.

Edit: Alredy fixed, editing a race file and some little things in the script, thanks.

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