What's wrong with my code?

Trying to restrict GetMurderer team from having the perma nyangun on spawn if they have bought it. I have this in autorun/server


hook.Add("PlayerSpawn", "DropNyan", function(ply)
	if ply:IsValid() && ply:Team() != GetMurderer then
		ply:StripWeapon("weapon_nyangun")
	end
end)

if ply:IsValid() && ply:GetMurderer() then

Perhaps like that?

Yeah I tried that but then the game would load up all glitchy.

Possibly ply:GetMurderer( )

That’s exactly what I have posted.

[editline]16th January 2014[/editline]

Why do you even have nyan gun on your server with Murder?

No you didn’t.

Additionally, this would be better suited for the PlayerLoadout hook OP.

I have a script that strips it on RDM so it’s usable. My only problem as of now is restricting it from the murderer.

I actually tried similar code then what you posted, not the exact same so I’ll try it and post back the results. Thanks.

[editline]16th January 2014[/editline]

Wait so plyGetMurderer() or ply:GetMurderer() robo?

Oh, I missed a “:”, it’s ply:GetMurderer()

Hmm. Didn’t work.

Not sure why, code seems to be in order.

It is a better idea to prevent the murderer from getting the weapon then removing it on spawn. Show you give him the weapon.

That’s not possible because any player can buy it if they are not murderer team and it’s a permanent weapon, so you only buy it once. The player spawns with it no matter what team, I just need to restrict the GetMurderer team from being able to use it, what ever way that takes.

It is possible, just show me the code you use to give the weapon.

I have it restricting the murderer from buying it already, but if someone buys it as bystander then spawns as the murderer they get it. Also, the first thing I tried was ITEM:CanPlayerEquip but it didn’t work…


ITEM.Name = 'Nyan Gun'
ITEM.Price = 1000
ITEM.Model = 'models/weapons/w_smg1.mdl'
ITEM.WeaponClass = 'weapon_nyangun'
ITEM.SingleUse = false

ITEM.CanPlayerBuy = function(self, ply)
if ply:GetMurderer() then return false end
return true
end

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

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

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

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

GM:PlayerCanPickupWeapon( _p, _w ) is actually called when a player is :Give’n a weapon; where _p = Player and _w is the Weapon.

Robot is on-to something; restrict them from picking it up; hook.Add the PlayerCanPickupWeapon and return false.

Tried adding this to the pointshop file also, didn’t work.



ITEM.CanPlayerEquip = function(self, ply)
if ply:GetMurderer() then return false end
return true
end

That will leave the gun on the ground for others to pickup AFAIK.

The proper way is:


ITEM.Name = 'Nyan Gun'
ITEM.Price = 1000
ITEM.Model = 'models/weapons/w_smg1.mdl'
ITEM.WeaponClass = 'weapon_nyangun'
ITEM.SingleUse = false

function ITEM:CanPlayerBuy(ply)
    if ply:GetMurderer() then return false end
    return true
end

function ITEM:OnBuy(ply)
    if ply:GetMurderer() then return end
    ply:Give(self.WeaponClass)
end

function ITEM:OnEquip(ply)
    if ply:GetMurderer() then return end
    ply:Give(self.WeaponClass)
end

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

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

Yup that works. Thanks man, learning something new every day.