Forum

> > CS2D > Scripts > VIP Pick weapons
Forums overviewCS2D overview Scripts overviewLog in to reply

English VIP Pick weapons

5 replies
To the start Previous 1 Next To the start

old VIP Pick weapons

NanuPlayer
User Off Offline

Quote
Is it possible to make the main VIP that is in ct group able to pick weapons? i was wondering if that is even possible or someone could make a script about it

old Re: VIP Pick weapons

Mami Tomoe
User Off Offline

Quote
Possible through scripting but is quite tedious to make.
I could make a script for that later today if nobody snipes me to it.

old Re: VIP Pick weapons

DC
Admin Off Offline

Quote
I'm not sure if cs2d lua hook walkover fires when a VIPs walk over items he can't collect.

If it does you could simply use that in combination with cs2d cmd equip, cs2d cmd setammo and cs2d cmd removeitem.

If it doesn't you would have to use cs2d lua hook movetile and cs2d lua cmd item to first retrieve a list of all items and then details about the item(s) on the specified tile. Then you could use the same commands as mentioned above to "collect" the item(s) (equip same item type, set ammo and remove from map).

In both cases you would also have to check first if the item can be collected (e.g. allow only 1 primary and 1 secondary weapon etc). You can check what the player already carries with cs2d lua cmd playerweapons.

old Re: VIP Pick weapons

cs2d_is_a_Gem
User Off Offline

Quote
@user NanuPlayer: You can also use as skin the image of the VIP and that appears the skin of the VIP in any player of the anti-terrorist team (random) From that code you add a line that allows only to pick up the weapon or any other adjustment, ej: Surely the VIP will be used in an escape or coperacion game mode, at the beginning of the round you give this player who is using the vip image position x and the y position on the tiles of the map, Doing it this way also solves the problem that when the VIP dies the round ends.
edited 2×, last 12.03.23 09:40:19 pm

old Re: VIP Pick weapons

Mami Tomoe
User Off Offline

Quote
I tried making it, it wasn't hard to get to this point but this is far from complete.
I gave up the moment I realised that the command cs2d cmd removeitem did not trigger items to respawn from the cs2d entity env_item entity, which as far as I'm concerned, cannot be fixed by Lua.
I didn't want to finish this with that dead-end in mind.

For whoever wants to pick up from where I left off:
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
local rules = {
	maxPrimaryItems		= 1,
	maxSecondaryItems	= 1
}

-- Items CS2D allows the V.I.P. to pick-up.
local whitelistedItems = {
	[01] = true, -- USP
	[57] = true, -- Kevlar
	[58] = true, -- Kevlar+Helm
	[59] = true, -- Night Vision
	[60] = true, -- Gas Mask
	[62] = true, -- Secondary Ammo
	[64] = true, -- Medikit
	[65] = true, -- Bandage
	[66] = true, -- Coins
	[67] = true, -- Money
	[68] = true, -- Gold
	[70] = true, -- Red Flag
	[79] = true, -- Light Armour
	[80] = true, -- Armour
	[81] = true, -- Heavy Armour
	[82] = true, -- Medic Armour
	[83] = true, -- Super Armour
	[84] = true  -- Stealth Suit
}

-- Items CS2D does not allow the V.I.P. to pick-up.
-- I never got to using this part, and I'm unsure on
-- whether this is even needed.
local blockedItems = {

}

-- Items that the V.I.P. should not pick-up.
local ignoredItems = {
	[55] = true, -- Bomb
	[63] = true, -- Planted Bomb
	[71] = true  -- Blue Flag
}

local function getHeldCount(p, slot)
	local pWpns = playerweapons(p)
	local count = 0

	for _, itemTypeId in pairs(pWpns) do
		if itemtype(itemTypeId, 'slot') == slot then
			count = count + 1
		end
	end

	return count
end

function walkover_hook(p, itemId, itemTypeId, ammoIn, ammo, mode)
	if player(p, 'team') ~= 3 then
		-- Not a V.I.P.

		return
	elseif whitelistedItems[itemTypeId] then

		return
	elseif ignoredItems[itemTypeId] then

		return
	end

	local slot = itemtype(itemTypeId, 'slot')

	if slot == 1 then
		if getHeldCount(p, 1) >= rules.maxPrimaryItems then

			return
		end
	elseif slot == 2 then
		if getHeldCount(p, 2) >= rules.maxSecondaryItems then

			return
		end
	end

	parse('sv_soundpos "items/pickup.wav" ' .. item(itemId, 'x') .. ' ' .. item(itemId, 'y'))
	parse('removeitem "' .. itemId .. '"')

	parse('equip "' .. p .. '" "' .. itemTypeId .. '"')
	parse('setammo "' .. p .. '" "' .. itemTypeId .. '" "' .. ammoIn .. '" "' .. ammo .. '"')
end

local function init()
	-- Hooks.
	addhook('walkover',		'walkover_hook',	 0)
end init()

Problems:
× Cannot properly pick up items that stack (like grenades)
× The above stated issue with cs2d entity env_item
× Possibly more that I never got to find
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview