Forum

> > CS2D > Scripts > Listing player items
Forums overviewCS2D overview Scripts overviewLog in to reply

English Listing player items

9 replies
To the start Previous 1 Next To the start

old Re: Listing player items

Livia
User Off Offline

Quote
user Tobey:
There is a function playerweapons(id) but it returns a table of weapon types not item ids. I don't know why it isn't listed in the help page. Thanks for your suggestion but I can't use any hooks in my script.

old Re: Listing player items

Cure Pikachu
User Off Offline

Quote
I guess this would be it. This one checks for all weapons (including bombs & flags), defuse kits, nightvision googles, gas masks and armors on a living person.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function playeritems(id)
	local t = {}
	if player(id,"exists") and player(id,"health") > 0 then
		for _, w in ipairs(playerweapons(id)) do
			table.insert(t,w)
		end
		if player(id,"defusekit") then
			table.insert(t,56)
		end
		if player(id,"nightvision") then
			table.insert(t,59)
		end
		if player(id,"gasmask") then
			table.insert(t,60)
		end
		if player(id,"armor") >= 1 and player(id,"armor") <= 65 then
			table.insert(t,57)
		end
		if player(id,"armor") >= 66 and player(id,"armor") <= 200 then
			table.insert(t,58)
		end
		if player(id,"armor") > 200 then
			local s = player(id,"armor") - 200
			local r = 78 + s
			table.insert(t,r)
		end
	end
	return t
end

old Re: Listing player items

EngiN33R
Moderator Off Offline

Quote
user Cure Pikachu has written
I guess this would be it. This one checks for all weapons (including bombs & flags), defuse kits, nightvision googles, gas masks and armors on a living person.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function playeritems(id)
	local t = {}
	if player(id,"exists") and player(id,"health") > 0 then
		for _, w in ipairs(playerweapons(id)) do
			table.insert(t,w)
		end
		if player(id,"defusekit") then
			table.insert(t,56)
		end
		if player(id,"nightvision") then
			table.insert(t,59)
		end
		if player(id,"gasmask") then
			table.insert(t,60)
		end
		if player(id,"armor") >= 1 and player(id,"armor") <= 65 then
			table.insert(t,57)
		end
		if player(id,"armor") >= 66 and player(id,"armor") <= 200 then
			table.insert(t,58)
		end
		if player(id,"armor") > 200 then
			local s = player(id,"armor") - 200
			local r = 78 + s
			table.insert(t,r)
		end
	end
	return t
end


In a way irrelevant, since user Livia specifies that he needs item IDs, not item types.

I guess this code would do what you need, user Livia:

1
2
3
4
5
6
7
8
9
10
11
function playeritems(id) --Sorry Pikachu
	local t={}
	for i=0,512 do --Just to be on the safe side, could be less
		if item(i,"exists") then
			if item(i,"player")==id then
				t[#t+1]=i
			end
		end
	end
	return 1
end

It should work.

old Re: Listing player items

Starkkz
Moderator Off Offline

Quote
use playerweapons(id), maybe it's not listed in CS2D Lua commands list, but it works.

Admin/mod comment

Read the topic. 'it returns a table of weapon types not item ids'. /Engi

old Re: Listing player items

Livia
User Off Offline

Quote
user EngiN33R:
It's quite heavy so I'll probably live without it.

user Infinite Rain:
ID is the item's indentifier where Type tells you what kind of item it is. I bet you know the difference between player's id and type (is he bot or not).
edited 1×, last 06.10.12 07:29:57 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview