Sign in to follow this  
Lloyd Logan

Any blatant mistakes?

Recommended Posts

function spawnVeh() 
    local serialz = getPlayerSerial(source) 
    carid = dbQuery(server, "SELECT carid FROM accounts WHERE serial = ?", serialz) 
    local cx = dbQuery(server, "SELECT cx FROM accounts WHERE serial = ?", serialz) 
    local cy = dbQuery(server, "SELECT cy FROM accounts WHERE serial = ?", serialz) 
    local cz = dbQuery(server, "SELECT cz FROM accounts WHERE serial = ?", serialz) 
    veh = createVehicle(carid, cx, cy, cz)   
end 
addEventHandler("onPlayerJoin", getRootElement(), spawnVeh) 

Expected number for the createvehicle, but the returned should be a number from the table.

Share this post


Link to post

Try this:

function spawnVeh() 
    local serialz = getPlayerSerial(source) 
    local database = dbQuery(server, "SELECT * FROM accounts WHERE serial = ?", serialz) 
    if #database > 0 then 
        local id, x, y, z = tonumber(database[1].carid), tonumber(database[1].cx), tonumber(database[1].cy), tonumber(database[1].cz) 
        veh = createVehicle ( id, x, y, z )  
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), spawnVeh) 

Share this post


Link to post

Your code is missing dbPoll.

local queryResult = dbQuery(server, "SELECT * FROM accounts WHERE serial = ?", serialz) 
local database = dbPoll(queryResult, -1) 

The rest as above.

Share this post


Link to post

You can selects multiple columns with one query, dbPoll is required to get the result.

See the syntax here: http://www.w3schools.com/sql/sql_select.asp

function spawnVeh() 
    local serialz = getPlayerSerial(source) 
    local result = dbPoll(dbQuery(server, "SELECT carid, cx, cy, cz FROM accounts WHERE serial = ?", serialz), -1) 
    if result and type(result) == "table" and #result > 0 then 
        veh = createVehicle(result[1]["carid"], result[1]["cx"], result[1]["cy"], result[1]["cz"]) 
    end 
end 
addEventHandler("onPlayerJoin", root, spawnVeh) 

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.