Can only 1 ents.FindInBox / SetGlobalInt be set off at a time?

I have 2 people at 2 different ents.FindInBox functions. Both of those ents.FindInBox functions have different SetGlobalInt variables. Only one ents.FindInBox seems to get updated, and I can’t figure out wether it’s the ents.FindInBox or the SetGlobalInt.

Questions:

  1. Can more than one SetGlobalInt go off at once?

  2. Can only one ents.FindInBox be triggered at a time?

Thanks for answering!

Yes, but the global ints will have to have unique identifiers, otherwise, they will conflict. There’s probably a better way to do what you want – could you describe it or post code?

Yep!

Here’s some code:




--init.lua

include("maps/warehouse/a.lua")

include("maps/warehouse/b.lua")

include("maps/warehouse/c.lua")

		if game.GetMap() == "svm_warehouse" then
		hook.Add("Think", "controlpointAWAREHOUSE", pointaWAREHOUSE )
		hook.Add("Think", "controlpointBWAREHOUSE", pointbWAREHOUSE )
		hook.Add("Think", "controlpointCWAREHOUSE", pointcWAREHOUSE )
		end

-- Example of a control point "maps/warehouse/c.lua":

function pointcWAREHOUSE()

if !Cscore then
Cscore = 0
Cscoresmooth = 0
Ccaptured = false
end
if roundActive == true then
for k, v in pairs(ents.FindInBox( Vector(3316.973145, 3450.772949, 70.683151), Vector(3777.455322, 3051.297363, 271.332001) ) ) do
		
		if v:IsPlayer() and v:Team() == 1 and Ccaptured == false then
				local DelayTime = .5
	if Cscore != 25 then
		
				
		if !ply.CmdDelay then
			ply.CmdDelay = 0
		end

            if ply.CmdDelay < CurTime() then
        ply.CmdDelay = CurTime() + DelayTime
		Cscore = Cscore - 1
		if Cscore == -1 then
		Cscore = 0
		end
		if Cscore == 1 then
		if SERVER then
		PrintMessage(HUD_PRINTTALK,"The Mercs have reset the Spies' progress at point C!")
		end
		end
		end
		end	
		end	
		if v:IsPlayer() and v:Team() == 0 and Ccaptured == false then
				local DelayTime = .5

		if !ply.CmdDelay then
			ply.CmdDelay = 0
		end

            if ply.CmdDelay < CurTime() then
        ply.CmdDelay = CurTime() + DelayTime
		Cscore = Cscore + 1
		if Cscore == 1 then
				if SERVER then
                            PrintMessage(HUD_PRINTTALK,"The Spies have started to capture Point C!")
                        end
				end
		if Cscore == 24 then
		Cscore = 25
		if SERVER then
		PrintMessage(HUD_PRINTTALK,"Spies captured Point C!")
		end
		Ccaptured = true
		end
		if Cscore == 26 then
		Cscore = 25
		end
		end	
				end
				
	end
	end
	
	SetGlobalInt("ProgressC", Cscore )
	SetGlobalBool("CapturedC", Ccaptured )
	
	end



Holy hell that’s one chaotic indentation. Could you sort that out to make the lives of those trying to help you easier? I cannot make anything out of this.

However, an ents.FindInBox in a Think hook is a sure-fire way to murder your server’s performance. Either make the actual function run every second or so, or use a zone entity (best option but harder to implement).

To see if a function runs like you want you can try placing prints around like “SETTING PROGRESS TO C …” to see if SetGlobalInt is actually being called.

I didn’t change anything in this code, I just wanted to fix that indentation. Auto-Indent ftw


--init.lua

include("maps/warehouse/a.lua")

include("maps/warehouse/b.lua")

include("maps/warehouse/c.lua")

