Forum

> > CS2D > Scripts > Drop Gas mask
Forums overviewCS2D overview Scripts overviewLog in to reply

English Drop Gas mask

8 replies
To the start Previous 1 Next To the start

old Drop Gas mask

NanuPlayer
User Off Offline

Quote
Hi us again...
i want if you type !dropgasmask you drop gas mask if anyone can do this little script pls help... cuz im not that scripter

old Re: Drop Gas mask

ttoni
User Off Offline

Quote
It needs to be finalized, just a "sketch"

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
addhook("say", "say")
addhook("die", "die")
addhook("spawn", "spawn")

local isDroppedMask = {}
local wpnList = {}

function say(pid, msg)
	if(msg == "!dropgasmask") then
		if(player(pid, "gasmask") == true) then
			isDroppedMask[pid] = true
			local itemlist = playerweapons(pid)
			wpnList[pid] = {}
			for _,iid in pairs(itemlist) do
				table.insert(wpnList[pid], itemtype(iid, "name"))
			end
			itemlist = nil
			parse("killplayer "..tostring(pid))
		end
	end
end

function die(victim, killer, weapon, x, y, killerobject)
	if(isDroppedMask[victim] == true) then
		parse("spawnplayer "..tostring(victim).." "..tostring(x).." "..tostring(y))
		return 1
	end
	return 0
end

function spawnEquip(pid)
	pid = tonumber(pid)
	for _,itemType in pairs(wpnList[pid]) do
		parse("equip "..tostring(pid).." "..tostring(itemType))
	end
	parse("spawnitem 60 "..tostring(player(pid, "tilex")).." "..tostring(player(pid, "tiley")))
end

function spawn(pid)
	if(isDroppedMask[pid] == true) then
		isDroppedMask[pid] = false
		timer(10, "spawnEquip", tostring(pid), 1)
	end
	
	return ""
end

old Re: Drop Gas mask

Cure Pikachu
User Off Offline

Quote
Like what user Mami Tomoe said, the workaround exists because you can't do a
strip *id* 60
console command to remove the gas mask from your inventory.
With that in mind, this is my approach to it. I just recycled the function I made 9 years ago so not sure if it works now.
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
function strip(id,item)
     if player(id,"exists") and player(id,"health") > 0 then -- Cheap precautions
          local armor, hp, mhp, wpnlist, x, y
          armor = player(id,"armor")
          hp = player(id,"health")
          mhp = player(id,"maxhealth")
          wpnlist = playerweapons(id)
          x = player(id,"x")
          y = player(id,"y")
          local df = false
          local nv = false
          local gm = false
          if player(id,"defusekit") then df = true end
          if player(id,"nightvision") then nv = true end
          if player(id,"gasmask") then gm = true end
          if item == 56 or item == 59 or item == 60 then
               parse("spawnplayer "..id.." "..x.." "..y)
               parse("setmaxhealth "..id.." "..mhp)
               parse("sethealth "..id.." "..hp)
               parse("setarmor "..id.." "..armor)
               for _, w in ipairs(wpnlist) do
                    parse("equip "..id.." "..w)
               end
               if item == 56 then
                    if nv == true then parse("equip "..id.." 59") end
                    if gm == true then parse("equip "..id.." 60") end
               elseif item == 59 then
                    if df == true then parse("equip "..id.." 56") end
                    if gm == true then parse("equip "..id.." 60") end
               elseif item == 60 then
                    if df == true then parse("equip "..id.." 56") end
                    if nv == true then parse("equip "..id.." 59") end
               end
          else
               parse("strip "..id.." "..item)
          end
     end
end

addhook("say","_say")
function _say(id,txt)
	if txt == "!dropgasmask" then
		if player(id,"gasmask") then
			local tx, ty = player(id,"tilex"), player(id,"tiley")
			parse("spawnitem 60 "..tx.." "..ty)
			strip(id,60)
		end
	end
end
edited 1×, last 06.05.21 11:56:52 pm

old Re: Drop Gas mask

Mami Tomoe
User Off Offline

Quote
@user Cure Pikachu: It does not work, we're required to kill the player, simply spawning the player will not work.

EDIT:
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
MT = { lock_gasmask = { } }

function MT.walkover_hook(p, itemID, itemType, ammoIn, ammo, mode)
	if itemType == 60 and MT.lock_gasmask[p] then

		return 1
	end
end

function MT.say_hook(p, message)
	if message == '!dropgasmask' then
		MT.lock_gasmask[p] = true

		local x, y = player(p, 'x'), player(p, 'y')

		parse('customkill "0" "Server" "' .. p .. '"')
		parse('setdeaths "' .. p .. '" "' .. player(p, 'deaths') - 1)
		parse('spawnplayer "' .. p .. '" "' .. x .. '" "' .. y .. '"')

		MT.lock_gasmask[p] = nil
	end
end

local function init()
	addhook('walkover',	'MT.walkover_hook')
	addhook('say',		'MT.say_hook')
end
init()

This works better, but has a few downsides due to CS2D's limitations.

√ This will make the player drop their Gas Mask.
× This will kill the player (but re-spawn them and reduce the death counter.
× This will end the round, if the player was the last one alive on their team on a standard game mode.
× On cases where the player gets weapons on spawn (either by the map, or another Lua script) the weapons will duplicate (can be fixed, but may be complicated to beginners).
× May not be reliable under bigger scripts, unless properly handled.

old Re: Drop Gas mask

Mami Tomoe
User Off Offline

Quote
user NanuPlayer has written
@user Mami Tomoe: its spawn gas mask gas mask will still in your head and also make you drop all your weapons there is lot bugs


No, it works, I tried it without any other script, you probably have other scripts running that break it.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview