So I am completely new to Lua but I want to learn how to make SWEP's. Someone said that a good idea would be to look at excisting SWEP's and look at their code.
So I did and I edited a little bit of the code just to see if it would work. It didn't.
My weapon ended up having 52 ammo, left clicking wont do anything and right clicking makes it shoot shotgun bursts.
Here's the code (sorry if there's a totally obvious error, as I said I am not good at Lua):
[code]
SWEP.Author ="Firestarter"
SWEP.Contact =""
SWEP.Purpose =""
SWEP.Instructions ="Left click spawns a zombie."
SWEP.Spawnable =false
SWEP.AdminSpawnable =true
SWEP.ViewModel ="models/weapons/v_annabelle.mdl"
SWEP.WorldModel ="models/weapons/v_annabelle.mdl"
SWEP.Primary.ClipSize =-1
SWEP.Primary.DefaultClip =-1
SWEP.Primary.Automatic =false
SWEP.Primary.Ammo ="none"
local ShootSound = Sound( "Metal.SawbladeStick" )
function SWEP:Reload()
end
function SWEP:Think()
end
function SWEP:PrimaryAttack()
local tr = self.Owner:GetEyeTrace()
if ( tr.HitWorld ) then return end
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetNormal( tr.HitNormal )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
util.Effect( "Sparks", effectdata )
self.Weapon:EmitSound( ShootSound )
self.BaseClass.ShootEffects( self )
if ( !SERVER ) then return end
local ent = ents.Create( "npc_zombie" )
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
undo.Create( "Zombie" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
[/code]
That's what's in the shared.lua file. If you need to see the other ones then please say so.
undo.Create( "Zombie" )
That should be npc_zombie
And why would you make it undo it just after you spawned it ? That doesnt make sense. I think if your not good at lua, you should edit the manhack gun :/
I did. That is taken straight from Garrys manhack gun. That's why I included it.
[editline]12:16PM[/editline]
Also it does not help to remove the undo bit.
[CODE]
// Variables that are used on both client and server
SWEP.Author = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = "Shoot a prop to attach a Manhack.\nRight click to attach a rollermine."
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_annabelle.mdl"
SWEP.WorldModel = "models/weapons/w_annabelle.mdl"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
local ShootSound = Sound( "Metal.SawbladeStick" )
/*---------------------------------------------------------
Reload does nothing
---------------------------------------------------------*/
function SWEP:Reload()
end
/*---------------------------------------------------------
Think does nothing
---------------------------------------------------------*/
function SWEP:Think()
end
/*---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
local tr = self.Owner:GetEyeTrace()
if ( tr.HitWorld ) then return end
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetNormal( tr.HitNormal )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
util.Effect( "Sparks", effectdata )
self:EmitSound( ShootSound )
self:ShootEffects( self )
// The rest is only done on the server
if (!SERVER) then return end
// Make a zombie
local ent = ents.Create( "npc_zombie" )
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
// Weld it to the object that we hit
local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 )
undo.Create("Zombie")
undo.AddEntity( weld )
undo.AddEntity( nocl )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
/*---------------------------------------------------------
SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
local tr = self.Owner:GetEyeTrace()
if ( tr.HitWorld ) then return end
self:EmitSound( ShootSound )
self:ShootEffects( self )
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos )
effectdata:SetNormal( tr.HitNormal )
effectdata:SetMagnitude( 8 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 16 )
util.Effect( "Sparks", effectdata )
// The rest is only done on the server
if (!SERVER) then return end
// Make a headcrab
local ent = ents.Create( "npc_headcrab" )
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -16 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
// Weld it to the object that we hit
local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 )
undo.Create("Headcrab")
undo.AddEntity( weld )
undo.AddEntity( nocl )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
/*---------------------------------------------------------
Name: ShouldDropOnDie
Desc: Should this weapon be dropped when its owner dies?
---------------------------------------------------------*/
function SWEP:ShouldDropOnDie()
return false
end
[/CODE]
Now learn yourself some lua :P I didnt test this, it should work.
I did use that for my SWEP. I just cut out some things like the weld bit.
Sorry, you need to Log In to post a reply to this thread.