Jump to content

SQL to gridlist


xyz

Recommended Posts

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) 

Link to comment

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) 
Link to comment

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) 

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