• Making NPCs fire in bursts of two or three?
    8 replies, posted
What I have so far: [lua]function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end local bullet = {} -- Set up the shot bullet.Num = self.Primary.NumShots bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() if self.Owner:IsPlayer() then bullet.Spread = Vector( (self.Primary.Cone / 90)/4, (self.Primary.Cone / 90)/4, 0 ) else bullet.Spread = Vector( self.Primary.Cone / 90, self.Primary.Cone / 90, 0 ) end bullet.Tracer = self.Primary.Tracer bullet.Force = self.Primary.Force if self.Owner:IsPlayer() then bullet.Damage = self.Primary.Damage * 4 else bullet.Damage = self.Primary.Damage end bullet.AmmoType = self.Primary.Ammo self.Owner:FireBullets( bullet ) self.Owner:MuzzleFlash() self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self.Owner:SetAnimation( PLAYER_ATTACK1 ) self.Weapon:EmitSound(Sound(self.Primary.Sound)) if !self.Owner:IsNPC() then if (self.Primary.TakeAmmoPerBullet) then self:TakePrimaryAmmo(self.Primary.NumShots) else self:TakePrimaryAmmo(1) end end self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) end[/lua] How would I make NPCs fire in bursts of two or three? It would be under if !self.Owner:IsNPC. I just feel like experimenting with npc sweps. This is for an an94.
Increase bullet.Num?
[QUOTE=commander204;22192775]Increase bullet.Num?[/QUOTE] Isnt that under if the swep is held by a player? [editline]05:07PM[/editline] And also wont it make it like a shotgun?
here is my burst code that i use. I have cut out a lot of the usual stuff. This has it where i shoot 1 bullet 3 times with a slight delay. [lua] burst = 0//put it up at the top function SWEP:PrimaryAttack() burst = burst + 1 if (burst < 3) timer.Simple( .1, self.PrimaryAttack, self ) end if (burst >= 3) then burst = 0 end end [/lua]
[QUOTE=??????;22205586]here is my burst code that i use. I have cut out a lot of the usual stuff. This has it where i shoot 1 bullet 3 times with a slight delay. [lua] burst = 0//put it up at the top function SWEP:PrimaryAttack() burst = burst + 1 if (burst < 3) timer.Simple( .1, self.PrimaryAttack, self ) end if (burst >= 3) then burst = 0 end end [/lua][/QUOTE] it says that there is an unexpected symbol near timer.Simple. [editline]10:50AM[/editline] actually it says then expected near lua:112
[lua] burst = 0//put it up at the top function SWEP:PrimaryAttack() burst = burst + 1 if (burst < 3) then timer.Simple( .1, self.PrimaryAttack, self ) end if (burst >= 3) then burst = 0 end end [/lua] he just forgot a "then" in the first if
[QUOTE=Szgan;22210592][lua] burst = 0//put it up at the top function SWEP:PrimaryAttack() burst = burst + 1 if (burst < 3) then timer.Simple( .1, self.PrimaryAttack, self ) end if (burst >= 3) then burst = 0 end end [/lua] he just forgot a "then" in the first if[/QUOTE] Ok. Is there a way to make the space in between bursts longer? Changing the delay doesn't really do anything. And if I increase the .1, it'll make the bursts take longer to finish, but won't make it so that the time in between the bursts change.
[b][url=http://luabin.foszor.com/code/addons/counter-strike/lua/weapons/weapon_cs_base/shared.lua#59][img]http://luabin.foszor.com/static/img/favicon.ico[/img] Weapon.SetNPCMinBurst, Weapon.SetNPCMaxBurst[/url][/b] Undocumented functions, but might be what you want.
[QUOTE=Kogitsune;22214204][b][url=http://luabin.foszor.com/code/addons/counter-strike/lua/weapons/weapon_cs_base/shared.lua#59][img]http://luabin.foszor.com/static/img/favicon.ico[/img] Weapon.SetNPCMinBurst, Weapon.SetNPCMaxBurst[/url][/b] Undocumented functions, but might be what you want.[/QUOTE] It does make npcs fire in bursts of two, but no matter how I change the delay variable, the rate of fire (not the time inbetween bursts) is super slow. [lua] SWEP.Base = "weapon_base" -- Visual/sound settings if ( SERVER ) then AddCSLuaFile( "shared.lua" ) SWEP.HoldType = "ar2" end SWEP.PrintName = "AN94" SWEP.Category = "Flubadoo's NPC Sweps" SWEP.Slot = 2 SWEP.SlotPos = 4 SWEP.DrawAmmo = true SWEP.DrawCrosshair = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 64 SWEP.ViewModel = "models/weapons/v_an94.mdl" SWEP.WorldModel = "models/weapons/w_an94.mdl" SWEP.ReloadSound = "weapons/pistol/pistol_reload1.wav" //SWEP.HoldType = "ar2" -- Other settings SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.MuzzleEffect = "effect_muzzle_rifle" SWEP.MuzzleAttachment = "1" -- SWEP info SWEP.Author = "Flubadoo" SWEP.Contact = "" SWEP.Purpose = "Because I can!" SWEP.Instructions = "Aim away from face!" -- Primary fire settings SWEP.Primary.Sound = "weapons/an94/an94_fire.wav" SWEP.Primary.Damage = 11 SWEP.Primary.NumShots = 1 SWEP.Primary.Recoil = 0 SWEP.Primary.Cone = 5.7 SWEP.Primary.Delay = 0.08 SWEP.Primary.ClipSize = 30 SWEP.Primary.DefaultClip = 256 SWEP.Primary.Tracer = 1 SWEP.Primary.Force = 10 SWEP.Primary.TakeAmmoPerBullet = false SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "SMG1" burst = 0 -- Secondary fire settings SWEP.Secondary.Sound = "" SWEP.Secondary.Damage = 10 SWEP.Secondary.NumShots = 1 SWEP.Secondary.Recoil = 1 SWEP.Secondary.Cone = 2 SWEP.Secondary.Delay = 0.1 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = 0 SWEP.Secondary.Tracer = 1 SWEP.Secondary.Force = 5 SWEP.Secondary.TakeAmmoPerBullet = false SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "" -- Hooks function SWEP:Initialize() if ( SERVER ) then self:SetWeaponHoldType( self.HoldType ) self:SetNPCMinBurst( 2 ) self:SetNPCMaxBurst( 2 ) self:SetNPCFireRate( 1 ) end end function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end local bullet = {} -- Set up the shot bullet.Num = self.Primary.NumShots bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() if self.Owner:IsPlayer() then bullet.Spread = Vector( (self.Primary.Cone / 90)/4, (self.Primary.Cone / 90)/4, 0 ) else bullet.Spread = Vector( self.Primary.Cone / 90, self.Primary.Cone / 90, 0 ) end bullet.Tracer = self.Primary.Tracer bullet.Force = self.Primary.Force if self.Owner:IsPlayer() then bullet.Damage = self.Primary.Damage * 4 else bullet.Damage = self.Primary.Damage end bullet.AmmoType = self.Primary.Ammo self.Owner:FireBullets( bullet ) self.Owner:MuzzleFlash() self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self.Owner:SetAnimation( PLAYER_ATTACK1 ) self.Weapon:EmitSound(Sound(self.Primary.Sound)) //self.Owner:ViewPunch(Angle( -self.Primary.Recoil, 0.5, 0.5 )) if !self.Owner:IsNPC() then if (self.Primary.TakeAmmoPerBullet) then self:TakePrimaryAmmo(self.Primary.NumShots) else self:TakePrimaryAmmo(1) end self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) end function SWEP:SecondaryAttack() end function SWEP:Think() end function SWEP:Reload() self.Weapon:DefaultReload(ACT_VM_RELOAD) return true end[/lua] thats what I have so far. Any suggestions on how to change how quickly the bursts are finished? should I incorporate the burst code in one of the above posts?
Sorry, you need to Log In to post a reply to this thread.