• I keep having a crash issue with the error: CUtIRBTree overflow
    20 replies, posted
So I am trying to use a hook function so that whenever an entity is spawned it checks if it is part of a list of enemies or not, is so, set him as our enemy (self.Target), but whenever I spawn an enemy, he will shoot at them, they will shoot back, but about 1 second later my game crashes with this message: CUtIRBTree overflow. Here is my hook:     hook.Add( "OnEntityCreated", "SoftEntList", function( ent )         if IsValid(self) then             if ent:GetClass() == "npc_antlionguard" or                 ent:GetClass() == "npc_combine*" or                 ent:GetClass() == "*zombie*" or                 ent:GetClass() == "npc_helicopter" or                 ent:GetClass() == "npc_manhack" or                 ent:GetClass() == "npc_metropolice" or                 ent:GetClass() == "npc_rollermine" or                 ent:GetClass() == "npc_strider" or                 ent:GetClass() == "npc_turret*" or                 ent:GetClass() == "npc_hunter" or                 ent:GetClass() == "npc_combine_s" or                 ent:GetClass() == "antlion"              then             timer.Simple(.1,function()                 target = ents.Create("npc_bullseye")                     target:SetParent(self)                     target:SetPos(self:GetPos()+Vector(0,0,20))                     target:Spawn()                     target:SetHealth(9999999)                     target:Activate()                     target:SetKeyValue( "health","9999" )                       target:SetKeyValue( "spawnflags","256" )                      target:SetNotSolid( true )                     -- This is where we find our enemies and list them, if they are listed, they will attack. (IK its inefficient...)                     for k,v in pairs(ents.FindByClass("npc_*")) do                          if ( string.find(v:GetClass(), "npc_antlionguard")) or                              ( string.find(v:GetClass(), "npc_combine*")) or                              ( string.find(v:GetClass(), "*zombie*")) or                              ( string.find(v:GetClass(), "npc_helicopter")) or                              ( string.find(v:GetClass(), "npc_manhack")) or                              ( string.find(v:GetClass(), "npc_metropolice")) or                              ( string.find(v:GetClass(), "npc_rollermine")) or                              ( string.find(v:GetClass(), "npc_strider")) or                              ( string.find(v:GetClass(), "npc_turret*")) or                              ( string.find(v:GetClass(), "npc_hunter")) or                             ( string.find(v:GetClass(), "npc_combine_s")) or                             ( string.find(v:GetClass(), "antlion")) then                             v:AddEntityRelationship( target, D_HT, 15 )                         end                     end                 end)             end         end     end) Another issue I have is that I want to create a healthbar at the bottom of the recruiters screen, I have the derma frame setup, but I don't know how to bring the entities health into the client init. As well as put in a text bot, like so. net.Receive("OpenMenu", function()      local frame = vgui.Create("DFrame")      frame:SetSize(280,80)      frame:SetPos(ScrW()/1.1985,ScrH()/1.25)     frame:SetScreenLock(true)     frame:ShowCloseButton(false)     frame:SetTitle("")     frame:SetDraggable(false)         function frame:Paint( w, h )             draw.RoundedBox( 10, 0, 0, w, h, Color( 0, 0, 0, 100 ) )         end     net.Receive("HealthBar", function()         local str = net.ReadString()         local num = net.ReadInt(32)         local bool = net.ReadBool()         if ( bool ) then return end         print(str .. num .. ".")     end)     local HP = vgui.Create("DLabel", frame)         HP:SetText("Mercenary HP: "..LocalPlayer():Health())         HP:SetPos(10, 25)         HP:SetFont("Health Bar")         HP:SetColor(Color(255, 255, 0))         HP:SetSize(1000, 30)     net.Receive("CloseMenu",function()         frame:Close()     end) end) function ENT:Think()     if self.Recruited then         self:NextThink(1)         print("This works!")         net.Start("HealthBar")             net.WriteString("I like cheese!")             net.WriteInt(self:Health(),32)             net.WriteBool(false)         net.Send(self.Recruiter)     end end Any help would be greatly appreciated, thanks in advance.
Okay, so now I am using draw.Rect, anyway, how do I relate the entities health into cl_init.lua
You are creating an infinite loop with entity creation - calling ents.Create with npc_bullseye will call OnEntityCreated and keep adding children to "self", which is the source of your error. Also, you really don't have to use this huge bullseye hack to make a proper entity relationship - you just have to alter the NPC's schedule after you add the relationship.
net.Receive("OpenMenu", function()     Healthbar = true     HP = net.ReadInt(32)     net.Receive("CloseMenu",function()         Healthbar = false     end) end) hook.Add("HUDPaint","HealthBar",function()     if Healthbar then         surface.SetDrawColor(50,50,50,255)         surface.DrawRect(30-2,ScrH()-170-2,300+4,30+4)         surface.SetDrawColor(255,100,100,255)         surface.SetTexture(10)         surface.DrawTexturedRect(30, ScrH()-170,300*HP / 100,30)         draw.SimpleText(HP,"MyFont",30+150,ScrH()-170+15,Color(255,255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)     else return end end) So here is the code I'm using, for some reason though, it always displays his health as 0, IDK why. In init.lua, here is the function for the WriteInt     function ENT:Think()         self:NextThink(.3)         if self.Recruited then             net.Start("HealthBar")                 net.WriteInt(self:Health(), 32)             net.Send(self.Recruiter)         end     end
This code works just fine with a test NPC "npc_test": AddCSLuaFile() ENT.Base = "base_ai" ENT.Type = "ai" ENT.Category = "foo" ENT.Spawnable = true function ENT:Initialize() self:SetModel("models/monk.mdl") if (SERVER) then self:PhysicsInitBox(Vector(-13, -13, 0), Vector(13, 13, 72)) end end local tHateNPCs = { ["npc_combine_s"] = true, ["npc_metropolice"] = true, ["npc_hunter"] = true } hook.Add("OnEntityCreated", "NPCTest", function(pEntity) if (pEntity:IsNPC() and tHateNPCs[pEntity:GetClass()]) then pEntity:AddRelationship("npc_test D_HT 99") end end)
Ill use the attacker one, but how can I constantly update the HP of the nextbot, I tried ontakedamage, but it isn't working as a function whatsoever. I don't know if it is networked or not.
The NPCs shot my test NPC - you can verify with the code above. That means the issue is with your SENT code in some manner.
I don't know how I can refer to my entity on clientside, since its clientside, but I tried moving my nextbot to multiplayer, and when I spawned it, others saw it as doing a sit animation, I saw it as standing, and only one of us could have one at a time.
    hook.Add("OnEntityCreated", "NPCTest", function(pEntity)         local tHateNPCs = {             ["npc_combine_s"] = true,             ["npc_metropolice"] = true,             ["npc_hunter"] = true         }         local ent = ents.FindByClass("recruitables")         if tHateNPCs[pEntity:GetClass()] and IsValid(ent) then             pEntity:AddRelationship("recruitables D_HT 99")             print("This works!")         elseif (!tHateNPCs[pEntity:GetClass()]) then             return         end     end) This isn't working, it prints "This works!" yet the enemies don't shoot at my NPC.
That code will not work - you don't need to use FindByClass or get the ents at all.
If I spawn an enemy without IsValid(ent) then it causes errors because he is not valid, yet it still tries to run.
That shouldn't matter in the code you posted - you don't use ent at all, and FindByClass returns a table which will never pass IsValid.
    local tHateNPCs = {         ["npc_combine_s"] = true,         ["npc_metropolice"] = true,         ["npc_hunter"] = true,         ["npc_manhack"] = true     }     hook.Add("OnEntityCreated", "StuffandStuff", function(pEntity)         if (pEntity:IsNPC() and tHateNPCs[pEntity:GetClass()]) then             pEntity:AddRelationship("recruitables D_HT 99")         end     end) That is literally the code I'm using and yet they are not attacking, know what could be causing this?
For the third time, the problem is with your actual SNPC code. Posting it might be a good start.
I physically can't post it , I can post some of the segments related to it, but its over 750 lines, and the website won't allow that.
Use pastebin or the like.
Like even when I try to make it fit, and its under 100% it just says error 404, page not found.
Your NPC has no physics object or solid type - the collision bounds won't even be taken into account unless you set that, and thus other NPCs have nowhere to shoot at. See Entity/PhysicsInit or Entity/SetSolid (both are not necessary). Also, Entity/AddFlags takes one argument. If you want to set multiple flags, use bit.bor. Also, you shouldn't be setting FL_CLIENT - it's used internally for players only and should not be set on (next)bots.
FL_CLIENT is what I use so that it can open automatic doors, and it works fine, used it before. But thanks for the fast responses, Ill test it out now.
Try Entity/PhysicsInitBox with your collision bounds. Could you also post your shared.lua so I can test?
shared.lua https://pastebin.com/GybyyVhh init.lua https://pastebin.com/SMGAE9sU cl_init.lua https://pastebin.com/PVVjLXRw
Sorry, you need to Log In to post a reply to this thread.