Forum

> > CS2D > Scripts > How to set stacked item count
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to set stacked item count

5 replies
To the start Previous 1 Next To the start

old How to set stacked item count

Mami Tomoe
User Off Offline

Quote
Hello, how can one approach setting a stacked item's amount in a player's inventory?

For example, player A has 2 Flashbangs, and I want them to only have one, how can I change it to 1?

cs2d cmd setammo does not work.

Currently the best approach I found was using cs2d cmd spawnitem and cs2d cmd setpos, but that's less reliable than I'd prefer due to it depending on a 0 millisecond timer.

Thank you.

old only 1 flashbang

ttoni
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("walkover", "walkover")

function walkover(pid, iid, type, ain, a, mode)
	if(type == 52) then--flashbang
		local wpns = playerweapons(pid)
		for _, wpntype in pairs(wpns) do
			if(wpntype == 52) then
				return 1--don't collect
			end
		end
	end
	return 0
end

Is it what you want?

old Re: How to set stacked item count

DX
User Off Offline

Quote
@user ttoni:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end

flsh=initArray(32)

addhook("drop","drop")
function drop(id,wpn)
  if flsh[id]==1 then
    flsh[id]=0
  end
end

addhook("collect","clct")
function clct(id,wpn)
  if wpn==52 then
    if flsh[id]==0 then
      flsh[id]=1
    end
  end
end

addhook("attack","att")
function att(id,wpn)
  if wpn==52 then
    if flsh[id]==1 then
      flsh[id]=0
    end
  end
end

addhook("walkover","wlk")
function wlk(id,wpn)
  if wpn==52 then
  if flsh[id]==1 then
    flsh[id]=0
    return 1
  end
  end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview