Custom pointshop item issue

Greetings all,

I’ve written a custom melee weapon replacer for my TTT server. Everythign works fine, you equip the item in the pointshop, it removes the default melee weapon and equips the new one instead. You sell the weapon, you get the default one back etc. When you sell the weapon if dead, you obviously only get the default one back when you’re alive.

The issue I’m having is as follows:

When you load into my server and you’re in the spectate mode (the one you’re in when you join a server while a round is still ongoing) If you sell your weapon at this point in the pointshop, the spectator WILL get the default weapon. He can then fly around and melee people in spectate mode untill the current round has ended. From this point everything functions normally again.

I reckon what I’m missing here is a check to see if he’s in the “joining” spectate mode since IsSpec() is clearly not working on this bit. Any help would be greatly appreciated.


ITEM.Name ='Baseball Bat'
ITEM.Price = 5000
ITEM.Model ='models/weapons/w_basebat.mdl'
ITEM.WeaponClass = 'weapon_zm_basebat'
ITEM.SingleUse = false
ITEM.SubCategory = "Melee"
function ITEM:OnEquip(ply)
ply:StripWeapon('weapon_zm_improvised')
	ply:Give('weapon_zm_basebat')
	ply:SelectWeapon('weapon_zm_basebat')
end

function ITEM:OnHolster(ply)
	ply:StripWeapon('weapon_zm_basebat')
	ply:Give('weapon_zm_improvised')
	ply:SelectWeapon('weapon_zm_improvised')
end

function ITEM:OnSell(ply)
    if !ply:IsSpec() or ply:Alive() then
	    ply:StripWeapon('weapon_zm_basebat')
	    ply:Give('weapon_zm_improvised')
     else
        ply:StripWeapon('weapon_zm_basebat')        
     end
end

What is the default weapon?
Edit: NVM I see.
You should change the or to an and.

weapon_zm_improvised is the default weapon and weapon_zm_basebat is the weapon you get when you buy this in the pointshop!

Modify to suit your needs



ITEM.Name = 'Sledgehammer'
ITEM.Price = 1500
ITEM.Model = 'models/weapons/w_sledgehammer.mdl'
ITEM.WeaponClass = 'weapon_zm_sledgehammer'

function ITEM:OnEquip(ply)
ply:StripWeapon('weapon_zm_improvised')
	if not ply:IsSpec() then
	ply:Give(self.WeaponClass)
	ply:SelectWeapon(self.WeaponClass)
end
end

function ITEM:OnHolster(ply)
	ply:StripWeapon(self.WeaponClass)
	if not ply:IsSpec() then
	ply:Give('weapon_zm_improvised')
	ply:SelectWeapon('weapon_zm_improvised')
end
end


Oh I see what you’ve done there Niandra, thanks!
Thanks to the both of you :slight_smile: