Jump to content

Help - Save Fuel


Recommended Posts

Hello, im having a problem to saving fuel from cars. It's giving me an error on debug in this next line ( Bad Argument 'SetElementData' [expect element at argument 1] )

Thanks for all help! ❤️ 

setElementData(vehicleConces[source], "DNL:Combustivel", vehFuel)

 

Code:

addEvent("Tic.addVeh", true)
addEventHandler("Tic.addVeh", root,
    function(source, model)
        local query = dbPoll(dbQuery(database, "SELECT * FROM playersConce WHERE Account = ?", getAccountName(getPlayerAccount(source))), -1)

        if query and #query > 0 then
            if vehicleConces[source] then
                if isPedInVehicle(source) then
                    local r1, g1, b1, r2, g2, b2, r3, g3, b3 = getVehicleColor(vehicleConces[source], true)
                    local conceSQL = {
                        vehLife = getElementHealth(vehicleConces[source]),
                    
                        vehColor = {
                            r1, g1, b1, 
                            r2, g2, b2, 
                            r3, g3, b3,
                        },
                    
                        vehTunning = {},
                        vehUpgrade = {},
                    }

                    removeElementData(vehicleConces[source], "Tic.vehicleBank")
                    destroyElement(vehicleConces[source])
					local vehFuel = dbPoll(dbQuery(database, "SELECT * FROM playersConce WHERE Account = ?", getAccountName(getPlayerAccount(source))), -1)
                    setElementData(vehicleConces[source], "DNL:Combustivel", vehFuel)

                    dxMsg(source, "Your vehicle was saved in the garage!", "success")
                    dbExec(database, "UPDATE playersConce SET Estado = ?, Dados = ? WHERE Account = ? AND Model = ?", "Garage", toJSON(conceSQL), getAccountName(getPlayerAccount(source)), model)
					dbExec(database, "UPDATE playersConce SET Fuel = ? WHERE Account = ?", getElementData(source, "DNL:Combustivel"), getAccountName(getPlayerAccount(source)))
                else
                    dxMsg(source, "Get inside the vehicle and try again.", "info")
                end
            else
                dxMsg(source, "Your not have a vehicle!", "info")
            end
        end
    end
)

 

Link to comment

 

Code: 

addEvent("Tic.addVeh", true)
addEventHandler("Tic.addVeh", root,
    function(source, model)
        local query = dbPoll(dbQuery(database, "SELECT * FROM playersConce WHERE Account = ?", getAccountName(getPlayerAccount(source))), -1)

        if query and #query > 0 then
            if vehicleConces[source] then
                if isPedInVehicle(source) then
                    local r1, g1, b1, r2, g2, b2, r3, g3, b3 = getVehicleColor(vehicleConces[source], true)
                    local conceSQL = {
                        vehLife = getElementHealth(vehicleConces[source]),
                    
                        vehColor = {
                            r1, g1, b1, 
                            r2, g2, b2, 
                            r3, g3, b3,
                        },
                    
                        vehTunning = {},
                        vehUpgrade = {},
                    }

                    removeElementData(vehicleConces[source], "Tic.vehicleBank")
                    destroyElement(vehicleConces[source])
					local vehFuel = dbPoll(dbQuery(database, "SELECT * FROM playersConce WHERE Account = ?", getAccountName(getPlayerAccount(source))), -1)
                    setElementData(vehicleConces[source], "DNL:Combustivel", vehFuel)

                    dxMsg(source, "Your vehicle was saved in the garage!", "success")
                    dbExec(database, "UPDATE playersConce SET Estado = ?, Dados = ? WHERE Account = ? AND Model = ?", "Garage", toJSON(conceSQL), getAccountName(getPlayerAccount(source)), model)
					dbExec(database, "UPDATE playersConce SET Fuel = ? WHERE Account = ?", getElementData(source, "DNL:Combustivel"), getAccountName(getPlayerAccount(source)))
                else
                    dxMsg(source, "Get inside the vehicle and try again.", "info")
                end
            else
                dxMsg(source, "Your not have a vehicle!", "info")
            end
        end
    end
)

 

About the solve: As I understand, you had destroyed the element before setElementData ( destroyElement(vehicleConces[source] ).

Also in dbExec you're trying to get ElementData from source, not from vehicleConces[source]. 

Edited by Erlkonig
  • Thanks 1
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...