BloxGaming Forums

Our Servers => BloxGaming SB3 => Topic started by: Keeves on February 28, 2015, 08:11:16 pm

Title: [Code] New pew pew script
Post by: Keeves on February 28, 2015, 08:11:16 pm

Code: [Select]

local BULLET = {}


-- Important Information
BULLET.Version = 2


-- General Information
BULLET.Name = "Gau-954 Coil Gun"

BULLET.Author = "Keeves"
BULLET.Description = "Fast rate of fire and high accuracy, however, it suffers from high recoil and is encouraged to be used on capital ships"
BULLET.AdminOnly = false
BULLET.SuperAdminOnly = false


-- Appearance
BULLET.Model = "models/combatmodels/tankshell_25mm.mdl"


-- Effects / Sounds
BULLET.FireSound = {"chippy/m134d.wav"}
BULLET.ExplosionSound = nil
BULLET.FireEffect = "muzzleflash"


-- Movement
BULLET.Speed = 900
--BULLET.Gravity = 0.0
BULLET.RecoilForce = 1560
BULLET.Spread = 0.0
BULLET.AffectedBySBGravity = true


-- Damage
BULLET.DamageType = "PointDamage"
BULLET.Damage = 210




-- Reloading/Ammo
BULLET.Reloadtime = 0.02
BULLET.Ammo = 2000
BULLET.AmmoReloadtime = 20


-- Other
BULLET.EnergyPerShot = 80


-- Wire Input (This is called whenever a wire input is changed) (Is run on: Cannon)
function BULLET:WireInput( name, value )
   if (name == "Fire") then
      if (value != 0) then
         self.Firing = true
      else
         self.Firing = false
      end
      if (value != 0 and self.CanFire == true) then
         self.LastFired = CurTime()
         self.CanFire = false
         if WireLib then WireLib.TriggerOutput(self.Entity, "Can Fire", 0) end
      end
   elseif (name == "Reload") then
      if (self.Ammo and self.Ammo > 0 and self.Ammo < self.Bullet.Ammo) then
         if (self.Bullet.Ammo and self.Bullet.Ammo > 0 and self.Bullet.AmmoReloadtime and self.Bullet.AmmoReloadtime > 0) then
            if (value != 0) then
               if (self.Ammo and self.Ammo > 0) then
                  self.Ammo = 0
                  self.LastFired = CurTime() + self.Bullet.Reloadtime
                  self.CanFire = false
                  if WireLib then
                     WireLib.TriggerOutput( self.Entity, "Can Fire", 0)
                     WireLib.TriggerOutput( self.Entity, "Ammo", 0 )
                  end
               end
            end
         end
      end
   end
end


-- Cannon Think (Is run on: Cannon)
function BULLET:CannonThink()
   if (!self.ChargeSound) then self.ChargeSound = CreateSound( self.Entity, "ambient/machines/spin_loop.wav" ) end
   if (!self.ChargeUpTime) then self.ChargeUpTime = 0 end
   if (CurTime() - self.LastFired > self.Bullet.Reloadtime and self.CanFire == false) then -- if you can fire
      if (self.Ammo <= 0 and self.Bullet.Ammo > 0) then -- check for ammo
         -- if we don't have any ammo left...
         if (self.Firing) then -- if you are holding down fire
            -- Sound
            if (self.Bullet.EmptyMagSound and self.SoundTimer and CurTime() > self.SoundTimer) then
               self.SoundTimer = CurTime() + self.Bullet.Reloadtime
               local soundpath = ""
               if (table.Count(self.Bullet.EmptyMagSound) > 1) then
                  soundpath = table.Random(self.Bullet.EmptyMagSound)
               else
                  soundpath = self.Bullet.EmptyMagSound[1]
               end
               self:EmitSound( soundpath )
            end         
         end
         self.CanFire = false
         if WireLib then WireLib.TriggerOutput( self.Entity, "Can Fire", 0) end
         if (CurTime() - self.LastFired > self.Bullet.AmmoReloadtime) then -- check ammo reloadtime
            self.Ammo = self.Bullet.Ammo
            if WireLib then WireLib.TriggerOutput( self.Entity, "Ammo", self.Ammo ) end
            self.CanFire = true
            if (self.Firing) then
               self.LastFired = CurTime()
               self.CanFire = false
            elseif WireLib then
               WireLib.TriggerOutput( self.Entity, "Can Fire", 1)
            end
         end
      else
         -- if we DO have ammo left
         self.CanFire = true
         if (self.Firing) then
            self.LastFired = CurTime()
            self.CanFire = false
            if (self.ChargeUpTime >= 0) then
               self:FireBullet()
            else
               self.ChargeUpTime = self.ChargeUpTime + 5
            end
            if (!self.ChargeSound:IsPlaying()) then
               self.ChargeSound:Play()
            end
            self.ChargeSound:ChangePitch(math.max(self.ChargeUpTime,1),0)
         elseif WireLib then
            WireLib.TriggerOutput( self.Entity, "Can Fire", 1 )
         end
      end
   end
   if (!self.Firing or self.Ammo == 0) then
      if (self.ChargeUpTime > 0) then
         self.ChargeUpTime = self.ChargeUpTime - 2
         self.ChargeSound:ChangePitch(math.max(self.ChargeUpTime,1),0)
      else
         self.ChargeSound:Stop()
      end
   end
   if (self.Bullet.Reloadtime and self.Bullet.Reloadtime < 0.5) then
      -- Run more often!
      self.Entity:NextThink( CurTime() )
      return true
   end
end


function BULLET:OnRemove()
   if (self.ChargeSound:IsPlaying()) then self.ChargeSound:Stop() end
end

pewpew:AddWeapon( BULLET )
Title: Re: [Code] New pew pew script
Post by: bloxgate on March 01, 2015, 03:07:10 am
Looks nice, I'd suggest a couple of changes though:
On another note, that name seems familiar. Did you name it after something?