I'm making a SWEP for personal use and i have some problems with the lua programming.
What kind of code do i use to make my weapon drop empty bullet cases just like smg1? Can i change the location of on-screen muzzle flash? Also, what code
defines either weapon reloads automatically after it runs out or not?
My weapon is also somehow a left hand version, something automatically switched it to left side and i don't know what. Checked all the code and i can't understand, what causes it :(
The muzzle flash is still in the right side - by the way. I want my weapon to be on the right side of a screen again :(
My lua is here, never mind about secondary fire. I generated this lua with some lua generator and changed values/names just to clear out.
[QUOTE]
//General Variables\\
SWEP.AdminSpawnable = true
SWEP.ViewModelFOV = 64
SWEP.ViewModel = "models/weapons/v_rif_g36c.mdl"
SWEP.WorldModel = "models/weapons/w_rif_g36c.mdl"
SWEP.AutoSwitchTo = true
SWEP.Slot = 0
SWEP.HoldType = "SMG"
SWEP.PrintName = "HK G36c Assault Rifle"
SWEP.Author = "heckler & koch"
SWEP.Spawnable = true
SWEP.AutoSwitchFrom = false
SWEP.FiresUnderwater = true
SWEP.Weight = 5
SWEP.DrawCrosshair = true
SWEP.Category = "heckler & koch"
SWEP.SlotPos = 1
SWEP.DrawAmmo = true
SWEP.ReloadSound = "weapons/m4/rel.wav"
SWEP.Instructions = "Point. Aim. Shoot."
SWEP.Contact = "heckler & koch"
SWEP.Purpose = "The right of the people to keep and bear arms, shall not be infringed!"
SWEP.base = "weapon_base"
//General Variables\\
//Primary Fire Variables\\
SWEP.Primary.Sound = "weapons/weapon_g36c/g36c-1.wav"
SWEP.Primary.Damage = 32
SWEP.Primary.TakeAmmo = 1
SWEP.Primary.ClipSize = 30
SWEP.Primary.Ammo = "smg1"
SWEP.Primary.DefaultClip = 8000
SWEP.Primary.Spread = 0.2
SWEP.Primary.NumberofShots = 1
SWEP.Primary.Automatic = true
SWEP.Primary.Recoil = 0.2
SWEP.Primary.Delay = 0.07
SWEP.Primary.Force = 10
//Primary Fire Variables\\
//Secondary Fire Variables\\
SWEP.Secondary.NumberofShots = 1
SWEP.Secondary.Force = 10
SWEP.Secondary.Spread = 0.1
SWEP.Secondary.Sound = "Weapon_Pistol.Single"
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Recoil = 1
SWEP.Secondary.Delay = 0.2
SWEP.Secondary.TakeAmmo = 1
SWEP.Secondary.ClipSize = 16
SWEP.Secondary.Damage = 10
//Secondary Fire Variables\\
//SWEP:Initialize()\\
function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
util.PrecacheSound(self.Secondary.Sound)
if ( SERVER ) then
self:SetWeaponHoldType( self.HoldType )
end
end
//SWEP:Initialize()\\
//SWEP:PrimaryFire()\\
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local bullet = {}
bullet.Num = self.Primary.NumberofShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
bullet.Tracer = 0
bullet.Force = self.Primary.Force
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
local rnda = self.Primary.Recoil * -1
local rndb = self.Primary.Recoil * math.random(-1, 1)
self:ShootEffects()
self.Owner:FireBullets( bullet )
self.Weapon:EmitSound(Sound(self.Primary.Sound))
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
end
//SWEP:PrimaryFire()\\
//SWEP:SecondaryFire()\\
function SWEP:SecondaryFire()
return false
end
//SWEP:SecondaryFire()\\[/QUOTE]
you can change the orientation of the swep by using SWEP.ViewModelFlip and equaling that to false, but if it's a CS:S model, they're made for left-handed people for some reason you would need to flip them.
The bullet ejection is... wait.
The only way you can learn lua is to just jump right in. That's how I had to do it. Just think logically, read a few guides, you'll soon get disgusted as there's no help on the internet.
The thing for the shell eject:
[CODE]
SWEP:ShootEffects()
local fx = EffectData() -- fx is gonna equal EffectData() for sake of saving time and space.
fx:SetEntity(self.Weapon)
fx:SetNormal(self.Owner:GetAimVector())
fx:SetAttachment(self.ShellEjectAttachment)
util.Effect(self.ShellEffect,fx) -- the effect
end
[/CODE]
here, self.ShellEjectAttachment basically means SWEP.ShellEjectAttachment.
So if you put a variable at the first of the code that starts with SWEP.<something> it needs to be referenced in either the game base or the code below. Since it's the plain old weapon_base, the vars you got all work, cause they're linked.
Muzzleflashes also work by putting an effectdata block under the shooteffects function, but those are a bit harder.
Sorry, you need to Log In to post a reply to this thread.