if game.GetMap() == "svm_warehouse" then
     hook.Add("Think", "controlpointAWAREHOUSE", pointaWAREHOUSE )
     hook.Add("Think", "controlpointBWAREHOUSE", pointbWAREHOUSE )
     hook.Add("Think", "controlpointCWAREHOUSE", pointcWAREHOUSE )
end

-- Example of a control point "maps/warehouse/c.lua":

function pointcWAREHOUSE()
     
     if !Cscore then
          Cscore = 0
          Cscoresmooth = 0
          Ccaptured = false
     end
     if roundActive == true then
          for k, v in pairs(ents.FindInBox( Vector(3316.973145, 3450.772949, 70.683151), Vector(3777.455322, 3051.297363, 271.332001) ) ) do
               
               if v:IsPlayer() and v:Team() == 1 and Ccaptured == false then
                    local DelayTime = .5
                    if Cscore != 25 then
                         
                         
                         if !ply.CmdDelay then
                              ply.CmdDelay = 0
                         end
                         
                         if ply.CmdDelay < CurTime() then
                              ply.CmdDelay = CurTime() + DelayTime
                              Cscore = Cscore - 1
                              if Cscore == -1 then
                                   Cscore = 0
                              end
                              if Cscore == 1 then
                                   if SERVER then
                                        PrintMessage(HUD_PRINTTALK,"The Mercs have reset the Spies' progress at point C!")
                                   end
                              end
                         end
                    end	
               end	
               if v:IsPlayer() and v:Team() == 0 and Ccaptured == false then
                    local DelayTime = .5
                    
                    if !ply.CmdDelay then
                         ply.CmdDelay = 0
                    end
                    
                    if ply.CmdDelay < CurTime() then
                         ply.CmdDelay = CurTime() + DelayTime
                         Cscore = Cscore + 1
                         if Cscore == 1 then
                              if SERVER then
                                   PrintMessage(HUD_PRINTTALK,"The Spies have started to capture Point C!")
                              end
                         end
                         if Cscore == 24 then
                              Cscore = 25
                              if SERVER then
                                   PrintMessage(HUD_PRINTTALK,"Spies captured Point C!")
                              end
                              Ccaptured = true
                         end
                         if Cscore == 26 then
                              Cscore = 25
                         end
                    end	
               end
               
          end
     end
     
     SetGlobalInt("ProgressC", Cscore )
     SetGlobalBool("CapturedC", Ccaptured )
     
end

what do you mean by zone entity?

A dummy entity with StartTouch so that when a player “touches” that zone, they get added to a table corresponding to that zone entity.

[editline]12th October 2017[/editline]

Although, this is kinda advanced because you have to deal with collision and stuff. Your code does the job but will murder the server’s FPS which is why a better alternative for you is to make your checks in 1-second timer instead of a Think hook which runs every frame.

Hey, I made it so it updates every .5 seconds, and it works beautifully. I figured out why all of my code wasn’t executing, and that’s still a problem. All three of my functions (
pointaWAREHOUSE(), pointbWAREHOUSE(), and pointcWAREHOUSE()) aren’t executing at the same time. For example, the points are listed as so:




init.lua:

--these aren't in a function

pointaWAREHOUSE()
pointbWAREHOUSE()
pointcWAREHOUSE()




Let’s say that my friend on the other team is at point B. I cannot capture C, but I can capture A. If he’s C, then I can capture both A and B. I’ve tried both timers and the GM:Think function, but they both don’t work.
Is there any way to make it all execute all code below what point he’s in?

First off make a variable that shows if anyone is on point A, then one for point B, then one on point C.
Have it something like 0 = Noone on the point, 1 = Friends on the point, 2 = Enemies on the point and 3 = Both on the point.
Set them up and use them to do the rest, should be a piece of cake after that.

If you want to execute them all at the same time, then there’s no way to do that, every script is read from top to bottom.



if(whoIsOnB != (2 || 3)) then
     
     pointaWAREHOUSE()
     
end

