I stopped working on my weapon base a while ago for a few reasons. One of the reasons was the thought that I would need someone to reanimate player models to allow for proper sprinting and ironsight animations.
What I wanted to know is if there was a way to attack this issue through Lua. I want people to know when a player is aiming down sights and when a player is sprinting, as different perks and negative effects occur when a player doing either of those actions.
If you guys have any ideas on how to accomplish this, I would sincerely appreciate your help.
I know in some of spys weaponry (fas:2 sweps iirc) a transition between hip and ironsights was done by changing holdtype from shotgun to smg1 or ar2. I think there's a similar holdtype for weapons held down by your chest you can use for sprinting? I don't know anything about lua sadly so I'm unable to help you on that aspect :c
"passive" is the preferred sprinting holdtype in most bases, and "slam" or "normal" works for pistol sprinting.
You dont even have to use Lua animation api
I use this for running/against wall which is hooked into SWEP:Think( ):
[lua]
if ( self:IsRunning() or self:IsAgainstWall() ) then
-- If the player is running or against a wall, set the
-- hold type to the weapon's defined idle hold type
self:SetWeaponHoldType( self.IdleHoldType )
else
-- Otherwise, set the hold type to the defined default one
self:SetWeaponHoldType( self.HoldType )
end
[/lua]
SWEP:IsRunning( ) and SWEP:IsAgainstWall( ) are custom functions I use to check whether the player is running or is against a wall. The self.IdleHoldType is pretty much the same as self.HoldType but it's instead used as the passive hold type. For example, for rifles, I use "passive" as the idle hold type.
For ironsights, you could use the same sort of concept but use a different hold type. There's a few hold types you could use for this, I recommend trying a few of them out to see which ones you would like to use.
Here's the content of IsAgainstWall( )
[lua]//
// Helper-function to check if the player is against the wall using CONST dist, or input distance - Josh 'Acecool' Moser
//
function PLAYER:IsAgainstWall( _dist )
if ( self:TraceDistance( ) < ( _dist || PLAYER_AGAINST_WALL_DIST ) ) then
return true;
else
return false;
end
end[/lua]
TraceDistance is another helper which combines two of the most side-by-side used functions, traces and distance measures.
IsRunning is just: [lua]( self.Owner:KeyDown( IN_SPEED ) && self.Owner:GetVelocity():Length() > self.Owner:GetWalkSpeed() )[/lua]
[QUOTE=Acecool;44379697]Here's the content of IsAgainstWall( )
[lua]//
// Helper-function to check if the player is against the wall using CONST dist, or input distance - Josh 'Acecool' Moser
//
function PLAYER:IsAgainstWall( _dist )
if ( self:TraceDistance( ) < ( _dist || PLAYER_AGAINST_WALL_DIST ) ) then
return true;
else
return false;
end
end[/lua]
TraceDistance is another helper which combines two of the most side-by-side used functions, traces and distance measures.
IsRunning is just: [lua]( self.Owner:KeyDown( IN_SPEED ) && self.Owner:GetVelocity():Length() > self.Owner:GetWalkSpeed() )[/lua][/QUOTE]I use this for IsAgainstWall, probably not the best way but it works.
[lua]
--[[---------------------------------------------------------
IsAgainstWall
-----------------------------------------------------------]]
function SWEP:IsAgainstWall( )
local Trace = self.Owner:GetEyeTrace()
local Distance = Trace.HitPos:Distance( self.Owner:GetShootPos() )
if ( Trace.Hit and Distance < 30 ) then
return true
else
return false
end
end
[/lua]
And also to put your IsRunning into a function:
[lua]
--[[---------------------------------------------------------
IsRunning
-----------------------------------------------------------]]
function SWEP:IsRunning( )
return ( self.Owner:KeyDown( IN_SPEED ) and self.Owner:GetVelocity():Length() > self.Owner:GetWalkSpeed() )
end
[/lua]
[QUOTE=ShadowRanger;44379733]I use this for IsAgainstWall, probably not the best way but it works.
[lua]
--[[---------------------------------------------------------
IsAgainstWall
-----------------------------------------------------------]]
function SWEP:IsAgainstWall( )
local Trace = self.Owner:GetEyeTrace()
local Distance = Trace.HitPos:Distance( self.Owner:GetShootPos() )
if ( Trace.Hit and Distance < 30 ) then
return true
else
return false
end
end
[/lua][/QUOTE]
Old version, essentially the exact same thing except the new one splits it up more.
I can see how the holdtype thing would work, and I believe there is a way to make custom holdtypes for prettier looks and what not. Thanks guys, I'm going to do a grand recoding of my weapon base and make it suck less very soon. (Oh, and post more threads in here because that's what I'm good at.)
I don't feel like I say it as greatly as I wish I could, but I'm always thankful for the help and thankful for not being thrashed as being a noob or something.
Well, you've tackled render target scopes. That's more than I've ever done.
Sorry, you need to Log In to post a reply to this thread.