Jump to content

Skip duplicated table values


Miika

Recommended Posts

Hello,

I'm using gridlist sections for weapon classes. I have stored my weapon data in table and i have set each weapon it's own class.

So my problem is this:

It creates section for every weapon, but it should skip if there is already section for class.

Here's how it looks now and how it should not look:

ylFnj8V.jpg

Code:

[Table]:

prices = {
	{ name="Shotgun", id=25, ammo=30, price=700, class="Shotguns", type="everyone" };
	{ name="Sawed-off", id=26, ammo=30, price=650, class="Shotguns", type="everyone" };
	{ name="Combat Shotgun", id=27, ammo=30, price=800, class="Shotguns", type="everyone" };
	
	{ name="Uzi", id=28, ammo=60, price=500, class="Sub-Machine Guns", type="everyone" };
	{ name="MP5", id=29, ammo=60, price=600, class="Sub-Machine Guns", type="everyone" };
	{ name="Uzi", id=32, ammo=60, price=500, class="Sub-Machine Guns", type="everyone" };
		
	{ name="AK-47", id=30, ammo=60, price=800, class="Assault Rifles", type="everyone" };
	{ name="M4", id=31, ammo=60, price=1000, class="Assault Rifles", type="everyone" };
	
	{ name="Rifle", id=33, ammo=60, price=2000, class="Rifles", type="everyone" };
	{ name="Sniper", id=34, ammo=60, price=3000, class="Rifles", type="everyone" };
	
	{ name="Rocket Launcher", id=35, ammo=20, price=7000, class="Heavy Weapons", type="Vip" };
	{ name="Heat-Seeking Rocket Launcher", id=36, ammo=20, price=1000, class="Heavy Weapons", type="Vip" };
	{ name="Minigun", id=38, ammo=2000, price=10000, class="Heavy Weapons", type="Vip" };
}

[Client]:

function drawWeaponsTable(weapons, isVip, vip_discount)
	local weapons = fromJSON(weapons)
	guiGridListClear(gridlist)
	local t = {}
	for i=1, #weapons do
		local value = weapons[i]["class"]
		if t[value] == nil then
			table.insert(t, value)
			local row = guiGridListAddRow(gridlist)
			guiGridListSetItemText(gridlist, row, 1, value, true, false)
		end
		local row = guiGridListAddRow(gridlist)
		guiGridListSetItemText(gridlist, row, 1, weapons[i]["name"], false, false)
	end
end

Hope you understand something :D

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