xyz Posted August 7, 2016 Posted August 7, 2016 So I'm trying to make a vehicle system, and I can't get the stuff from SQL database to gridlist. -- Client function insertVehs(res) for _, vehn in ipairs(res) do local num, model, x, y, z, yRot, r, g, b, fuel, hp, plate, upgrades = unpack(vehn) local row = guiGridListAddRow(p.g) guiGridListSetItemText(p.g, row, 1, num, false, false) guiGridListSetItemText(p.g, row, 2, getVehicleNameFromModel(model), false, false) guiGridListSetItemText(p.g, row, 3, hp, false, false) guiGridListSetItemText(p.g, row, 4, fuel, false, false) end end addEvent("vehs:insertVehsIntoGui", true) addEventHandler("vehs:insertVehsIntoGui", root, insertVehs) bindKey("F3", "down", "vehicles") function openPGui() local state = not guiGetVisible(p.w) guiSetVisible(p.w, state) showCursor(state) triggerServerEvent("vehs:getVehicles", localPlayer) end addCommandHandler("vehicles", openPGui) -- Server function getActualVehs(qh, source) local res = dbPoll(qh, 0) triggerClientEvent(source, "vehs:insertVehsIntoGui", source, res) end function getVeh() local acc = getPlayerAccount(client) local accn = getAccountName(acc) dbQuery(getActualVehs, {client}, con, "SELECT * FROM "..accn) end addEvent("vehs:getVehicles", true) addEventHandler("vehs:getVehicles", root, getVeh)
_DrXenon Posted August 7, 2016 Posted August 7, 2016 try not to use 'source' as a parameter. Maybe change it with something different.
xyz Posted August 8, 2016 Author Posted August 8, 2016 I changed it, these are the errors I get. And yes the vehicles are saved to the database.
N3xT Posted August 9, 2016 Posted August 9, 2016 Try that. function insertVehs(res) for _, vehn in ipairs(res) do local num, model, x, y, z, yRot, r, g, b, fuel, hp, plate, upgrades = unpack(vehn) local row = guiGridListAddRow(p.g) guiGridListSetItemText(p.g, row, 1, tostring(num), false, false) guiGridListSetItemText(p.g, row, 2, tostring(getVehicleNameFromModel(model)), false, false) guiGridListSetItemText(p.g, row, 3, tostring(hp), false, false) guiGridListSetItemText(p.g, row, 4, tostring(fuel), false, false) end end addEvent("vehs:insertVehsIntoGui", true) addEventHandler("vehs:insertVehsIntoGui", root, insertVehs) bindKey("F3", "down", "vehicles") function openPGui() local state = not guiGetVisible(p.w) guiSetVisible(p.w, state) showCursor(state) triggerServerEvent("vehs:getVehicles", localPlayer) end addCommandHandler("vehicles", openPGui)
xyz Posted August 9, 2016 Author Posted August 9, 2016 Doesn't work, the problem here is that it doesn't get the stuff from the table, it just inserts nil and false into the gridlist.
ozulus Posted August 9, 2016 Posted August 9, 2016 Do you create new table for every users? If not, you are wrong. It should be like that. dbQuery(getActualVehs, {client}, con, "SELECT * FROM tableName WHERE accountNameColumn = "..accn)
xyz Posted August 9, 2016 Author Posted August 9, 2016 I do create a new table for every new user addEventHandler("onPlayerLogin", root, function() local acc = getPlayerAccount(source) local accn = getAccountName(acc) dbExec(con, "CREATE TABLE IF NOT EXISTS "..accn.." ('num', 'model', 'x', 'y', 'z', 'yRot', 'r', 'g', 'b', 'fuel', 'hp', 'plate', 'upgrades')") end)
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