PointShop perma weapons

I know this thread has been made several times before, but is there a way to check what weapon the player has, and if it’s not the perma weapon, delete it then replace it with the perma weapon?

Here’s my current code, which works fine except when people pick up another weapon when the round starts. Then they have to go into pointshop, holster it then equip it again.



ITEM.Name = 'M3 (Perm)'
ITEM.Price = 200
ITEM.Model = 'models/weapons/w_shot_m3super90.mdl'
ITEM.WeaponClass = 'weapon_ttt_m3_perm'
ITEM.SingleUse = false

function ITEM:OnBuy(ply)
	ply:Give(self.WeaponClass)
	ply:SelectWeapon(self.WeaponClass)
end

function ITEM:OnSell(ply)
	ply:StripWeapon(self.WeaponClass)
end

function ITEM:OnEquip(ply)
	ply:Give(self.WeaponClass)
	ply:SelectWeapon(self.WeaponClass)
end

function ITEM:OnHolster(ply)
	ply:StripWeapon(self.WeaponClass)
end


I made an edit to it in an attempt to make it work.

It didn’t work and functioned like the above.



ITEM.Name = 'M3 (Perm)'
ITEM.Price = 200
ITEM.Model = 'models/weapons/w_shot_m3super90.mdl'
ITEM.WeaponClass = 'weapon_ttt_m3_perm'
ITEM.SingleUse = false

function ITEM:OnBuy(ply)
	local currentWeapon = ply:GetActiveWeapon():GetClass()
	if not currentWeapon == self.WeaponClass then
		ply:StripWeapon(currentWeapon)
		ply:Give(self.WeaponClass)
		ply:SelectWeapon(self.WeaponClass)
	else
		ply:Give(self.WeaponClass)
		ply:SelectWeapon(self.WeaponClass)
	end
end

function ITEM:OnSell(ply)
	ply:StripWeapon(self.WeaponClass)
end

function ITEM:OnEquip(ply)
	local currentWeapon = ply:GetActiveWeapon():GetClass()
	if not currentWeapon == self.WeaponClass then
		ply:StripWeapon(currentWeapon)
		ply:Give(self.WeaponClass)
		ply:SelectWeapon(self.WeaponClass)
	else
		ply:Give(self.WeaponClass)
		ply:SelectWeapon(self.WeaponClass)
	end
end

function ITEM:OnHolster(ply)
	ply:StripWeapon(self.WeaponClass)
end