Chat Weapon Drop

I have a SENT. It’s a knife. When you press E on it, it removes itself and gives you a knife. The name of the SWEP is “weapon_jack_knife” and the name of the SENT that gives it to you is “ent_jack_wep_knife”

I’m trying to get a code such that when you say “/dropweapon” and the knife is your current weapon, it strips the knife from you and creates the knife ENTSWEP at your feet.

It’s not even responding when I say “/weapondrop” and I don’t know why. No lua errors, nothing. Here is the code that is in the SENT’s init file. This is just the section that pertains to the chatdrop. Nothing else is relevant I don’t think.

[lua]
function ChatDrop(ply,text)

if (string.sub(text,1,11)=="/dropweapon") then

	if (ply:GetActiveWeapon()=="weapon_jack_knife") then

		ply:StripWeapon("weapon_jack_knife")

		local SpawnPos = ((ply:GetPos())+(Vector(0,0,math.Rand(5,55)))+(ply:GetAimVector()*math.Rand(5,25)))
		local SpawnVelocity = ply:GetVelocity()

		local ent = ents.Create("ent_jack_wep_knife")
		ent:SetPos(SpawnPos)
		ent:Spawn()
		ent:Activate()
		ent:GetPhysicsObject():SetVelocity(SpawnVelocity)
	end
return
end

end

hook.Add( “PlayerSay”, “KnifeChatDrop”, ChatDrop )
[/lua]

[lua]
function ChatDrop(ply,text)

if (string.sub(text,1,11)=="/dropweapon") then
local wep = ply:GetActiveWeapon()
	if wep && wep:IsValid() && wep:GetClass() == "weapon_jack_knife" then

		ply:StripWeapon("weapon_jack_knife")

		local SpawnPos = ((ply:GetPos())+(Vector(0,0,math.Rand(5,55)))+(ply:GetAimVector()*math.Rand(5,25)))
		local SpawnVelocity = ply:GetVelocity()

		local ent = ents.Create("ent_jack_wep_knife")
		ent:SetPos(SpawnPos)
		ent:Spawn()
		ent:Activate()
		ent:GetPhysicsObject():SetVelocity(SpawnVelocity)
	end
return
end

end

hook.Add( “PlayerSay”, “KnifeChatDrop”, ChatDrop )
[/lua]

Another instance of me failing to remember lessons I learned from E2.

Thanks.

[editline]08:57PM[/editline]

Alright, new problem.
I have 3 weapons that each have their own corresponding ENTSWEP.
Each of the three has its own ChatDrop function, and each ChatDrop function is activated ONLY if THAT particular weapon is the player’s current weapon.

Problem is, when I say “/dropweapon” with the knife in my hand, all three weapons drop. When I say dropweapon with the pistol in my hand, the pistol and the rifle drop, and when I say it with the rifle in my hand, just the rifle drops (which is how it’s supposed to work).

What’s going on? Why are the functions executing together?

Here’s the ChatDrop function in the rifle entity’s init file:
[lua]
function ChatDrop(ply,text)

if (string.sub(text,1,11)=="/dropweapon") then  
	local wep = ply:GetActiveWeapon()  
	if wep && wep:IsValid() && wep:GetClass() == "weapon_jack_g3" then  
  
		local SpawnPos = ((ply:GetPos())+(Vector(0,0,math.Rand(5,55)))+(ply:GetAimVector()*math.Rand(5,25)))  
		local SpawnVelocity = ply:GetVelocity()  
  
		local ent = ents.Create("ent_jack_wep_g3")  
			wep = ply:GetWeapon("weapon_jack_g3")
			ent:SetClip1(wep:Clip1())
		ent:SetPos(SpawnPos)  
		ent:Spawn()  
		ent:Activate()  
		ent:GetPhysicsObject():SetVelocity(SpawnVelocity)  
		
		ply:StripWeapon("weapon_jack_g3")
	end
end  

end

hook.Add( “PlayerSay”, “G3ChatDrop”, ChatDrop )
[/lua]

Here is the ChatDrop function in the pistol entity’s init file:
[lua]
function ChatDrop(ply,text)

if (string.sub(text,1,11)=="/dropweapon") then  
	local wep = ply:GetActiveWeapon()  
	if wep && wep:IsValid() && wep:GetClass() == "weapon_jack_m9" then  
    
		local SpawnPos = ((ply:GetPos())+(Vector(0,0,math.Rand(5,55)))+(ply:GetAimVector()*math.Rand(5,25)))  
		local SpawnVelocity = ply:GetVelocity()  
  
		local ent = ents.Create("ent_jack_wep_m9")  
			wep = ply:GetWeapon("weapon_jack_m9")
			ent:SetClip1(wep:Clip1())
		ent:SetPos(SpawnPos)  
		ent:Spawn()  
		ent:Activate()  
		ent:GetPhysicsObject():SetVelocity(SpawnVelocity)  
		
		ply:StripWeapon("weapon_jack_m9")
	end
end  

end

hook.Add( “PlayerSay”, “M9ChatDrop”, ChatDrop )
[/lua]

Here is the ChatDrop function in the knife entity’s init file:
[lua]
function ChatDrop(ply,text)

if (string.sub(text,1,11)=="/dropweapon") then  
	local wep = ply:GetActiveWeapon()  
    if wep && wep:IsValid() && wep:GetClass() == "weapon_jack_knife" then  
  
        local SpawnPos = ((ply:GetPos())+(Vector(0,0,math.Rand(5,55)))+(ply:GetAimVector()*math.Rand(5,25)))  
        local SpawnVelocity = ply:GetVelocity()  
  
        local ent = ents.Create("ent_jack_wep_knife")  
		ent:SetPos(SpawnPos)  
		ent:Spawn()  
        ent:Activate()  
        ent:GetPhysicsObject():SetVelocity(SpawnVelocity)  
		
		ply:StripWeapon("weapon_jack_knife")  
		
    end  
end  

end

hook.Add( “PlayerSay”, “KnifeChatDrop”, ChatDrop )
[/lua]

Also, where to I put “return” to keep the player’s chat from being seen?

Alright, he’s apparently gone. Can anyone else figure this out? Please?

you can also do…

[lua]
function ChatDrop(ply,text)
local Argument = string.Explode(" ", text)

if Argument[1] == "/dropweapon" then
	-- code here
end

end
hook.Add( “PlayerSay”, “KnifeChatDrop”, ChatDrop )
[/lua]