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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Copy the script again.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Copy the script again, now it works.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

No, actually you put that and I forgot to remove it ;).

Check your first script.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

Everything there is wrong -__-, you can't just expect that every event handler will fit your needs.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

The script doesn't save the color, it'll load it.

P.S: Is not the only thing I changed, are you blind?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

No errors on debug?

P.S: It loads the color when a map starts but not when you change the vehicle?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That script is SERVER SIDE, not client side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Post your complete script, client side and server side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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