Forum

> > CS2D > Scripts > Check if Player has already specific weapon
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Check if Player has already specific weapon

2 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Check if Player has already specific weapon

Karvaparta
User Off Offline

Zitieren
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 >

alt Re: Check if Player has already specific weapon

Mami Tomoe
User Off Offline

Zitieren
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.

alt Re: Check if Player has already specific weapon

Marcell
Super User Off Offline

Zitieren
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht