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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--------------
-- GLOBALS --
--------------
GRENADE_LIMIT = 4;
---------------------
-- DECLARE HOOKS --
---------------------
-- decide if the player is allowed to collect a grenade
addhook("walkover", "p_walkover");
-- decide if the player is allowed to buy a grenade
addhook("buy", "p_buy");
-------------------
-- HELPER FUNCS --
-------------------
--You can manually add stuff here which should be considered as grenade
function is_grenade_type(item_id)
	local he_flash_smoke_flare = (item_id >= 51 and item_id <= 54);
	local gas_mol = (item_id == 72 or item_id == 73);
	local snow_air = (item_id == 75 or item_id == 76);
	local gut = (item_id == 86);
	local satchel = (item_id == 89);
	return he_flash_smoke_flare or gas_mol or snow_air or gut or satchel;
end
--returns the amount of grenades carried.
--I do not know how this behaves for flash bangs. You should check that.
function p_count_grenades(p_id)
	local p_items = playerweapons(p_id);
	local p_gcount = 0;
	for _,item_id in pairs(p_items) do
		if (is_grenade_type(item_id)) then p_gcount = p_gcount + 1; end
	end
	return p_gcount;
end
function decide_collect_buy(p_id, item_id)
	--Is no grenade? allow collect
	if (not is_grenade_type(item_id)) then return 0; end
	
	--if player grenade limit reached -> no collect
	if (p_count_grenades(p_id) >= GRENADE_LIMIT) then return 1; end
	--The player is allowed to collect
	return 0;
end
---------------------
-- DEFINED HOOKS --
---------------------
function p_walkover(p_id, item_id)
	return decide_collect_buy(p_id, item_id);
end
function p_buy(p_id, item_id)
	return decide_collect_buy(p_id, item_id);
end