John_Scott Posted October 30, 2014 Share Posted October 30, 2014 Hi! Can someone help me with add items to a GridList from an array? I would like to set weapon IDs, Names, Prices in a Array, like this: weapons = { "31";"M4";"100", "29";"MP5";"75", "30";"AK47";"90" } Place the ID to the first column, the name to the second and the price to the third. Thanks for the helps! Link to comment
-.Paradox.- Posted October 30, 2014 Share Posted October 30, 2014 I made this along time ago, try it(opens and close with 'shop') Client: GUI = { Button = {}, Window = {}, Gridlist = {} } local weaponItems = { {'Bat', 500, 5, 500}, {'Chainsaw', 5000, 9, 1}, {'Knife', 500, 4, 500}, {'Katana', 3000, 8, 500}, {'Shovel', 5000, 6, 1}, {'Colt-45', 1000, 23, 500}, {'Silenced Pistol', 2500, 22, 500}, {'Desert Eagle', 2000, 24, 500}, {'Sawn-Off Shotgun', 4700, 26, 500}, {'Shotgun', 5000, 25, 500}, {'SPAZ-12', 4000, 27,500}, {'Uzi', 7500, 28, 500}, {'Tec-9', 7500, 32, 500}, {'MP5', 10500, 29, 500}, {'AK-47', 5000, 30, 500}, {'M4', 9000, 31, 500}, {'Country Rifle', 3000, 33, 500}, {'Sniper Rifle', 6000, 34, 500}, {'Rocket Launcher', 10000, 35, 500}, {'Heat-Seeking RPG', 10000, 36, 500}, {'Grenade', 3500, 16, 500}, {'Molotov Cocktails', 1500, 18, 500}, {'Satchel Charges', 1500, 39, 50}, {'Tear Gas', 300, 17, 500}, } addEventHandler('onClientResourceStart', resourceRoot, function() GUI.Window[1] = guiCreateWindow(510, 337, 287, 336, "Shop", false) guiSetAlpha(GUI.Window[1], 1.00) GUI.Gridlist[1] = guiCreateGridList(9, 24, 268, 255, false, GUI.Window[1]) guiGridListAddColumn(GUI.Gridlist[1], "ID", 0.2) guiGridListAddColumn(GUI.Gridlist[1], "Weapons", 0.4) guiGridListAddColumn(GUI.Gridlist[1], "$", 0.2) for i, v in pairs(weaponItems) do -- Note v is a table value. local weaponName = v[1] local weaponCost = v[2] local weaponID = v[3] local weaponAmmo = v[4] local hiddenData = {weaponAmmo} local theRow = guiGridListAddRow(GUI.Gridlist[1]) guiGridListSetItemText(GUI.Gridlist[1], theRow, 1, weaponID, false, false) guiGridListSetItemText(GUI.Gridlist[1], theRow, 2, weaponName, false, false) guiGridListSetItemText(GUI.Gridlist[1], theRow, 3, weaponCost, false, false) guiGridListSetItemData(GUI.Gridlist[1], theRow, 1, hiddenData) end GUI.Button[1] = guiCreateButton(180, 289, 87, 38, "Close", false, GUI.Window[1]) GUI.Button[2] = guiCreateButton(19, 287, 87, 39, "Buy", false, GUI.Window[1]) guiSetVisible(GUI.Window[1], false) showCursor(false) end ) function enableOrDisableShop() if guiGetVisible(GUI.Window[1]) == false then guiSetVisible(GUI.Window[1], true) showCursor(true) updateWeaponGridList() else guiSetVisible(GUI.Window[1], false) showCursor(false) end end addCommandHandler("shop", enableOrDisableShop) function updateWeaponGridList() guiGridListClear(GUI.Gridlist[1]) for i, v in pairs(weaponItems) do -- Note v is a table value. local weaponName = v[1] local weaponCost = v[2] local weaponID = v[3] local weaponAmmo = v[4] local hiddenData = {weaponAmmo} local theRow = guiGridListAddRow(GUI.Gridlist[1]) guiGridListSetItemText(GUI.Gridlist[1], theRow, 1, weaponID, false, false) guiGridListSetItemText(GUI.Gridlist[1], theRow, 2, weaponName, false, false) guiGridListSetItemText(GUI.Gridlist[1], theRow, 3, weaponCost, false, false) guiGridListSetItemData(GUI.Gridlist[1], theRow, 1, hiddenData) end end addEventHandler("onClientGUIClick", guiRoot, function() if source == GUI.Button[2] then local row = guiGridListGetSelectedItem(GUI.Gridlist[1]) if row then local weaponID = guiGridListGetItemText(GUI.Gridlist[1], row, 1) local weaponName = guiGridListGetItemText(GUI.Gridlist[1], row, 2) local weaponCost = guiGridListGetItemText(GUI.Gridlist[1], row, 3) local hiddenData = guiGridListGetItemData(GUI.Gridlist[1], row, 1) local weaponAmmo = hiddenData[1] triggerServerEvent("onWeaponBought", localPlayer, weaponName, weaponCost, weaponID, weaponAmmo) end elseif source == GUI.Button[1] then enableOrDisableShop() end end) Server: addEvent("onWeaponBought", true) addEventHandler("onWeaponBought", root, function(weaponName, weaponCost, weaponID, weaponAmmo) if getPlayerMoney (source) >= tonumber(weaponCost) then takePlayerMoney (source, weaponCost) giveWeapon ( source, weaponID, weaponAmmo ) outputChatBox('You have just bought #FFFFFF('..weaponName..')!', source, 255, 0, 0, true) else outputChatBox('This weapon require #FFFFFF$'..tonumber(weaponCost)..'#FF0000.', source, 255, 0, 0, true) end end) Link to comment
John_Scott Posted October 31, 2014 Author Share Posted October 31, 2014 Thank you very much! Link to comment
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