Jump to content

Solved


1LoL1

Recommended Posts

Who's "source" or "sorce"

and setElementData(sorce, "all", r,g,b)

should be setElementData(sorce, "all", {r,g,b})

Yeah I looked over the table in setElementData

setElementData(source, "all", {r,g,b}) -- this has to be source instead of sorce probably 
  
addEventHandler("onVehicleEnter", getRootElement(), 
function (player) 
    local colors = getElementData(player, "all") -- by calling it r, g, b you use 3 variables but the table only needs 1 
    local r, g, b = unpack(colors) -- here you go from 1 table to 3 variables 
    setVehicleHeadLightColor(source, r, g, b) 
end) 

When i use your code i have this error:

bad argument #1 to 'unpack' (table expected, got nil)

addCommandHandler("colors",  
function (source) 
local colors = getElementData(source, "all") 
local r, g, b = unpack(color) 
outputChatBox("Colors: "..r..", "..g..", "..b.."", source, 255, 255, 255, true) 
end) 

Link to comment
  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

You keep changing your code just show the ENTIRE code. It's not like we're about to steal it because we can write it as well.

function (source) has to be function () (if this is client sided)

Else you make source = commandName

let me see the setElementData function because I don't know what the source is right now.
Link to comment
You keep changing your code just show the ENTIRE code. It's not like we're about to steal it because we can write it as well.

function (source) has to be function () (if this is client sided)

Else you make source = commandName

let me see the setElementData function because I don't know what the source is right now.

What? this is server-side. And this is next code i want only know how color i have.

Link to comment
Well I'll help you if I see the entire deal, I have no idea right know what you are trying to do. The example is correct.

Now i'am trying to save.

This save work normally:

local r = getElementData(source, "r") 
local g = getElementData(source, "g") 
local b = getElementData(source, "b") 
dbExec(db, "INSERT INTO RGB (Name, Account, RGB) VALUES (?, ?, ?)", name, account, ""..r..", "..g..", "..b.."" 

When i want load RGB values not work idk how to:

setElementData(source, "RGB", poll[1]["RGB"]) 

Link to comment
Show us how you are using poll.

Although you could open your database and look if it saved.

he's not planning on showing the code this is all we get to fix it. I've tried speaking to him but hé only wants to do it in skype.

Yes because you want full code. And i can't share full code because there i have save system.

Link to comment
We cant see how you are loading.

How can you expect us to know where the problem is?

Here:

local r = getElementData(source, "r") 
local g = getElementData(source, "g") 
local b = getElementData(source, "b") 
 dbExec(db, "INSERT INTO RGB (Name, Account, RGB) VALUES (?, ?, ?)", name, account, ""..r..", "..g..", "..b.."") 

in database is "255, 255, 255"

But idk how i can load 3x getElementData to 1x getElementData

function loadd (source) 
    local account = getAccountName(source) 
    local result = dbQuery ( database ,"SELECT * FROM RGB WHERE Account = ?", account) 
    local poll, rows = dbPoll(result, -1) 
    if rows == 1 then 
        setElementData(source, "RGB", poll[1]["HERE IDK HOW"]) 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), loadd) 

because i want use it to Vehicle Lights and there i need r, g, b.

Link to comment
function loadd (source) 
    local account = getAccountName(source) 
    local query = dbQuery ( database ,"SELECT * FROM RGB WHERE Account = ?", account) 
    local result = dbPoll(query, -1) 
    if result then 
        for _, row in ipairs (result) do 
            -- here you can use row or get the column: row["column"] or use a 2nd loop for the column 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), loadd) 

If I'm right tho

Link to comment
function loadd (source) 
    local account = getAccountName(source) 
    local query = dbQuery ( database ,"SELECT * FROM RGB WHERE Account = ?", account) 
    local result = dbPoll(query, -1) 
    if result then 
        for _, row in ipairs (result) do 
            -- here you can use row or get the column: row["column"] or use a 2nd loop for the column 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), loadd) 

If I'm right tho

I don't understand this

-- here you can use row or get the column: row["column"] or use a 2nd loop for the column

Link to comment
You were trying to do something with your rows but didn't access them right. What exactly are you trying to do? what is your script's idea? I also don't know how your table is build up.

??? i don't know what do you mean with row["column"] mean row["1"] ?

Link to comment
function loadd (_, acc) 
    local account = getAccountName(acc) 
    local result = dbQuery ( database ,"SELECT RGB FROM RGB WHERE Account = ?", account) 
    local poll = dbPoll(result, -1) 
    if poll and poll[1] then 
        setElementData(source, "RGB", poll[1]["RGB"]) 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), loadd) 

Try that ...

onPlayerLogin gives you 3 arguments:

The first is the previous acc, the second is the current acc and the third is a boolean for auto-login.

You used the first argument, the previous acc.

But I think you want to get the RGB for the current acc, not previous.

Then you used source for the source (player) and for the previous acc.

That can't work

Link to comment
function loadd (_, acc) 
    local account = getAccountName(acc) 
    local result = dbQuery ( database ,"SELECT RGB FROM RGB WHERE Account = ?", account) 
    local poll = dbPoll(result, -1) 
    if poll and poll[1] then 
        setElementData(source, "RGB", poll[1]["RGB"]) 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), loadd) 

Try that ...

onPlayerLogin gives you 3 arguments:

The first is the previous acc, the second is the current acc and the third is a boolean for auto-login.

You used the first argument, the previous acc.

But I think you want to get the RGB for the current acc, not previous.

Then you used source for the source (player) and for the previous acc.

That can't work

Now in database is "255, 255, 255"

but when i go setElementData(source, "RGB" its 3 in 1. So now how i can get to Car Lights???

Example:

local w = {255,255,255} 
r = w[1] 
g = w[2] 
b = w[3] 

and lights will normally r, g, b

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