When I tried to do a trace off my weapon I got this:
weapons/be_binocs/shared.lua:75: attempt to index global 'self' (a nil value)
[code]if SERVER then
AddCSLuaFile("shared.lua")
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.HoldType = "pistol"
SWEP.PlayOnce = false
end
if CLIENT then
surface.CreateFont("csd", ScreenScale(30), 500, true, true, "CSKillIcons")
surface.CreateFont("csd", ScreenScale(60), 500, true, true, "CSSelectIcons")
SWEP.DrawAmmo = true
SWEP.DrawCrosshair = false
SWEP.ViewModelFOV = 60
SWEP.ViewModelFlip = false
SWEP.CSMuzzleFlashes = true
SWEP.PrintName = "Brenodi Binoculars"
SWEP.IconLetter = "a"
SWEP.IconFont = "CSSelectIcons"
function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
draw.SimpleText( self.IconLetter, self.IconFont, x + wide/2, y + tall*0.2, Color( 15, 20, 200, 255 ), TEXT_ALIGN_CENTER )
end
end
SWEP.Author = "Empty"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.Base = "emp_scoped_base"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/imperial/weapons/v/pistol1/imp_pistol1.mdl"
SWEP.WorldModel = "models/imperial/weapons/w/pistol1/imp_pistol1.mdl"
SWEP.Primary.Sound = Sound("weapons/imp/scoutrifle/fire.wav")
SWEP.Primary.Reload1 = Sound("weapons/nf/pistol/clipout.wav")
SWEP.Primary.Reload2 = Sound("weapons/nf/pistol/clipin.wav")
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 0
SWEP.Primary.NumShots = 0
SWEP.Primary.ConeStatic = 0
SWEP.Primary.Cone = 0
SWEP.Primary.Delay = 0
SWEP.CrouchModifier = 0
SWEP.JumpModifier = 0
SWEP.SprintModifier = 0
SWEP.CurrentAccuracy = 0
SWEP.MoveModifier = 0
SWEP.Magnify = 8
SWEP.Move = 1
SWEP.Jump = 1
SWEP.Crouch = 1
SWEP.Sprint = 1
SWEP.ScopeMat = "imperial/weapons/v/binoculars/binocs_overlay"
SWEP.Primary.ClipSize = 5
SWEP.Primary.DefaultClip = 10
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
function SWEP.PrimaryAttack()
local tr = self.Owner:GetEyeTrace()
if ( tr.HitWorld ) then return end
local Pos1 = tr.HitPos
self.ion = ents.Create("ion_caller")
self.ion:SetVar("owner",self.Owner)
self.ion:SetPos(Pos1)
end[/code]
As you can see I've done nothing wrong, as far as I know, why am I getting this error?!
Is that code inside a SWEP function, eg SWEP:PrimaryAttack()?
Yes.
It's in primaryattack.
In fact, I really should post the whole script.
One moment.
EDIT: Added.
There's a few functions missing, they're in the swep base (I made my own, and it works.)
Make sure you did:
[lua]function SWEP:PrimaryAttack()[/lua]
not
[lua]function SWEP.PrimaryAttack()[/lua]
Thank you! I never would have found that.
Your'e welcome. :smile:
Still having issues :(
[code]if SERVER then
AddCSLuaFile("shared.lua")
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.HoldType = "pistol"
SWEP.PlayOnce = false
end
if CLIENT then
surface.CreateFont("csd", ScreenScale(30), 500, true, true, "CSKillIcons")
surface.CreateFont("csd", ScreenScale(60), 500, true, true, "CSSelectIcons")
SWEP.DrawAmmo = true
SWEP.DrawCrosshair = false
SWEP.ViewModelFOV = 60
SWEP.ViewModelFlip = false
SWEP.CSMuzzleFlashes = true
SWEP.PrintName = "Brenodi Binoculars"
SWEP.IconLetter = "a"
SWEP.IconFont = "CSSelectIcons"
function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
draw.SimpleText( self.IconLetter, self.IconFont, x + wide/2, y + tall*0.2, Color( 15, 20, 200, 255 ), TEXT_ALIGN_CENTER )
end
end
SWEP.Author = "Empty"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.Base = "emp_scoped_base"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/imperial/weapons/v/binocs/imp_binocs.mdl"
SWEP.WorldModel = "models/imperial/weapons/w/binoculars/imp_binoculars.mdl"
SWEP.Primary.Sound = Sound("weapons/imp/scoutrifle/fire.wav")
SWEP.Primary.Reload1 = Sound("weapons/nf/pistol/clipout.wav")
SWEP.Primary.Reload2 = Sound("weapons/nf/pistol/clipin.wav")
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 1
SWEP.Primary.NumShots = 1
SWEP.Primary.ConeStatic = 0
SWEP.Primary.Cone = 0
SWEP.Primary.Delay = 10
SWEP.CrouchModifier = 0
SWEP.JumpModifier = 0
SWEP.SprintModifier = 0
SWEP.CurrentAccuracy = 0
SWEP.MoveModifier = 0
SWEP.Magnify = 8
SWEP.Move = 1
SWEP.Jump = 1
SWEP.Crouch = 1
SWEP.Sprint = 1
SWEP.ScopeMat = "imperial/weapons/v/binoculars/binocs_overlay"
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 10
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "pistol"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self.Weapon:EmitSound(self.Primary.Sound,100,math.random(97,103))
self:TakePrimaryAmmo(1)
local tr = self.Owner:GetEyeTrace()
if ( tr.HitWorld ) then return end
local Hitpos = tr.HitPos
if SERVER then
self.ion = ents.Create("ion_caller")
self.ion:SetVar("owner",self.Owner)
self.ion:SetPos(Hitpos)
self.ion:Spawn()
self.ion:Activate()
end
end[/code]
"ion" doesn't spawn, whatever I do.
Can you spawn the ion entity with ent_create?
It doesn't matter now since I made a more efficient swep.
Sorry, you need to Log In to post a reply to this thread.