Permalink
Browse files

Updates to weapons

* Fixed prediction ( kinda ) for manhack welder
* Fixed a few bugs in Medkit
* Minor changes to Fists
  • Loading branch information...
1 parent a5ee95e commit 921b8d0c2c84da8584204d19b54b33788378bd4a @robotboy655 robotboy655 committed Jan 16, 2014
@@ -1,9 +1,6 @@
-- Variables that are used on both client and server
-SWEP.Author = ""
-SWEP.Contact = ""
-SWEP.Purpose = ""
SWEP.Instructions = "Shoot a prop to attach a Manhack.\nRight click to attach a rollermine."
SWEP.Spawnable = true
@@ -34,9 +31,6 @@ SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.UseHands = true
-
-
-
local ShootSound = Sound( "Metal.SawbladeStick" )
--[[---------------------------------------------------------
@@ -51,7 +45,6 @@ end
function SWEP:Think()
end
-
--[[---------------------------------------------------------
PrimaryAttack
-----------------------------------------------------------]]
@@ -60,28 +53,30 @@ function SWEP:PrimaryAttack()
local tr = self.Owner:GetEyeTrace()
--if ( tr.HitWorld ) then return end
- local effectdata = EffectData()
+ if ( IsFirstTimePredicted() ) then
+ local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetNormal( tr.HitNormal )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
- util.Effect( "Sparks", effectdata )
+ util.Effect( "Sparks", effectdata )
+ end
self:EmitSound( ShootSound )
self:ShootEffects( self )
-- The rest is only done on the server
- if ( !SERVER ) then return end
+ if ( CLIENT ) then return end
-- Make a manhack
local ent = ents.Create( "npc_manhack" )
- ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
- ent:SetAngles( tr.HitNormal:Angle() )
+ ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
+ ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
- local weld = nil;
+ local weld = nil
if ( tr.HitWorld ) then
@@ -115,22 +110,24 @@ function SWEP:SecondaryAttack()
self:EmitSound( ShootSound )
self:ShootEffects( self )
- local effectdata = EffectData()
+ if ( IsFirstTimePredicted() ) then
+ local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetNormal( tr.HitNormal )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
- util.Effect( "Sparks", effectdata )
+ util.Effect( "Sparks", effectdata )
+ end
-- The rest is only done on the server
- if (!SERVER) then return end
+ if ( CLIENT ) then return end
-- Make a manhack
local ent = ents.Create( "npc_rollermine" )
- ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
- ent:SetAngles( tr.HitNormal:Angle() )
+ ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
+ ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
local weld = nil;
@@ -1,15 +1,20 @@
AddCSLuaFile()
+SWEP.PrintName = "Fists"
+
SWEP.Author = "robotboy655 & MaxOfS2D"
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
SWEP.UseHands = true
+SWEP.DrawAmmo = false
SWEP.ViewModel = "models/weapons/c_arms_citizen.mdl"
SWEP.WorldModel = ""
SWEP.ViewModelFOV = 52
+SWEP.Slot = 0
+SWEP.SlotPos = 5
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
@@ -21,16 +26,6 @@ SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
-SWEP.Weight = 5
-SWEP.AutoSwitchTo = false
-SWEP.AutoSwitchFrom = false
-
-SWEP.PrintName = "Fists"
-SWEP.Slot = 0
-SWEP.SlotPos = 5
-SWEP.DrawAmmo = false
-SWEP.DrawCrosshair = true
-
local SwingSound = Sound( "weapons/slam/throw.wav" )
local HitSound = Sound( "Flesh.ImpactHard" )
@@ -49,9 +44,10 @@ end
SWEP.HitDistance = 48
SWEP.AttackAnims = { "fists_left", "fists_right", "fists_uppercut" }
function SWEP:PrimaryAttack()
+
self.Owner:SetAnimation( PLAYER_ATTACK1 )
- if ( !SERVER ) then return end
+ if ( !IsFirstTimePredicted() ) then return end
-- We need this because attack sequences won't work otherwise in multiplayer
local vm = self.Owner:GetViewModel()
@@ -93,7 +89,7 @@ function SWEP:PrimaryAttack()
end )
timer.Simple( 0.2, function()
- if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
+ if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self || CLIENT ) then return end
self:DealDamage( anim )
end )
@@ -173,10 +169,12 @@ function SWEP:Holster( wep )
end
function SWEP:Deploy()
+
local vm = self.Owner:GetViewModel()
vm:ResetSequence( vm:LookupSequence( "fists_draw" ) )
self:Idle()
return true
+
end
@@ -1,6 +1,7 @@
AddCSLuaFile()
+SWEP.PrintName = "Medkit"
SWEP.Author = "robotboy655 & MaxOfS2D"
SWEP.Purpose = "Heal people with your primary attack, or yourself with the secondary."
@@ -11,22 +12,21 @@ SWEP.ViewModel = "models/weapons/c_medkit.mdl"
SWEP.WorldModel = "models/weapons/w_medkit.mdl"
SWEP.ViewModelFOV = 54
+SWEP.Slot = 5
+SWEP.SlotPos = 3
SWEP.Primary.ClipSize = 100
SWEP.Primary.DefaultClip = 100
-SWEP.Primary.Automatic = true
+SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
-SWEP.PrintName = "Medkit"
-SWEP.Slot = 5
-SWEP.SlotPos = 3
-
-SWEP.HealAmount = 20
+SWEP.HealAmount = 20 -- Maximum heal amount per use
+SWEP.MaxAmmo = 100 -- Maxumum ammo
local HealSound = Sound( "items/smallmedkit1.wav" )
local DenySound = Sound( "items/medshotno1.wav" )
@@ -35,16 +35,18 @@ function SWEP:Initialize()
self:SetWeaponHoldType( "slam" )
- timer.Create( "medkit_ammo" .. self:EntIndex(), 0.5, 0, function()
+ if ( CLIENT ) then return end
+
+ timer.Create( "medkit_ammo" .. self:EntIndex(), 1, 0, function()
if ( !IsValid( self.Owner ) ) then return end
- if ( self:Clip1() < 100 ) then self:TakePrimaryAmmo( -1 ) end
+ if ( self:Clip1() < self.MaxAmmo ) then self:SetClip1( math.min( self:Clip1() + 2, self.MaxAmmo ) ) end
end )
end
function SWEP:PrimaryAttack()
- if ( !SERVER ) then return end
+ if ( CLIENT ) then return end
local tr = util.TraceLine( {
start = self.Owner:GetShootPos(),
@@ -53,21 +55,24 @@ function SWEP:PrimaryAttack()
} )
local ent = tr.Entity
+
+ local need = self.HealAmount
+ if ( IsValid( ent ) ) then need = math.min( ent:GetMaxHealth() - ent:Health(), self.HealAmount ) end
- if ( IsValid( ent ) && self:Clip1() >= self.HealAmount && ( ent:IsPlayer() || ent:IsNPC() ) && ent:Health() < ent:GetMaxHealth() ) then
+ if ( IsValid( ent ) && self:Clip1() >= need && ( ent:IsPlayer() || ent:IsNPC() ) && ent:Health() < 100 ) then
- self:TakePrimaryAmmo( self.HealAmount )
+ self:TakePrimaryAmmo( need )
- ent:SetHealth( math.min( ent:GetMaxHealth(), ent:Health() + self.HealAmount ) )
+ ent:SetHealth( math.min( ent:GetMaxHealth(), ent:Health() + need ) )
ent:EmitSound( HealSound )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:SetNextPrimaryFire( CurTime() + self:SequenceDuration() + 0.5 )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
- -- Even though the viewmodel has looping IDLE anim at all times, we need this ti make fire animation work in multiplayer
- timer.Simple( self:SequenceDuration(), function() if ( !IsValid( self ) ) then return end self:SendWeaponAnim( ACT_VM_IDLE ) end )
+ -- Even though the viewmodel has looping IDLE anim at all times, we need this to make fire animation work in multiplayer
+ timer.Create( "weapon_idle" .. self:EntIndex(), self:SequenceDuration(), 1, function() if ( IsValid( self ) ) then self:SendWeaponAnim( ACT_VM_IDLE ) end end )
else
@@ -80,23 +85,26 @@ end
function SWEP:SecondaryAttack()
- if ( !SERVER ) then return end
+ if ( CLIENT ) then return end
local ent = self.Owner
+
+ local need = self.HealAmount
+ if ( IsValid( ent ) ) then need = math.min( ent:GetMaxHealth() - ent:Health(), self.HealAmount ) end
- if ( IsValid( ent ) && self:Clip1() >= self.HealAmount && ent:Health() < ent:GetMaxHealth() ) then
+ if ( IsValid( ent ) && self:Clip1() >= need && ent:Health() < ent:GetMaxHealth() ) then
- self:TakePrimaryAmmo( self.HealAmount )
+ self:TakePrimaryAmmo( need )
- ent:SetHealth( math.min( ent:GetMaxHealth(), ent:Health() + self.HealAmount ) )
+ ent:SetHealth( math.min( ent:GetMaxHealth(), ent:Health() + need ) )
ent:EmitSound( HealSound )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
- self:SetNextSecondaryFire( CurTime() + self:SequenceDuration() + 1 )
+ self:SetNextSecondaryFire( CurTime() + self:SequenceDuration() + 0.5 )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
- timer.Simple( self:SequenceDuration(), function() if ( !IsValid( self ) ) then return end self:SendWeaponAnim( ACT_VM_IDLE ) end )
+ timer.Create( "weapon_idle" .. self:EntIndex(), self:SequenceDuration(), 1, function() if ( IsValid( self ) ) then self:SendWeaponAnim( ACT_VM_IDLE ) end end )
else
@@ -110,6 +118,15 @@ end
function SWEP:OnRemove()
timer.Stop( "medkit_ammo" .. self:EntIndex() )
+ timer.Stop( "weapon_idle" .. self:EntIndex() )
+
+end
+
+function SWEP:Holster()
+
+ timer.Stop( "weapon_idle" .. self:EntIndex() )
+
+ return true
end

0 comments on commit 921b8d0

Please sign in to comment.