Permalink
Browse files

Improved Fists

* Fists are now fully predicted
* Fixed some fuckup with Overlay material paths
  • Loading branch information...
1 parent c26040e commit 37a1bab3108f8626207a9bbe4a819a739d33ee5f @robotboy655 robotboy655 committed Jan 30, 2014
Showing with 108 additions and 70 deletions.
  1. +7 −7 garrysmod/lua/postprocess/overlay.lua
  2. +101 −63 garrysmod/lua/weapons/weapon_fists.lua
@@ -53,11 +53,11 @@ list.Set( "OverlayMaterials", "#overlay_pp.tankglass", { Material = "models/pro
list.Set( "OverlayMaterials", "#overlay_pp.globe", { Material = "models/props_combine/tprings_globe", Icon = "models/props_combine/tprings_globe" } )
list.Set( "OverlayMaterials", "#overlay_pp.fisheye", { Material = "models/props_c17/fisheyelens", Icon = "models/props_c17/fisheyelens" } )
list.Set( "OverlayMaterials", "#overlay_pp.rendertarget", { Material = "models/overlay_rendertarget", Icon = "models/overlay_rendertarget" } )
-list.Set( "OverlayMaterials", "#overlay_pp.strider_pinch_dudv", { Material = "models/strider_pinch_dudv", Icon = "effects/strider_pinch_dudv" } )
-list.Set( "OverlayMaterials", "#overlay_pp.teleport", { Material = "effects/tp_eyefx/tpeye", Icon = "effects/tp_eyefx/tpeye" } )
-list.Set( "OverlayMaterials", "#overlay_pp.teleport2", { Material = "effects/tp_eyefx/tpeye2", Icon = "effects/tp_eyefx/tpeye2" } )
-list.Set( "OverlayMaterials", "#overlay_pp.teleport3", { Material = "effects/tp_eyefx/tpeye3", Icon = "effects/tp_eyefx/tpeye3" } )
-list.Set( "OverlayMaterials", "#overlay_pp.tvnoise", { Material = "effects/tvscreen_noise002a", Icon = "effects/tvscreen_noise002a" } )
+list.Set( "OverlayMaterials", "#overlay_pp.strider_pinch_dudv", { Material = "effects/strider_pinch_dudv", Icon = "effects/strider_pinch_dudv" } )
+list.Set( "OverlayMaterials", "#overlay_pp.teleport", { Material = "effects/tp_eyefx/tpeye", Icon = "effects/tp_eyefx/tpeye" } )
+list.Set( "OverlayMaterials", "#overlay_pp.teleport2", { Material = "effects/tp_eyefx/tpeye2", Icon = "effects/tp_eyefx/tpeye2" } )
+list.Set( "OverlayMaterials", "#overlay_pp.teleport3", { Material = "effects/tp_eyefx/tpeye3", Icon = "effects/tp_eyefx/tpeye3" } )
+list.Set( "OverlayMaterials", "#overlay_pp.tvnoise", { Material = "effects/tvscreen_noise002a", Icon = "effects/tvscreen_noise002a" } )
list.Set( "OverlayMaterials", "#overlay_pp.water_warp01", { Material = "effects/water_warp01", Icon = "effects/water_warp01" } )
if ( IsMounted( "tf" ) ) then
@@ -67,9 +67,9 @@ if ( IsMounted( "tf" ) ) then
list.Set( "OverlayMaterials", "#overlay_pp.water_warp", { Material = "effects/water_warp", Icon = "effects/water_warp" } )
list.Set( "OverlayMaterials", "#overlay_pp.water_warp_2fort", { Material = "effects/water_warp_2fort", Icon = "effects/water_warp_2fort" } )
list.Set( "OverlayMaterials", "#overlay_pp.water_warp_well", { Material = "effects/water_warp_well", Icon = "effects/water_warp_well" } )
- list.Set( "OverlayMaterials", "#overlay_pp.bleed_overlay", { Material = "effects/bleed_overlay", Icon = "effects/bleed_overlay" } )
+ list.Set( "OverlayMaterials", "#overlay_pp.bleed_overlay", { Material = "effects/bleed_overlay", Icon = "effects/bleed_overlay" } )
list.Set( "OverlayMaterials", "#overlay_pp.bombinomicon_distortion", { Material = "effects/bombinomicon_distortion", Icon = "effects/bombinomicon_distortion" } )
- list.Set( "OverlayMaterials", "#overlay_pp.dodge_overlay", { Material = "effects/dodge_overlay", Icon = "effects/dodge_overlay" } )
+ list.Set( "OverlayMaterials", "#overlay_pp.dodge_overlay", { Material = "effects/dodge_overlay", Icon = "effects/dodge_overlay" } )
list.Set( "OverlayMaterials", "#overlay_pp.distortion_normal", { Material = "effects/distortion_normal001", Icon = "effects/distortion_normal001" } )
end
@@ -3,7 +3,7 @@ AddCSLuaFile()
SWEP.PrintName = "Fists"
-SWEP.Author = "robotboy655 & MaxOfS2D, Tenrys"
+SWEP.Author = "Killburn, robotboy655, MaxOfS2D & Tenrys"
SWEP.Purpose = "Well we sure as hell didn't use guns! We would just wrestle Hunters to the ground with our bare hands! I used to kill ten, twenty a day, just using my fists."
SWEP.Spawnable = true
@@ -43,58 +43,40 @@ function SWEP:PreDrawViewModel( vm, wep, ply )
end
SWEP.HitDistance = 48
-function SWEP:PrimaryAttack( right )
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
+function SWEP:SetupDataTables()
+
+ self:NetworkVar( "Float", 0, "NextMeleeAttack" )
+ self:NetworkVar( "Float", 1, "NextIdle" )
+ self:NetworkVar( "Int", 2, "Combo" )
+
+end
- if ( !IsFirstTimePredicted() ) then return end
+function SWEP:UpdateNextIdle()
- -- We need this because attack sequences won't work otherwise in multiplayer
local vm = self.Owner:GetViewModel()
- vm:ResetSequence( vm:LookupSequence( "fists_idle_01" ) )
-
- local anim = "fists_left"
- if ( right ) then anim = "fists_right" end
- if ( math.random( 1, 10 ) == 1 ) then anim = "fists_uppercut" end
-
- timer.Simple( 0, function()
- if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
+ self:SetNextIdle( CurTime() + vm:SequenceDuration() )
- local vm = self.Owner:GetViewModel()
- vm:ResetSequence( vm:LookupSequence( anim ) )
+end
- self:Idle()
- end )
+function SWEP:PrimaryAttack( right )
- timer.Simple( 0.05, function()
- if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
- if ( anim == "fists_left" ) then
- self.Owner:ViewPunch( Angle( 0, 16, 0 ) )
- elseif ( anim == "fists_right" ) then
- self.Owner:ViewPunch( Angle( 0, -16, 0 ) )
- elseif ( anim == "fists_uppercut" ) then
- self.Owner:ViewPunch( Angle( 16, -8, 0 ) )
- end
- end )
+ self.Owner:SetAnimation( PLAYER_ATTACK1 )
- timer.Simple( 0.2, function()
- if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
- if ( anim == "fists_left" ) then
- self.Owner:ViewPunch( Angle( 4, -16, 0 ) )
- elseif ( anim == "fists_right" ) then
- self.Owner:ViewPunch( Angle( 4, 16, 0 ) )
- elseif ( anim == "fists_uppercut" ) then
- self.Owner:ViewPunch( Angle( -32, 0, 0 ) )
- end
- self.Owner:EmitSound( SwingSound )
-
- end )
+ local anim = "fists_left"
+ if ( right ) then anim = "fists_right" end
+ if ( self:GetCombo() >= 2 ) then
+ anim = "fists_uppercut"
+ end
+
+ local vm = self.Owner:GetViewModel()
+ vm:SendViewModelMatchingSequence( vm:LookupSequence( anim ) )
- timer.Simple( 0.2, function()
- if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self || CLIENT ) then return end
- self:DealDamage( anim )
- end )
+ self:EmitSound( SwingSound )
+ self:UpdateNextIdle()
+ self:SetNextMeleeAttack( CurTime() + 0.2 )
+
self:SetNextPrimaryFire( CurTime() + 0.9 )
self:SetNextSecondaryFire( CurTime() + 0.9 )
@@ -104,7 +86,12 @@ function SWEP:SecondaryAttack()
self:PrimaryAttack( true )
end
-function SWEP:DealDamage( anim )
+function SWEP:DealDamage()
+
+ local anim = self:GetSequenceName(self.Owner:GetViewModel():GetSequence())
+
+ self.Owner:LagCompensation( true )
+
local tr = util.TraceLine( {
start = self.Owner:GetShootPos(),
endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
@@ -121,11 +108,20 @@ function SWEP:DealDamage( anim )
} )
end
- if ( tr.Hit ) then self.Owner:EmitSound( HitSound ) end
+ if ( tr.Hit && SERVER ) then self.Owner:EmitSound( HitSound ) end
- if ( IsValid( tr.Entity ) && ( tr.Entity:IsNPC() || tr.Entity:IsPlayer() || tr.Entity:Health() > 0 ) ) then
+ local hit = false
+
+ if ( SERVER && IsValid( tr.Entity ) && ( tr.Entity:IsNPC() || tr.Entity:IsPlayer() || tr.Entity:Health() > 0 ) ) then
local dmginfo = DamageInfo()
+
+ local attacker = self.Owner
+ if ( !IsValid( attacker ) ) then attacker = self end
+ dmginfo:SetAttacker( attacker )
+
+ dmginfo:SetInflictor( self )
dmginfo:SetDamage( math.random( 8, 12 ) )
+
if ( anim == "fists_left" ) then
dmginfo:SetDamageForce( self.Owner:GetRight() * 49125 + self.Owner:GetForward() * 99984 ) -- Yes we need those specific numbers
elseif ( anim == "fists_right" ) then
@@ -134,49 +130,91 @@ function SWEP:DealDamage( anim )
dmginfo:SetDamageForce( self.Owner:GetUp() * 51589 + self.Owner:GetForward() * 100128 )
dmginfo:SetDamage( math.random( 12, 24 ) )
end
- dmginfo:SetInflictor( self )
- local attacker = self.Owner
- if ( !IsValid( attacker ) ) then attacker = self end
- dmginfo:SetAttacker( attacker )
tr.Entity:TakeDamageInfo( dmginfo )
+ hit = true
+
+ end
+
+ if ( SERVER && IsValid( tr.Entity ) ) then
+ local phys = tr.Entity:GetPhysicsObject()
+ if ( IsValid( phys ) ) then
+ phys:ApplyForceOffset( self.Owner:GetAimVector() * 80 * phys:GetMass(), tr.HitPos )
+ end
end
-end
-function SWEP:Idle()
+ if ( SERVER ) then
+ if ( hit && anim != "fists_uppercut" ) then
+ self:SetCombo( self:GetCombo() + 1 )
+ else
+ self:SetCombo( 0 )
+ end
+ end
- local vm = self.Owner:GetViewModel()
- timer.Create( "fists_idle" .. self:EntIndex(), vm:SequenceDuration(), 1, function()
- vm:ResetSequence( vm:LookupSequence( "fists_idle_0" .. math.random( 1, 2 ) ) )
- end )
+ self.Owner:LagCompensation( false )
end
function SWEP:OnRemove()
-
+
if ( IsValid( self.Owner ) ) then
local vm = self.Owner:GetViewModel()
if ( IsValid( vm ) ) then vm:SetMaterial( "" ) end
end
-
- timer.Stop( "fists_idle" .. self:EntIndex() )
-
+
end
function SWEP:Holster( wep )
self:OnRemove()
return true
+
end
function SWEP:Deploy()
local vm = self.Owner:GetViewModel()
- vm:ResetSequence( vm:LookupSequence( "fists_draw" ) )
+ vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_draw" ) )
+
+ self:UpdateNextIdle()
+
+ if ( SERVER ) then
+ self:SetCombo( 0 )
+ end
+
+ return true
+
+end
+
+function SWEP:Think()
+
+ local vm = self.Owner:GetViewModel()
+ local curtime = CurTime()
+ local idletime = self:GetNextIdle()
+
+ if ( idletime > 0 && CurTime() > idletime ) then
- self:Idle()
+ vm:SendViewModelMatchingSequence( vm:LookupSequence( "fists_idle_0" .. math.random( 1, 2 ) ) )
+
+ self:UpdateNextIdle()
- return true
+ end
+
+ local meleetime = self:GetNextMeleeAttack()
+
+ if ( meleetime > 0 && CurTime() > meleetime ) then
+ self:DealDamage()
+
+ self:SetNextMeleeAttack( 0 )
+
+ end
+
+ if ( SERVER && CurTime() > self:GetNextPrimaryFire() + 0.1 ) then
+
+ self:SetCombo( 0 )
+
+ end
+
end

0 comments on commit 37a1bab

Please sign in to comment.