Forum

> > CS2D > Scripts > How to strip/force drop a specific weapon
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to strip/force drop a specific weapon

3 replies
To the start Previous 1 Next To the start

old How to strip/force drop a specific weapon

Casper-
User Off Offline

Quote
My goal is to use make a lua script from which players will buy using score points.
(I want to completely disable the in-game buyzone shop since the price is not customizable.)
Now the thing is when I try to "buy" (using equip "..id..") a weapon from a lua script, the player gets 1 additional weapon instead of dropping the previous one. How do I strip/force drop a weapon?

While thinking about how to do it I thought of giving each player a variable set to 1, once they have picked/bought a primary weapon. On death, it would reset to 0. Would this be simpler? (Which also gave me an idea for carry weight of weapons similar to Killing Floor 2 if anyone played it.)

old Re: How to strip/force drop a specific weapon

WatPz
User On Online

Quote
Just use "playerweapons" to check that
And use "strip", "spawnitem", "sv_soundpos" to stimulate the action which player will perform when he press the drop key "G"

Don't forget the "equip"

old Re: How to strip/force drop a specific weapon

Bowlinghead
User Off Offline

Quote
You can check the playerweapons. I dont think there is a primary/secondary check in the game, so I just made one.

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
function forceDrop(pid, wpn)
	local in, spare = playerammo(pid, wpn)
	parse("spawnitem "..wpn.." "..player(pid,"tilex").." "..player(pid,"tiley").." "..in.." "..spare)
	parse("strip "..pid.." "..wpn)
	
end

function myBuyMenuBuy(pid, wpn)
	local pwpns = playerweapons(pid)
	if (isPrimary(wpn) and hasPrimary(pid, pwpns) ) then
		forceDrop(pid, wpn)
	elseif (isSecondary(wpn) and hasSecondary(pid, pwpns)) then
		forceDrop(pid, wpn)
	end
	parse("equip "..pid.." "..wpn)
end

function hasPrimary(pid, pwpns)
	for _,wpn in pairs(pwpns) do
		if (isPrimary(wpn)) then
			return true;
		end
	end
	return false;
end


function isPrimary(wpn)
	if (wpn >= 10 and wpn < 50) then
		return true;
	end
		
	if (wpn >= 90 and wpn <= 91) then
		return true;
	end
		
	if (wpn == 88) then
		return true;
	end
	return false;
end

Edit:
Applied user Cure Pikachu bug fix
edited 1×, last 23.12.23 12:49:58 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview