• Can't index self, a nil value.
    6 replies, posted
Bleh on a stick, I can't seem to get this to work. [lua] AddCSLuaFile( "shared.lua" ) SWEP.HoldType = "Pistol" SWEP.Name = "Random Pointless Weapon" SWEP.Category = "Taco's Weapons" SWEP.Printname = "Random Pointless Weapon" SWEP.Instructions = "I'm not even sure..." SWEP.Purpose = "None" SWEP.Contact = "I love you!" SWEP.Author = "TacoNinja1995" SWEP.Slot = 0 SWEP.SlotPos = 0 SWEP.DrawAmmo = False SWEP.DrawCrosshair = False SWEP.IconLetter = "y" SWEP.ViewModelFlip = False SWEP.Base = "weapon_cs_base" SWEP.Spawnable = false SWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_pistol.mdl" SWEP.WorldModel = "models/weapons/w_pistol.mdl" SWEP.PrimaryAutomatic = true SWEP.SecondaryAutomatic = false SWEP.Weight = 5 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = false function SWEP:Initialize() end function SWEP.PrimaryAttack() end function SWEP.SecondaryAttack() self.Owner:ViewPunch( Angle( 0, 0, 0 ) ) self.Weapon:SetNextPrimaryFire( CurTime() + 0.15 ) local trace = self.Owner:GetEyeTrace() local effectdata = EffectData() effectdata:SetOrigin( trace.HitPos ) effectdata:SetNormal( trace.HitNormal ) effectdata:SetEntity( trace.Entity ) effectdata:SetAttachment( trace.PhysicsBone ) util.Effect( "super_explosion", effectdata ) local effectdata = EffectData() effectdata:SetOrigin( trace.HitPos ) effectdata:SetStart( self.Owner:GetShootPos() ) effectdata:SetAttachment( 1 ) effectdata:SetEntity( self.Weapon ) util.Effect( "ToolTracer", effectdata ) if (SERVER) then local owner=self.Owner if self.Owner.SENT then owner=self.Owner.SENT.Entity end local explosion = ents.Create( "env_explosion" ) explosion:SetPos(trace.HitPos) explosion:SetKeyValue( "iMagnitude" , "170" ) explosion:SetPhysicsAttacker(owner) explosion:SetOwner(owner) explosion:Spawn() explosion:Fire("explode","",0) explosion:Fire("kill","",0 ) end end [/lua] ...but I get THIS: [code] lua\weapons\funswep\shared.lua:40: attempt to index global 'self' (a nil value)[/code] Any help?
Next time, put it in lua tags please.
[QUOTE=grea$emonkey;23116868]Next time, put it in lua tags please.[/QUOTE] Sorry, derp move on my part.
And assuming line #40 is self.Owner:ViewPunch( Angle( 0, 0, 0 ) ), I'm not sure. That line looks fine.
That's why I'm so baffled by it.
Line 38. [code]function SWEP.SecondaryAttack()[/code] You used a period, not a colon, indicating it was just a function variable inside the SWEP, rather than an object-oriented function on the swep. Should be [code]function SWEP:SecondaryAttack() [/code]
[QUOTE=Entoros;23117043]Line 38. [code]function SWEP.SecondaryAttack()[/code] You used a period, not a colon, indicating it was just a function variable inside the SWEP, rather than an object-oriented function on the swep. Should be [code]function SWEP:SecondaryAttack() [/code][/QUOTE] I can't believe I missed that. It's late. :xd:
Sorry, you need to Log In to post a reply to this thread.