lua:4: attempt to index global 'SWEP' (a nil value) 1. unknown
18 replies, posted
So im making my first sweep to test it out and i used a template from garrys mod .org with some custom models. but when i load it in gmod i get this error:
[ERROR] lua/howl.lua:4: attempt to index global 'SWEP' (a nil value)
1. unknown - lua/howl.lua:4
ive looked around the internet but find it hard to find a answer please help
[CODE]-- Swep Creator - theRumblers100
//General Settings \\
SWEP.AdminSpawnable = true // Is the swep spawnable for admin
SWEP.ViewModelFOV = 64 // How much of the weapon do u see ?
SWEP.ViewModel = "models/weapons/v_tom_m4a1.mdl" // The viewModel, the model you se when you are holding it-.-
SWEP.WorldModel = "models/weapons/w_tom_m4a1.mdl" // The worlmodel, The model yu when it's down on the ground
SWEP.AutoSwitchTo = true // when someone walks over the swep, chould i automatectly change to your swep ?
SWEP.Slot = 3 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
SWEP.HoldType = "ar2" // How the swep is hold Pistol smg greanade melee
SWEP.PrintName = "CSGO: M4A1 Howl" // your sweps name
SWEP.Author = "✯theRumblers100✯" // Your name
SWEP.Spawnable = true // Can everybody spawn this swep ? - If you want only admin keep this false and adminsapwnable true.
SWEP.AutoSwitchFrom = false // Does the weapon get changed by other sweps if you pick them up ?
SWEP.FiresUnderwater = false // Does your swep fire under water ?
SWEP.Weight = 5 // Chose the weight of the Swep
SWEP.DrawCrosshair = true // Do you want it to have a crosshair ?
SWEP.Category = "theRumblers100's CSGO Weapons" // Make your own catogory for the swep
SWEP.SlotPos = 4 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
SWEP.DrawAmmo = true // Does the ammo show up when you are using it ? True / False
SWEP.ReloadSound = "m4a1_clipout.wav,m4a1_clipin.wav" // Reload sound, you can use the default ones, or you can use your one; Example; "sound/myswepreload.waw"
SWEP.Instructions = "Press primary fire button to fire :D" // How do pepole use your swep ?
SWEP.Contact = "YourMailAdress" // How Pepole chould contact you if they find bugs, errors, etc
SWEP.Purpose = "M4A1 with the Howl skin" // What is the purpose with this swep ?
SWEP.base = "weapon_base"
//General settings\\
//PrimaryFire Settings\\
SWEP.Primary.Sound = "m4a1_unsil-1.wav" // The sound that plays when you shoot :]
SWEP.Primary.Damage = 20 // How much damage the swep is doing
SWEP.Primary.TakeAmmo = 1 // How much ammo does it take for each shot ?
SWEP.Primary.ClipSize = 20 // The clipsize
SWEP.Primary.Ammo = "smg1" // ammmo type pistol/ smg1
SWEP.Primary.DefaultClip = 60 // How much ammo does the swep come with `?
SWEP.Primary.Spread = 0.5 // Does the bullets spread all over, if you want it fire exactly where you are aiming leave it o.1
SWEP.Primary.NumberofShots = 1 // How many bullets you are firing each shot.
SWEP.Primary.Automatic = true // Is the swep automatic ?
SWEP.Primary.Recoil = 1 // How much we should punch the view
SWEP.Primary.Delay = 0.25 // How long time before you can fire again
SWEP.Primary.Force = 10 // The force of the shot
//PrimaryFire settings\\
//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:Throw_Attack(Model, Sound, Angle)\\
function SWEP:Throw_Attack (Model, Sound, Angle)
local tr = self.Owner:GetEyeTrace()
self.Weapon:EmitSound (Sound)
self.BaseClass.ShootEffects (self)
if (!SERVER) then return end
local ent = ents.Create ("prop_physics")
ent:SetModel (Model)
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
ent:SetAngles (self.Owner:EyeAngles())
ent:Spawn()
local phys = ent:GetPhysicsObject()
local shot_length = tr.HitPos:Length()
phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 7))
phys:AddAngleVelocity(Angle)
cleanup.Add (self.Owner, "props", ent)
undo.Create ("Thrown model")
undo.AddEntity (ent)
undo.SetPlayer (self.Owner)
undo.Finish()
end
//Throw_Attack(Model, Sound, Angle)\\
[/CODE]
The file must be lua/[b]weapons/[/b]howl.lua
the script is not being recognized as a weapon script, due to its position.
try placing "howl.lua" inside the "/weapons" folder of the Lua folder you put it in.
edit: basically do what Robotboy said just before me.
were is that at?
[editline]27th October 2015[/editline]
[QUOTE=cynaraos;48993071]the script is not being recognized as a weapon script, due to its position.
try placing "howl.lua" inside the "/weapons" folder of the Lua folder you put it in.
edit: basically do what Robotboy said just before me.[/QUOTE]
okay
"lua/howl.lua"?
it needs to be "lua/[b]weapons[/b]/howl.lua"
[QUOTE=cynaraos;48993071]the script is not being recognized as a weapon script, due to its position.
try placing "howl.lua" inside the "/weapons" folder of the Lua folder you put it in.
edit: basically do what Robotboy said just before me.[/QUOTE]
i now get this: Couldn't include file 'howl.lua' (File not found) (<nowhere>)
at the top of the file put this: AddCSLuaFile()
[QUOTE=MasterPatch;48993081]i now get this: Couldn't include file 'howl.lua' (File not found) (<nowhere>)[/QUOTE]
there are no inclusion calls in your script, did you include every single part of your script in your original post?
[QUOTE=cynaraos;48993085]there are no inclusion calls in your script, did you include every single part of your script in your original post?[/QUOTE]
yes i did, its the entire file
[editline]27th October 2015[/editline]
[QUOTE=MaximLaHaxim;48993084]at the top of the file put this: AddCSLuaFile()[/QUOTE]
still same error
[editline]27th October 2015[/editline]
okay so i tried: lua_openscript_cl weapons\howl.lua
and got the exact same error
have you tried restarting the game completely?
as far as I know, weapon scripts shouldn't be executed with any "lua_openscript" console commands.
you should be able to see your weapon in its designated weapon category, in the weapon spawnmenu.
[QUOTE=cynaraos;48993124]have you tried restarting the game completely?
as far as I know, weapon scripts shouldn't be executed with any "lua_openscript" console commands.
you should be able to see your weapon in its designated weapon category, in the weapon spawnmenu.[/QUOTE]
ill give that a try,
[editline]27th October 2015[/editline]
Okay. i found it, im getting texture errors (i can fix that) but it has alt ammo?
[QUOTE=MasterPatch;48993127]
[..] but it has alt ammo?[/QUOTE]
try putting the following lines in your script:
[lua]
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Ammo = "none"
[/lua]
add in "SWEP.Secondary.Automatic = true" if it is necessary.
[QUOTE=cynaraos;48993186]try putting the following lines in your script:
[lua]
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Ammo = "none"
[/lua]
add in "SWEP.Secondary.Automatic = true" if it is necessary.[/QUOTE]
that worked but there is a empty ammo gun sound
[QUOTE=MasterPatch;48993209]that worked but there is a empty ammo gun sound[/QUOTE]
defining function SWEP:SecondaryAttack() without any content should help you with this issue.
[QUOTE=cynaraos;48993228]defining function SWEP:SecondaryAttack() without any content should help you with this issue.[/QUOTE]
well im not sure it worked. i fixed the texture issue (i hexed wrong), then moved the entire folder into the addons folder and now its not in the spawn menu
[QUOTE=MasterPatch;48993280][..] then moved the entire folder into the addons folder and now its not in the spawn menu[/QUOTE]
how did you move the folder?
is the file structure anything like "garrysmod/addons/[addon_name]/lua/howl.lua"?
[QUOTE=cynaraos;48993288]how did you move the folder?
is the file structure anything like "garrysmod/addons/[addon_name]/lua/howl.lua"?[/QUOTE]
its exactly that but i have sounds, models and textures too
[QUOTE=MasterPatch;48993304]its exactly that but i have sounds, models and textures too[/QUOTE]
there's not more I can help you with, then.
[QUOTE=cynaraos;48993318]there's not more I can help you with, then.[/QUOTE]
okay. i dont know why it doesnt show :/
[editline]27th October 2015[/editline]
[QUOTE=cynaraos;48993318]there's not more I can help you with, then.[/QUOTE]
is it suppose to be a gma file?
Sorry, you need to Log In to post a reply to this thread.