• self.Entity code help
    11 replies, posted
Hello. I have tried to fix the lua error in many different ways, but i can't get it fixed. 12:59:22 Lua Error: [Drugs Mod] lua/entities/durgz_base/init.lua:127: Tried to use a NULL entity! 1. Remove - [C]:-1 2. unknown - lua/entities/durgz_base/init.lua:127 LINE 127 = self.Entity:Remove()
Could you show the function at least? [editline]10th July 2015[/editline] Or the whole file
Thatll be better..
From the error at least it tells that you're trying to remove an entity that doesn't exist. self.Entity is not an entity hence the error
Sure.. Sorry [QUOTE]function ENT:Use(activator,caller) umsg.Start("durgz_lose_virginity", activator) umsg.End() self:High(activator,caller); if( self.HASHIGH )then DoHigh( activator, caller, self:GetClass(), self.LASTINGEFFECT, self.TRANSITION_TIME, self.OverdosePhrase, self.Nicknames ); end self:AfterHigh(activator, caller); for k,v in pairs(self.LACED)do local drug = ents.Create(v); drug:Spawn(); drug:High(activator,caller); DoHigh( activator, caller, drug:GetClass(), drug.LASTINGEFFECT, drug.TRANSITION_TIME, drug.OverdosePhrase, drug.Nicknames ); drug:AfterHigh(activator,caller); drug:Remove(); end self.Entity:Remove() end[/QUOTE]
Replace that line (self.Entity:Remove()) with: [code] if (IsValid(self.Entity)) then self.Entity:Remove() end [/code]
The error is gone now. But when you pocket water, and put the water out from your pocket again and then trying to take the water then you can spam the "e" button and the water will not disappear. You will just get water and water and water.
Replace self.Entity:Remove() with self:Remove()
It's still the same. The line is now [QUOTE]if (IsValid(self.Entity)) then self:Remove() end[/QUOTE] No errors, but i can still spam the e button on a drug I throw out of the pocket.
Post the entire file
[QUOTE]AddCSLuaFile("shared.lua") include("shared.lua") ENT.MODEL = "models/props_c17/briefcase001a.mdl" ENT.LASTINGEFFECT = 30; ENT.HASHIGH = true ENT.MULTIPLY = 1 ENT.LACED = {} --console commands CreateConVar( "durgz_witty_sayings", "1", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) --0 for no witty sayings when you take the drug CreateConVar( "durgz_roleplay", "0", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) --set to 1 for none of those "special" side effects (like ultimate speed and really low gravity) function ENT:SpawnFunction( ply, tr, Classname) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create(Classname) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end function ENT:Initialize() self:SetModel( self.MODEL ) self:PhysicsInit( SOLID_VPHYSICS ) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.LACED = {}; if( self.MASS )then self.Entity:GetPhysicsObject():SetMass( self.MASS ); end end function ENT:OnTakeDamage( dmginfo ) self.Entity:TakePhysicsDamage( dmginfo ) end local function DoHigh(activator, caller, class, lastingeffect, transition_time, overdosephrase, nicknames) --if you're transitioning to the end and you take another, smoothen it out if activator:GetNetworkedFloat(class.."_high_end") && activator:GetNetworkedFloat(class.."_high_end") > CurTime() && activator:GetNetworkedFloat(class.."_high_end") - transition_time < CurTime() then --set the high start in such a way to where it doesn't snap to the start time, goes smoooothly. local set = CurTime() - ( activator:GetNetworkedFloat(class.."_high_end") - CurTime() ); activator:SetNetworkedFloat(class.."_high_start", set); --if you're not high at all elseif( !activator:GetNetworkedFloat(class.."_high_start") || activator:GetNetworkedFloat(class.."_high_end") < CurTime() )then activator:SetNetworkedFloat(class.."_high_start", CurTime()); end --high is done local ctime; if( !activator:GetNetworkedFloat(class.."_high_end") || activator:GetNetworkedFloat(class.."_high_end") < CurTime() )then ctime = CurTime(); --you're already high on the drug, add more highness else ctime = activator:GetNetworkedFloat(class.."_high_end") - lastingeffect/3; end activator:SetNetworkedFloat(class.."_high_end", ctime + lastingeffect); if( activator:GetNetworkedFloat(class.."_high_end") && activator:GetNetworkedFloat(class.."_high_end") - lastingeffect*5 > CurTime() )then --kill em activator.DURGZ_MOD_DEATH = class; activator.DURGZ_MOD_OVERDOSE = overdosephrase[math.random(1, #overdosephrase)]; activator.DURGZ_MOD_NICKNAMES = nicknames[math.random(1, #nicknames)]; activator:Kill(); end end hook.Add("PlayerDeath", "durgz_death_notice", function(victim, inflictor, attacker) if( victim.DURGZ_MOD_DEATH )then --add shmexy killicon umsg.Start( "PlayerKilledByDrug" ) umsg.Entity( victim ); umsg.String( victim.DURGZ_MOD_DEATH ); umsg.End() local s = victim.DURGZ_MOD_OVERRIDE or victim:Nick().." "..victim.DURGZ_MOD_OVERDOSE.." "..victim.DURGZ_MOD_NICKNAMES.." and died."; /*for id,pl in pairs(player.GetAll())do pl:PrintMessage(HUD_PRINTTALK, s); end*/ MsgAll(s); victim.DURGZ_MOD_DEATH = nil; victim.DURGZ_MOD_OVERDOSE = nil; victim.DURGZ_MOD_NICKNAMES = nil; victim.DURGZ_MOD_OVERRIDE = nil; return true end end) function ENT:Use(activator,caller) umsg.Start("durgz_lose_virginity", activator) umsg.End() self:High(activator,caller); if( self.HASHIGH )then DoHigh( activator, caller, self:GetClass(), self.LASTINGEFFECT, self.TRANSITION_TIME, self.OverdosePhrase, self.Nicknames ); end self:AfterHigh(activator, caller); for k,v in pairs(self.LACED)do local drug = ents.Create(v); drug:Spawn(); drug:High(activator,caller); DoHigh( activator, caller, drug:GetClass(), drug.LASTINGEFFECT, drug.TRANSITION_TIME, drug.OverdosePhrase, drug.Nicknames ); drug:AfterHigh(activator,caller); drug:Remove(); end if (IsValid(self.Entity)) then self:Remove() end end --this is pretty much a function you call if you want the person taking the drug to say something, all this function does is check if the console command is a ok. function ENT:Say(pl, str) local should_say = GetConVar("durgz_witty_sayings", 0):GetBool() local is_empty = type(str) == "string" and str == "" or type(str) == "table" and #str == 0 or str == nil if should_say and !is_empty then if type(str) == "table" then str = str[math.random(1, #str)] end pl:ConCommand("say "..str) end return should_say end function ENT:Realistic() return GetConVar("durgz_roleplay", 0):GetBool() end function ENT:High(activator, caller) end function ENT:AfterHigh(activator, caller) end local function SoberUp(pl, x, y, z, ndeath, didntdie) --make a smooth transition and not a instant soberization local drugs = { "weed", "cocaine", "cigarette", "alcohol", "mushroom", "meth", "ecstasy", "caffeine", "pcp", "lsd", "opium" } local ttime = { 6, 5, 4, 6, 6, 3, 3, 3, 3, 6, 3 } --you can't get out of the heroine high because you die when the high ends if( !didntdie )then table.insert(ttime, 5) table.insert(drugs, "heroine") end for i = 1, #drugs do local tend = 0 if( pl:GetNetworkedFloat("durgz_"..drugs[i].."_high_start") + ttime[i] > CurTime() )then tend = ( CurTime() - pl:GetNetworkedFloat("durgz_"..drugs[i].."_high_start") ) + CurTime() elseif !( pl:GetNetworkedFloat("durgz_"..drugs[i].."_high_end") - ttime[i] < CurTime() )then tend = CurTime() + ttime[i] elseif( pl:GetNetworkedFloat("durgz_"..drugs[i].."_high_end") > CurTime() )then tend = pl:GetNetworkedFloat("durgz_"..drugs[i].."_high_end") end pl:SetNetworkedFloat("durgz_"..drugs[i].."_high_start", 0) pl:SetNetworkedFloat("durgz_"..drugs[i].."_high_end", tend) end --set speed back to normal if pl.durgz_cocaine_fast then pl:SetWalkSpeed(DURGZ_DEFAULT_WALK_SPEED) pl:SetRunSpeed(DURGZ_DEFAULT_RUN_SPEED) pl.durgz_cocaine_fast = false end --set sound to normal pl:SetDSP(1, false) --no more floating pl:SetGravity(1) if( ndeath )then pl:EmitSound(Sound("vo/npc/male01/moan0"..math.random(4,5)..".wav")) end end hook.Add("DoPlayerDeath", "durgz_sober_up_cmd_death", SoberUp) hook.Add("PlayerSpawn", "durgz_sober_up_cmd_spawn", SoberUp) function ENT:Soberize(pl) SoberUp(pl, true, true, true, true, true); end[/QUOTE]
[QUOTE=Marciano;48164298]It's still the same. The line is now No errors, but i can still spam the e button on a drug I throw out of the pocket.[/QUOTE] Replace IsValid(self.Entity) with IsValid(self) [editline]10th July 2015[/editline] Also for future reference use the [code] tag when posting code
Sorry, you need to Log In to post a reply to this thread.