Discord
Steam
/
General Discussion
/
Melee lua SWEP..
Login/Join
Event Log
Melee lua SWEP attack animation not always starting
0 replies, posted
Search
In This Thread
I'm creating a gamemode with custom weapons. But there's a problem with this melee weapon, the attack animation sometimes starts and sometimes doesn't. Here's the code. AddCSLuaFile() SWEP.Base = "weapon_base" SWEP.PrintName = "Hard Hitter" SWEP.Category = "Stalkers" SWEP.Author = "iKebab897" SWEP.Purpose = "Stalk and kill your preys" SWEP.Instructions = "LMB: Attack, RMB: Invisibility, RELOAD: Ability" SWEP.Spawnable = false SWEP.AdminOnly = false SWEP.Slot = 0 SWEP.SlotPos = 0 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true SWEP.UseHands = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 60 SWEP.BobScale = 4.65 SWEP.SwayScale = 1.8 SWEP.ViewModel = "models/weapons/v_stunstick.mdl" SWEP.WorldModel = "models/weapons/w_stunbaton.mdl" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Primary.Delay = 1.15 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Secondary.Delay = 1.5 sound.Add( { name = "antlionguard_growl_high", channel = CHAN_AUTO, volume = 1.0, level = 55, pitch = { 100, 110 }, sound = "npc/antlion_guard/growl_high.wav" } ) sound.Add( { name = "antlionguard_attack_double", channel = CHAN_VOICE, volume = 1.0, level = 55, pitch = { 100, 110 }, sound = "npc/antlion/attack_double1.wav" } ) local HitSound = Sound( "Weapon_Crowbar.Melee_Hit" ) local HitWorldSound = Sound( "Weapon_Crowbar.Melee_HitWorld" ) local MissSound = Sound( "Weapon_Crowbar.Single" ) function SWEP:Initialize() if self.Owner:IsValid() then self:SetHoldType( "melee" ) end end function SWEP:PrimaryAttack() if self.Owner:GetNWBool( "inv", false ) == false then self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if ( CLIENT ) then return end local tracedata = {} tracedata.start = self.Owner:GetShootPos() tracedata.endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 75 tracedata.filter = self.Owner tracedata.mins = Vector( -15 , -15 , -15 ) tracedata.maxs = Vector( 15 , 15 , 15 ) if ( self.Owner:IsPlayer() ) then self.Owner:LagCompensation( true ) end local tr = util.TraceHull( tracedata ) local vm = self.Owner:GetViewModel() local pitch = math.random( -40, 40 ) local yaw = math.random( -40, 40 ) local roll = math.random( -40, 40 ) if self.Owner:IsOnGround() then self.Owner:SetWalkSpeed( 1000 ) self.Owner:SetRunSpeed( 1200 ) timer.Simple( 0.01, function() self.Owner:SetWalkSpeed( 185 ) self.Owner:SetRunSpeed( 415 ) end ) end timer.Simple( 0.055, function() if tr.Hit then self:SendWeaponAnim( ACT_VM_HITCENTER ) self.Owner:SetAnimation( PLAYER_ATTACK1 ) if tr.Entity:IsPlayer() or tr.Entity:IsNPC() or tr.Entity:Health() > 0 then self.Owner:EmitSound( HitSound ) self.Owner:SetWalkSpeed( 15 ) self.Owner:SetRunSpeed( 15 ) tr.Entity:TakeDamage( tr.Entity:GetMaxHealth() / 7 + math.random( 20, 28 ), self.Owner, stalk ) net.Start( "SmallStun" ) net.Send( self.Owner ) else self.Owner:ViewPunch( Angle( pitch, yaw, roll ) ) self.Owner:EmitSound( HitWorldSound ) self:SetNextPrimaryFire( CurTime() + self.Primary.Delay + 0.55 ) self.Owner:SetWalkSpeed( 65 ) self.Owner:SetRunSpeed( 65 ) net.Start( "HardStun" ) net.Send( self.Owner ) self.Owner:SetVelocity( self.Owner:GetForward() * -750 + Vector( 0, 0, -300 ) ) end else self:SetNextPrimaryFire( CurTime() + self.Primary.Delay + 0.1 ) self:SendWeaponAnim( ACT_VM_MISSCENTER ) self.Owner:EmitSound( MissSound ) self.Owner:SetWalkSpeed( 45 ) self.Owner:SetRunSpeed( 45 ) net.Start( "MediumStun" ) net.Send( self.Owner ) end end ) if ( self.Owner:IsPlayer() ) then self.Owner:LagCompensation( false ) end end end function SWEP:SecondaryAttack() self:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) if ( CLIENT ) then return end net.Start( "ChangeInv" ) net.Send( self.Owner ) net.Start( "SecondarySound" ) net.Send( self.Owner ) end
Sorry, you need to
Log In
to post a reply to this thread.