TTT - Improving Weapons ( Lua Help )


AddCSLuaFile()

SWEP.HoldType	= "ar2"

if CLIENT then
   SWEP.PrintName	= "M16"
   SWEP.Slot	= 2

   SWEP.Icon = "VGUI/ttt/icon_m16"
end

SWEP.Base	= "weapon_tttbase"
SWEP.Spawnable = true

SWEP.Kind = WEAPON_HEAVY
SWEP.WeaponID = AMMO_M16

SWEP.Primary.Delay	= 0.19
SWEP.Primary.Recoil	= 1.6
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "Pistol"
SWEP.Primary.Damage = 23
SWEP.Primary.Cone = 0.018
SWEP.Primary.ClipSize = 20
SWEP.Primary.ClipMax = 60
SWEP.Primary.DefaultClip = 20
SWEP.AutoSpawnable = true
SWEP.AmmoEnt = "item_ammo_pistol_ttt"

SWEP.UseHands	= true
SWEP.ViewModelFlip	= false
SWEP.ViewModelFOV	= 64
SWEP.ViewModel	= "models/weapons/cstrike/c_rif_m4a1.mdl"
SWEP.WorldModel	= "models/weapons/w_rif_m4a1.mdl"

SWEP.Primary.Sound = Sound( "Weapon_M4A1.Single" )

SWEP.IronSightsPos = Vector(-7.58, -9.2, 0.55)
SWEP.IronSightsAng = Vector(2.599, -1.3, -3.6)


function SWEP:SetZoom(state)
   if CLIENT then return end
   if not (IsValid(self.Owner) and self.Owner:IsPlayer()) then return end
   if state then
      self.Owner:SetFOV(35, 0.5)
   else
      self.Owner:SetFOV(0, 0.2)
   end
end

-- Add some zoom to ironsights for this gun
function SWEP:SecondaryAttack()
   if not self.IronSightsPos then return end
   if self:GetNextSecondaryFire() > CurTime() then return end

   bIronsights = not self:GetIronsights()

   self:SetIronsights( bIronsights )

   if SERVER then
      self:SetZoom( bIronsights )
   end

   self:SetNextSecondaryFire( CurTime() + 0.3 )
end

function SWEP:PreDrop()
   self:SetZoom(false)
   self:SetIronsights(false)
   return self.BaseClass.PreDrop(self)
end

function SWEP:Reload()
    if (self:Clip1() == self.Primary.ClipSize or
        self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0) then
       return
    end
    self:DefaultReload(ACT_VM_RELOAD)
    self:SetIronsights(false)
    self:SetZoom(false)
end

function SWEP:Holster()
   self:SetIronsights(false)
   self:SetZoom(false)
   return true
end

So - the above is pretty much the default code for the M16 for TTT.

I’m going to try to learn lua instead of hiring a bunch of people from coder hire to do stuff for me, so - I have ideas on improving on the guns slightly such as less recoil when aiming down sighs and various other things -

Would function SWEP:ShootBullet( damage, num_bullets, aimcone ) be useful for anything?

Also - is there a way to set reload time to be longer / slower?

Does swep weight effect guns in TTT? How fast does it change out?


SWEP.Primary.Delay	= 0.19
SWEP.Primary.Recoil	= 1.6

obvious enough.
For the reload speed look into SWEP.Reload (here)


function SWEP:Reload()
    if (self:Clip1() == self.Primary.ClipSize or
        self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0) then
       return
    end
    self:DefaultReload(ACT_VM_RELOAD)
    self:SetIronsights(false)
    self:SetZoom(false)
end

And yes swep weight does effect guns in TTT (I’m like 80% sure of this :P)

SWEP Weight traditionally affects weapon switch priority, so for example if you throw a grenade, the weapon you switch to thereafter is determined with Weight.

Swep deploy time is the new one - so for


function SWEP:ShootBullet( damage, num_bullets, aimcone )
	
	local bullet = {}

	bullet.Num 	= num_bullets
	bullet.Src 	= self.Owner:GetShootPos() -- Source
	bullet.Dir 	= self.Owner:GetAimVector() -- Dir of bullet
	bullet.Spread 	= Vector( aimcone, aimcone, 0 )	 -- Aim Cone
	bullet.Tracer	= 5 -- Show a tracer on every x bullets 
	bullet.Force	= 1 -- Amount of force to give to phys objects
	bullet.Damage	= damage
	bullet.AmmoType = "Pistol"
	
	self.Owner:FireBullets( bullet )
	
	self:ShootEffects()
	
end

So where it says ( damage, num_bullets, aimcone ) - what does that mean? Does it mean it is only pulling the values out of the brackets?

Also - how does aimcone work?

why are you changing ttt weps in the first place lol they are balanced and it will annoy people who are
used to countering the recoil etc

damage, num_bullets, aimcone are arguments damage is obv num_bullets is obvious dont worry about aimcone