if(whoIsOnC == (2 || 3)) then
     
     pointaWAREHOUSE()
     pointbWAREHOUSE()
     
end


Something like that. But I don’t know what pointaWAREHOUSE() etc. does, I used them like they are the functions to capture the point but you tell me.

will try this when I get home! Thanks for the solution man! Quick question though, what are the vertical bars for? I don’t think I’ve seen them in Gmod LUA before

|| = or
&& = and

I prefer using them because they look cooler and I started off coding E2 then moved onto lua

Theoretically, couldn’t someone create a square prop that is simply a collision mesh, and then once a cube/rectangle is defined via vectors, spawn the prop in the middle and scale collision mesh? Would there be any problems with doing that?

Just tried it, didn’t work, am I doing it wrong?




--Example of one of the points

function pointaWAREHOUSE()

    pointa = 0

for k, v in pairs(ents.FindInBox( Vector(2478.453125, 3488.321533, 64.624039), Vector(2020.106567, 2852.683594, 644.221130) ) ) do
		
		if v:IsPlayer() and v:Team() == 1 and Acaptured == false then

		     pointa = 2

                end
                if v:IsPlayer() and v:Team() == 0 and Acaptured == false then

                     pointa = 1

                end

end

-- Example of what I put in init:

if(pointb == (2)) then
     
     pointcWAREHOUSE()
     
end

if(pointa == (2)) then
    
	pointbWAREHOUSE()
     pointcWAREHOUSE()
     
end


Try changing that FindInBox, you need to put first the vector that has all of the X Y and Z smaller than the X Y and Z of the second vector. So in your case it should be:



ents.FindInBox( Vector(2020.106567, 2852.683594, 64.624039), Vector(2478.453125, 3488.321533, 644.221130) )


still didn’t work… any other solutions that I could possibly use?

(And thank you so much dude for helping me out btw)

Try printing in your console each state of each point and check what happens when an ally or enemy goes on it. Doing that usually helps out finding out what the problem is. Or try to do the rubbery ducky method on me, please explain me each step you are doing in your code and what each variable does (Also would help me too because I’m clueless at what you want to do TBH)

Hey! I FINALLY fixed it! Thank you so much for your help Ubre!

I fixed it by using the method you came up with:




if(whoIsOnB != (2 || 3)) then
     
     pointaWAREHOUSE()
     
end

if(whoIsOnC == (2 || 3)) then
     
     pointaWAREHOUSE()
     pointbWAREHOUSE()
     
end



But instead of using that, I added some hook.Adds for Think (I know this will decapitate server performance, looking for an alternative) and I also added hook.Removes.

Here is what the code looks like if anyone is interested:




if pointa == 0 && pointb == 0 then
hook.Remove("Think","controlpointBPOINTA")
hook.Remove("Think","controlpointCAfter2")
hook.Remove("Think","controlpointAAfter2")

hook.Remove("Think", "controlpointAAFTER")
hook.Remove("Think","controlpointBBeforeK")
hook.Remove("Think","controlpointCAfter1")

hook.Add("Think","controlpointABefore", pointaWAREHOUSE )
hook.Add("Think","controlpointBBefore", pointbWAREHOUSE )
hook.Add("Think","controlpointCBefore", pointcWAREHOUSE )
end

if pointb == 2 then
hook.Remove("Think","controlpointBBefore")
hook.Remove("Think","controlpointCBefore")
hook.Remove("Think","controlpointABefore")


hook.Remove("Think","controlpointBPOINTA")
hook.Remove("Think","controlpointCAfter2")
hook.Remove("Think","controlpointAAfter2")

hook.Add("Think","controlpointCAfter1", pointcWAREHOUSE )
hook.Add("Think", "controlpointAAFTER", pointaWAREHOUSE )
hook.Add("Think","controlpointBBeforeK", pointbWAREHOUSE )


end



I would like to thank EVERYONE who helped me out with this issue, you guys saved me a ton of headbanging! <3