Jump to content

Gridlist problem


Bean666

Recommended Posts

why is it like this?

4NhTZeE.png

cost = { 
"1000$", 
"1000$", 
"1000$", 
"1000$" } 
  
spawnG = guiCreateGridList(0.02, 0.04, 0.56, 0.94, true, window) 
guiGridListSetSelectionMode ( spawnG, 2 ) 
local column1 = guiGridListAddColumn(spawnG, "Weapons:", 0.5) 
local column2 = guiGridListAddColumn(spawnG, "Cost:", 0.5) 
  
Cost part: 
for key,cost in pairs(cost) do 
                local row = guiGridListAddRow ( spawnG )  
                guiGridListSetItemText ( spawnG, row, 2, cost, false, false ) 
        end 

Link to comment

it's not what i mean, i want the all the 1000$ up there, they're not the same line as the other rows.

how to fix it?

here is the gridlist/rows part:

  skins = 
            { 
            {"M4", 31}, 
            {"AK47", 30},           
            {"Shotgun", 25},  
            {"Sniper", 34},  
            } 
  
cost = { 
"1000$", 
"1000$", 
"1000$", 
"1000$" } 
  
window = guiCreateWindow(0.31, 0.21, 0.38, 0.63, "Weapon Shop", true) 
guiWindowSetSizable(window, false) 
guiSetVisible(window, false) 
  
spawnG = guiCreateGridList(0.02, 0.04, 0.56, 0.94, true, window) 
guiGridListSetSelectionMode ( spawnG, 2 ) 
local column1 = guiGridListAddColumn(spawnG, "Weapons:", 0.5) 
local column2 = guiGridListAddColumn(spawnG, "Cost:", 0.5) 
  
            for i,skins in ipairs(skins) do 
    row = guiGridListAddRow(spawnG) 
    guiGridListSetItemText(spawnG, row, 1, tostring(skins[1]), false, false) 
    guiGridListSetItemData(spawnG, row, 1, tostring(skins[2])) 
end 
  
for key,cost in pairs(cost) do 
                local row = guiGridListAddRow(spawnG) 
                guiGridListSetItemText ( spawnG, row, 2, cost, false, false ) 
        end 
  
guiGridListAddRow(spawnG) 
spawnbtn = guiCreateButton(0.63, 0.31, 0.30, 0.11, "Buy", true, window) 
cancel = guiCreateButton(0.63, 0.54, 0.30, 0.11, "Cancel", true, window)  
  
function buyweapon() 
    if ( source == spawnbtn ) then 
    local row, col = guiGridListGetSelectedItem( spawnG ) 
    local name = guiGridListGetItemText( spawnG, row, col )  
    if name == "M4" then 
        local id = 31 
        triggerServerEvent("spawn", getLocalPlayer(), id) 
        elseif name == "AK47" then 
        local id = 30 
        triggerServerEvent("spawn2", getLocalPlayer(), id) 
        elseif name == "Shotgun" then 
        local id = 25 
        triggerServerEvent("spawn3", getLocalPlayer(), id) 
        elseif name == "Sniper" then 
        local id = 34 
        triggerServerEvent("spawn4", getLocalPlayer(), id) 
    end 
end 
end 
addEventHandler("onClientGUIClick",root,buyweapon) 
  

Link to comment

are you making another grid list rows in another table or outside the loop?

edit #

do it in one table :

 skins = 
            { 
            {"M4", 31, "1000$"}, 
            {"AK47", 30, "1000$"},           
            {"Shotgun", 25, "1000$"}, 
            {"Sniper", 34, "1000$"}, 
            } 
  
for i,skins in ipairs(skins) do 
    row = guiGridListAddRow(spawnG) 
    guiGridListSetItemText(spawnG, row, 1, skins[1], false, false) 
    guiGridListSetItemText ( spawnG, row, 2, skins[3], false, false ) 
    guiGridListSetItemData(spawnG, row, 1, skins[2]) 
end 

and remove line 35 .

Edited by Guest
Link to comment

edited^

and you can do this :

-- Client side # 
function buyweapon() 
    if ( source == spawnbtn ) then 
        if guiGridListGetSelectedItem( spawnG ) ~= -1 then 
            local name = guiGridListGetItemText( spawnG, guiGridListGetSelectedItem( spawnG ), 1 ) 
            local data = guiGridListGetItemData ( spawnG, guiGridListGetSelectedItem( spawnG ),1 ) 
            triggerServerEvent("spawn", getLocalPlayer(), name, data ) 
        end 
    end 
end 
addEventHandler("onClientGUIClick",root,buyweapon) 

-- Server Side # 
addEvent ( 'spawn', true) 
addEventHandler('spawn', root,function (name, data) 
    outputChatBox ( 'you have been giving a '..name..' weapon', client) 
    giveWeapon ( client, data ) 
end) 

and you can do this with money too.

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