• Making combine mortar fire 5 shots
    3 replies, posted
Hey, Im trying to mod the combine mortar so it fires 5 shots on 1 click. I have it firing the 6 shots, but I want to make a delay between them. Any ideas? [lua] function SWEP:PrimaryAttack() for i=1,6 do // Find where the player is aiming. local targetTrace = util.QuickTrace( self.Owner:GetShootPos(), self.Owner:GetAimVector() * 8192, self.Owner ) // If we hit the sky/walls/ceilings, don't bother. if ( targetTrace.HitSky ) then return end if ( math.deg( math.acos( targetTrace.HitNormal:Dot( Vector( 0, 0, 1 ) ) ) ) > self.MaxOffFlat ) then return end // Trace up to find the sky. local skyTrace = util.TraceLine( { start = targetTrace.HitPos, endpos = targetTrace.HitPos + Vector( 0, 0, 16383 ), filter = self.Owner, mask = MASK_NPCWORLDSTATIC } ) if ( !skyTrace.HitSky ) then return end // Prevents rare crash when mortar is below the target. if ( skyTrace.HitPos.z <= targetTrace.HitPos.z ) then return end // Effects. self:EmitSound( "Weapon_Mortar.Single" ) self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self.Owner:ViewPunch( Angle( -0.1, 0, 0 ) ) // Timing. self:SetLastFire() self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if ( !SERVER ) then return end // Create the mortar. local mortar = ents.Create( "func_tankmortar" ) mortar:SetPos( skyTrace.HitPos ) mortar:SetAngles( Angle( 90, 0, 0 ) ) mortar:SetKeyValue( "iMagnitude", self.Primary.Damage ) // Damage. mortar:SetKeyValue( "firedelay", "1" ) // Time before hitting. mortar:SetKeyValue( "warningtime", "1" ) // Time to play incoming sound before hitting. mortar:SetKeyValue( "incomingsound", "Weapon_Mortar.Incomming" ) // Incoming sound. mortar:Spawn() // Create the target. local target = ents.Create( "info_target" ) target:SetPos( targetTrace.HitPos ) target:SetName( tostring( target ) ) target:Spawn() mortar:DeleteOnRemove( target ) // Fire. mortar:Fire( "SetTargetEntity", target:GetName(), 0 ) mortar:Fire( "Activate", "", 0 ) mortar:Fire( "FireAtWill", "", 0 ) mortar:Fire( "Deactivate", "", 2 ) mortar:Fire( "kill", "", 2 ) end end [/lua] I would also like to make it fire around a 50 radius of the shot area. Im pretty new to making SWEPs so any help would be appreciated ;)
Ive tried creating a lua delay, but this just crashes source :/ Anyone?
You should be able to do something like: [lua] local function FireMortar() <SHOT CODE HERE> end local Delay = 1 local Reps = 5 timer.Create("MortarFireTimer", Delay, Reps, function() FireMortar() end) [/lua] Untested but that should be a simple way to delay the shots.
Works a treat - Thanks!
Sorry, you need to Log In to post a reply to this thread.