Forum

> > CS2D > Scripts > Check if Player has already specific weapon
Forums overviewCS2D overview Scripts overviewLog in to reply

English Check if Player has already specific weapon

2 replies
To the start Previous 1 Next To the start

old Check if Player has already specific weapon

Karvaparta
User Off Offline

Quote
Hello,
Is it possible to check if player has specific weapon when he uses "script shop", E.g. equip "..id.." 46 / Flamethrower.
If the player already has this item it will still remove -200 points from him but give him nothing. I'm trying to block this with some kinda of error message like "msg2(id,"©255000000You already have this!@C")" -> end
Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
if title == "Special Weapons" then
		if sel == 1 then
			if ms.money[id] > 199 then
				parse("equip "..id.." 46")
				msg2(id,"©000255000You've buy Flamethrower!@C")
				ms.money[id]=ms.money[id]-200
				ms.moneyshow(id)
			else
				msg2(id,"©255000000You have not enouch money!@C")
			end
		end

Here is the shop "base" that I'm using:

Spoiler >

old Re: Check if Player has already specific weapon

Mami Tomoe
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
local function hasWeapon(p, weapon)
	for _, w in pairs(playerweapons(p)) do
		if w == weapon then
			
			return true
		end
	end
	
	return false
end

This might work, untested.
Place this above everything if you don't know how local functions work, or just remove the local part.

old Re: Check if Player has already specific weapon

Marcell
Super User Off Offline

Quote
yeah, that should kinda work. then just pass the function like hasweapon() == true and if thats the case msg2...

otherwise remove the 200 points and give him the flamethrower. If u stuck, add me on Discord and I will try to help. Or just join the Discord server and look for cs2d-scripting channel.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview