Lloyd Logan Posted January 17, 2014 Posted January 17, 2014 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.
3NAD Posted January 17, 2014 Posted January 17, 2014 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)
Jusonex Posted January 17, 2014 Posted January 17, 2014 Your code is missing dbPoll. local queryResult = dbQuery(server, "SELECT * FROM accounts WHERE serial = ?", serialz) local database = dbPoll(queryResult, -1) The rest as above.
TAPL Posted January 18, 2014 Posted January 18, 2014 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now