Forum

> > CS2D > General > Comparing two tables with functions to iterate
ForenübersichtCS2D-ÜbersichtGeneral-ÜbersichtEinloggen, um zu antworten

Englisch Comparing two tables with functions to iterate

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Comparing two tables with functions to iterate

olie18
User Off Offline

Zitieren
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?

alt Re: Comparing two tables with functions to iterate

Masea
Super User Off Offline

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

alt Re: Comparing two tables with functions to iterate

Masea
Super User Off Offline

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

alt Re: Comparing two tables with functions to iterate

olie18
User Off Offline

Zitieren
@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 >
5× editiert, zuletzt 26.11.17 17:59:04
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenGeneral-ÜbersichtCS2D-ÜbersichtForenübersicht