• Trying to make the Vortex Melon work for the newest version of Garry's Mod
    19 replies, posted
Help me please I am having issues with this LUA AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) function ENT:Initialize() self.Entity:SetModel( "models/props_junk/watermelon01.mdl" ) self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) local phys = self.Entity:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.ents = {} timer.Create("UpdateTargets"..tostring(self), 0.5, 0, self.UpdateTargets, self) timer.Create("DoEffects"..tostring(self), 0.05, 0, self.DoEffects, self) end function ENT:OnRemove() timer.Remove("UpdateTargets"..tostring(self)) timer.Remove("DoEffects"..tostring(self)) end function ENT:DoEffects() local allowed_classes = { "prop_physics", "prop_ragdoll"} for k,ent in pairs(self.ents) do if (!ent:IsValid() || ent == vortex_melon || (!table.HasValue(allowed_classes, ent:GetClass()) && !ent:IsNPC())) then self.ents[k] = nil else local rate = 5 local r,g,b,a = ent:GetColor() local alpha = a - rate if (alpha <= 0) then ent:Remove() self.ents[k] = nil else local ed = EffectData() ed:SetEntity( ent ) ed:SetOrigin( self:GetPos() ) util.Effect( "particle_funnel", ed, true, true ) ent:SetColor(r, g, b, alpha) end end end end function ENT:UpdateTargets() local radius = 256 self.ents = ents.FindInSphere(self:GetPos(), 256 radius) end function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create( "vortex_melon" ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end [Vortex Melon] lua/entities/vortex_melon/init.lua:32: attempt to index local 'self' (a nil value)   1. unknown - lua/entities/vortex_melon/init.lua:32 Timer Failed! [DoEffectsEntity [80][vortex_melon]][@lua/entities/vortex_melon/init.lua (line 20)] [Vortex Melon] lua/entities/vortex_melon/init.lua:60: attempt to index local 'self' (a nil value)   1. unknown - lua/entities/vortex_melon/init.lua:60 Timer Failed! [UpdateTargetsEntity [80][vortex_melon]][@lua/entities/vortex_melon/init.lua (line 19)] these are the errors I get
@thefuzz1234555 You are calling ENT function by it's meta. You need to call Method on it Table call: self.Draw() Method call: self:Draw() If function is called as Method it will give self for function. --- Also, you can create timer like that: "UpdateTargets"..self:EntIndex()
Where in the code should I put it like where its giving error lines?
Where you set up a callback function. In timer.Create
Hmm ok if I get another error from the code I'll comment what happend
Again. As a sad in first post. You need to call function ON Entity. So: // BEFORE timer.Create("UpdateTargets"..tostring(self), 0.5, 0, self.UpdateTargets, self) timer.Create("DoEffects"..tostring(self), 0.05, 0, self.DoEffects, self) // AFTER timer.Create("UpdateTargets"..tostring(self), 0.5, 0, self:UpdateTargets) timer.Create("DoEffects"..tostring(self), 0.05, 0, self:DoEffects)
That is not valid code. IT should be self.UpdateTargets and self.DoEffects
Yes, sorry, I understand it only now. I say that I was right because I'm doing like that: timer.Create("Timer",1,0,function() self:DoClick() end)
I put in the new code, its not appearing in the spawn menu anymore? Please help
Check your console (server and client) for errors.
Ill see if any show up when the map loads
I should provide line 59 self.ents = ents.FindInSphere(self:GetPos(), 256 radius)
That code isn't valid - what is "256 radius?" Your argument should just be a number or variable alone.
hmm so remove radius?
Try and see.
Huh that fixed it but new error... why [Vortex Melon] lua/entities/vortex_melon/init.lua:31: attempt to index local 'self' (a nil value)   1. unknown - lua/entities/vortex_melon/init.lua:31 Timer Failed! [DoEffectsEntity [67][vortex_melon]][@lua/entities/vortex_melon/init.lua (line 19)] [Vortex Melon] lua/entities/vortex_melon/init.lua:59: attempt to index local 'self' (a nil value)   1. unknown - lua/entities/vortex_melon/init.lua:59 Timer Failed! [UpdateTargetsEntity [67][vortex_melon]][@lua/entities/vortex_melon/init.lua (line 18)] Line 31: for k,ent in pairs(self.ents) do Line 19: timer.Create("DoEffects"..tostring(self), 0.05, 0, self.DoEffects) Line 59: self.ents = ents.FindInSphere(self:GetPos(), 256 ) Line 18: timer.Create("UpdateTargets"..tostring(self), 0.5, 0, self.UpdateTargets) Why does this old addon have to be so broken?
"self" is not valid in the code instances provided. It will only be so if you are using self in an ENT: function.
Hmm I don't know what to put @code_gs could you be more specific
Functions like this get "self" as a parameter which refers to the entity: function ENT:SomeFunc() Functions like this do not get a "self" parameter: function SomeFunc() function ENT.SomeFunc()
bump
Sorry, you need to Log In to post a reply to this thread.