English Comparing two tables with functions to iterate

6 replies
Goto Page
To the start Previous 1 Next To the start
Up
olie18
User
Offline Off
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?
26.11.17 12:54:17 pm
Up
Gaios
Security Supporter
Offline Off
26.11.17 12:56:22 pm
Up
Masea
Super User
Offline Off
Code:
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...
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
26.11.17 01:04:47 pm
Up
olie18
User
Offline Off
@user Masea:

EDIT: reread what you posted, makes sense. I'll try it later, thank you.
edited 1×, last 26.11.17 01:10:16 pm
26.11.17 01:09:51 pm
Up
Masea
Super User
Offline Off
My code was just about to tell you how should it be looked like.

For making use of, just read this:
Code:
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.
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
26.11.17 01:12:31 pm
Up
Cure Pikachu
User
Offline Off
@user olie18: Not exactly. For example, the weapon list of yours has 5 items in it. What if you have those 5 items plus an additional one?
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
26.11.17 01:12:48 pm
Up
olie18
User
Offline Off
@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