• SWEP Master Sword Error
    7 replies, posted
I'm having an issue with a custom SWEP that I have added to pointshop. For some reason I get an error that states: [B][ERROR] gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua:206: attempt to index local 'self' (a nil value) 1. SecondaryAttackDelay - gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua:206 2. unknown - gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua:201. [/B] I understand that it has some issue with the timer but not sure what to do. Please help! Here is the SWEP file: [code] if (SERVER) then AddCSLuaFile("shared.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end if (CLIENT) then SWEP.PrintName = "Master Sword" SWEP.DrawAmmo = false SWEP.DrawCrosshair = true SWEP.ViewModelFOV = 70 SWEP.ViewModelFlip = false SWEP.CSMuzzleFlashes = false end SWEP.Author = "jA_cOp, spin attack mods by SpazeGlitch" SWEP.Contact = "" SWEP.Purpose = "Slaughter your enemies, Link-style." SWEP.Instructions = "Primary Fire: Regular Attack\nSecondary Fire: Jump Attack\nReload: Spin Attack\nUse+Secondary Fire: Switch Spin Attacks" SWEP.Base = "weapon_tttbase" SWEP.Kind = WEAPON_EQUIP SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_masters.mdl" SWEP.WorldModel = "models/weapons/w_masters.mdl" util.PrecacheModel(SWEP.ViewModel) util.PrecacheModel(SWEP.WorldModel) 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" SWEP.ReloadRate = 1 SWEP.JumpRefire = false SWEP.OldSpin = 0 /*--------------------------------------------------------- Initialize ---------------------------------------------------------*/ function SWEP:Initialize() end /*--------------------------------------------------------- Think (Jump attack stuff) ---------------------------------------------------------*/ function SWEP:JumpReset() self.JumpRefire = true end function SWEP:Think() //Jump think if self.InAirDmg == 1 then local trace = {} trace.start = self.Owner:GetPos() trace.endpos = self.Owner:GetPos() + (self.Owner:GetUp() * -10) trace.filter = self.Owner local tr2 = util.TraceLine(trace) self.Owner:SetHealth(self.PrevHP) if tr2.Hit then self.InAirDmg = 0 self.JumpRefire = false self.Weapon:SetNextSecondaryFire(CurTime() + 0.8) self.Weapon:SetNextPrimaryFire(CurTime() + 0.3) if SERVER then self.Owner:EmitSound(Sound("player/pl_pain5.wav")) end else local ang = self.Owner:GetAimVector() local spos = self.Owner:GetShootPos() local trace = {} trace.start = spos trace.endpos = spos + (ang * 150) trace.filter = self.Owner local tr = util.TraceLine(trace) if tr.HitNonWorld and self.JumpRefire == true then self.JumpRefire = false local bullet = {} bullet.Num=5 bullet.Src = self.Owner:GetShootPos() bullet.Dir= self.Owner:GetAimVector() bullet.Spread = Vector(0.1,0.1,0.1) bullet.Tracer = 0 bullet.Force = 500 bullet.Damage = 5 self.Owner:FireBullets(bullet) self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER) timer.Simple(0.5,self.JumpReset,self) if SERVER then self.Owner:EmitSound(Sound("npc/vort/claw_swing"..tostring(math.random(1,2))..".wav")) end if SERVER then self.Owner:EmitSound(Sound("Zsword/oot-AdultLink_Sword"..tostring(math.random(1,3))..".wav")) end end end end //Spinning think if self.Spinning == 1 then if self.OldSpin == 0 then self.Owner:SetEyeAngles(Angle(0,self.Owner:EyeAngles().y + 11,0)) util.BlastDamage(self.Weapon, self.Owner, self.Owner:GetPos(), 200, 10) end if self.OldSpin == 1 then self.Owner:SetEyeAngles(Angle(0,self.Owner:EyeAngles().y + 20,0)) util.BlastDamage(self.Weapon, self.Owner, self.Owner:GetPos(), 200, 5) end end end //(DO NOT UNCOMMENT THIS END!! IT BORKS THE FILE!!) /*--------------------------------------------------------- PrimaryAttack (Attack attack ^^) ---------------------------------------------------------*/ function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire(CurTime() + 0.3) if SERVER then self.Owner:EmitSound(Sound("npc/vort/claw_swing"..tostring(math.random(1,2))..".wav")) end -- if SERVER then self.Owner:EmitSound(Sound("Zsword/oot-AdultLink_Sword"..tostring(math.random(1,3))..".wav")) end local ang = self.Owner:GetAimVector() local spos = self.Owner:GetShootPos() local trace = {} trace.start = spos trace.endpos = spos + (ang * 150) trace.filter = self.Owner local tr = util.TraceLine(trace) if tr.HitNonWorld then local bullet = {} bullet.Num=5 bullet.Src = self.Owner:GetShootPos() bullet.Dir= self.Owner:GetAimVector() bullet.Spread = Vector(0.2,0.2,0.2) bullet.Tracer = 0 bullet.Force = 10 bullet.Damage = 10 self.Owner:FireBullets(bullet) self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER) elseif tr.HitWorld then self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER) elseif !tr.Hit then self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER) if SERVER then if self.Owner:Health() >= 100 then self.plasma = ents.Create("env_citadel_energy_core") self.plasma:SetKeyValue("scale","2") self.plasma:SetKeyValue("spawnflags","3") self.plasma:SetKeyValue("globalname",self.Owner:Name().."rifleshot") self.plasma:SetPos(self.Owner:GetShootPos()) self.plasma:SetAngles(self.Owner:GetAngles()) self.plasma:Spawn() table.insert(self.plasmatable,self.plasma) end end end end /*--------------------------------------------------------- SecondaryAttack (Jump attack) ---------------------------------------------------------*/ SWEP.InAirDmg = 0 function SWEP:SecondaryAttack() if self.Owner:KeyDown(IN_USE) and self.Spinning == 0 then self.OldSpin = 1 - self.OldSpin else if SERVER then self.Owner:EmitSound(Sound("Zsword/oot-AdultLink_Sword"..tostring(math.random(2,3))..".wav")) end if SERVER then self.Owner:EmitSound(Sound("player/suit_sprint.wav")) end self.Weapon:SetNextSecondaryFire(CurTime() + 100) self.Weapon:SetNextPrimaryFire(CurTime() + 100) self.PrevHP = self.Owner:Health() if SERVER then self.Owner:SetVelocity(self.Owner:GetUp() * 200 + Vector(0,0,400)) end timer.Simple(0.2,self.SecondaryAttackDelay,self) end end function SWEP:SecondaryAttackDelay() self.InAirDmg = 1 self.JumpRefire = true end /*--------------------------------------------------------- Holster ---------------------------------------------------------*/ function SWEP:Holster() return true end /*--------------------------------------------------------- Deploy ---------------------------------------------------------*/ function SWEP:Deploy() self.Weapon:SendWeaponAnim(ACT_VM_DRAW) return true end /*--------------------------------------------------------- Draw hud ---------------------------------------------------------*/ function SWEP:DrawHUD() end [/code]
You're using the outdated timer syntax. On line 201, change [lua]timer.Simple(0.2,self.SecondaryAttackDelay,self)[/lua] to [lua]timer.Simple(0.2, function() self.SecondaryAttackDelay() end)[/lua]
[QUOTE=code_gs;42824896]You're using the outdated timer syntax. On line 201, change [lua]timer.Simple(0.2,self.SecondaryAttackDelay,self)[/lua] to [lua]timer.Simple(0.2, function() self.SecondaryAttackDelay() end)[/lua][/QUOTE] I used the new syntax that you posted; however, I get this error: [ERROR] gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua:206: attempt to index local 'self' (a nil value) 1. unknown - gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua:206 Timer Failed! [Simple][@gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua (line 201)] [ERROR] gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua:206: attempt to index local 'self' (a nil value) 1. unknown - gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua:206 Timer Failed! [Simple][@gamemodes/terrortown/entities/weapons/weapon_mastersword/shared.lua (line 201)]
I assume it would require self.InAirDmg = 1 to be self.Weapon:InAirDmg = 1
[QUOTE=Nookyava;42825082]I assume it would require self.InAirDmg = 1 to be self.Weapon:InAirDmg = 1[/QUOTE] Tried that and got this: [ERROR] gamemodes/terrortown/gamemode/cl_wepswitch.lua:101: attempt to call method 'Ammo1' (a nil value) 1. DrawWeapon - gamemodes/terrortown/gamemode/cl_wepswitch.lua:101 2. Draw - gamemodes/terrortown/gamemode/cl_wepswitch.lua:155 3. unknown - gamemodes/terrortown/gamemode/cl_hud.lua:340
That has nothing to do with the weapon, it's from your cl_wepswitch TTT file.
[QUOTE=code_gs;42825335]That has nothing to do with the weapon, it's from your cl_wepswitch TTT file.[/QUOTE] Any ideas of what I could do to get it working?
[QUOTE=code_gs;42824896]You're using the outdated timer syntax. On line 201, change [lua]timer.Simple(0.2,self.SecondaryAttackDelay,self)[/lua] to [lua]timer.Simple(0.2, function() self.SecondaryAttackDelay() end)[/lua][/QUOTE] change [lua]timer.Simple(0.2,self.SecondaryAttackDelay,self)[/lua] to [lua]timer.Simple(0.2, function() self:SecondaryAttackDelay() end)[/lua] ( Note the symbol after self )
Sorry, you need to Log In to post a reply to this thread.