need help with tracing in SWEP

hi all,

A friend came with the idea: make a Crowbar for crowbar fights so you can earn points and buy stuff, but only if an other player has the crowbar too. I said ok, and started programming. I have to say that my programming skill isnt verry high and I don’t have that much experience with lua.
So, the first thing i did was remaking the crowbar. That wasn’t hard, but now the hard part: I want it to check if the player you hit has also the crowbarfight-crowbar, if so, it must do damage, else it may not do damage.
I’ve set up this trace in the SWEP:PrimaryAttack function:



local tr = {}
tr.start = self.Owner:GetShootPos()
tr.endpos = self.Owner:GetShootPos() + ( self.Owner:GetAimVector() * 75 )
tr.filter = self.Owner
tr.mask = MASK_SHOT
local trace = util.TraceLine( tr )

The problem is that this trace finds entities. although I can check if the entity is a player, but i cant say: trace.Player:function.
How can i properly find if the player entity traced is holding the weapon?

[lua]local tr = self.Owner():GetEyeTrace()
if tr.Entity:IsPlayer() and tr.Entity:GetActiveWeapon():GetClass() == “weapon crowbar” then
– Do stuff
end[/lua]

Use GetEyeTrace() to figure out what a player is looking at, and use trace.Entity to get the entity.

Ok, that works great, but it is like a gun. Its a melee weapons so I want it to have a maximum range of 75.

Something else:
when I add a Derma window to the SWEP:SecondairyAttack, it opens up 2 to 5 Derma windows instead of 1 :S

BUMP, it has been some time, still no answer…

To answer your first question: [lua]local tracedata = { };
tracedata.start = self.Owner:GetShootPos( );
tracedata.endpos = self.Owner:GetShootPos( ) + self.Owner:GetAimVector( ) * 75;
tracedata.filter = self.Owner;
local tr = util.TraceLine( tracedata );

if tr.Entity:IsPlayer() and tr.Entity:GetActiveWeapon():GetClass() == “weapon crowbar” then
– Do stuff
end[/lua]