checking player specific weapon?

Does anyone know a function to check if a player has a specific weapon equipped??

Currently it only checks if the player has the weapon in their weapon menu.

Here is my code:


	if IsValid(trace.Entity) and trace.Entity:IsPlayer() and trace.Entity:HasWeapon() then 
		return
	end

If by equipped you mean holding it then
[lua]trace.Entity:GetActiveWeapon() == wep[/lua]

[editline]25th October 2013[/editline]

May I also ask what is the purpose of this? It seems like you’re attempting to stop the person who triggered this trace from being included in it.

Actually you would be better off checking Entity.GetClass of the return of Player.GetActiveWeapon against a string of the desired classname. But don’t forget to check whether IsValid is true for Player.GetActiveWeapon first!

Sorry for the little information, I just meant to give him the function.

The problem is that in your way you would need another “wep” entity to check it against. That’s a pretty inefficient thing to do, and you shouldn’t ever do that.

Something like this would be better.
[lua]
IsValid(t.Entity:GetActiveWeapon()) and t.Entity:GetActiveWeapon():GetClass() == “class_name”
[/lua]