Forum

> > CS2D > General > Comparing two tables with functions to iterate
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Comparing two tables with functions to iterate

6 replies
To the start Previous 1 Next To the start

old Comparing two tables with functions to iterate

olie18
User Off Offline

Quote
Does this work and how would it:

all_weapons_count = 0
Weapon_list = {list of weapon IDs I add manually}

Function weapon_has(playerweapons(id))
Using ipairs to iterate through. Can't remember the exact code without being at pc.

Function weapon_list_iterations(weapon_list[id])
Same as above

If weapon_has(playerweapons(id)) == weapon_list_iterations(weapon_list[id]) then
all_weapons_count = all_weapons_count + 1
If all_weapons_count == tables.maxn(weapon_list_iterations(id)) then
all_weapons_count = 0
parse("sv_msg2 "..id.." you have every weapon")
End
End

Written very roughly as I'm on my phone and out. The idea is to check if player id has all weapons on the weapon list. Does the if comparison work?

old Re: Comparing two tables with functions to iterate

Masea
Super User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
weaponList = {} --add them here manually

function checkPlayerHas(id)
	local c = #weaponList

	for k, v in pairs(playerweapons(id)) do
		for a, b in pairs(weaponList) do
			if b == v then
				c = c - 1
			end
		end
	end

	return c == 0
end

@user Gaios: You made us both fucked up. What is that...

old Re: Comparing two tables with functions to iterate

Masea
Super User Off Offline

Quote
My code was just about to tell you how should it be looked like.

For making use of, just read this:
1
2
3
4
5
if checkPlayerHas(id) then
	msg2(id, "Player has all the weapons.")
else
	msg2(id, "Player doesn't have all the weapons.")
end

Share the full code with me and I'll try to help you more.

old Re: Comparing two tables with functions to iterate

olie18
User Off Offline

Quote
@user Masea:

Edited my post, I think what you posted would work. I read it too quickly and thought it was just showing how to iterate through one table.

Will update later.

UPDATE:

here's my code so far for anyone interested, the main parts you helped with are in the serveraction and kill hooks. Seem to have got it working, some parts of the code are still a little buggy and most of it is a mess that needs to be cleaned up.

Making a arcade style mod ~

Spoiler >
edited 5×, last 26.11.17 05:59:04 pm
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview