I was testing the method to get the entnum from the last spawned entity mentioned by Purple here: Anti-Door Block, which is used to iterate through all the entities
and I noticed that sometimes it works fine and sometimes it does not.


I tested this script in obj/obj_team2 with freeze-tag and a weapon mod with no players


level waittill spawn;
wait 10; // Tested with and without the wait

local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max0";
println $max0.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max1";
println $max1.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max2";
println $max2.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max3";
println $max3.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max4";
println $max4.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max5";
println $max5.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max6";
println $max6.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max7";
println $max7.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max8";
println $max8.entnum;
local.max = spawn script_model model "models/fx/dummy.tik" origin ( 0 0 -5000 ) targetname "max9";
println $max9.entnum;


And this is the output:

57
58
80
81
158
159
160
161
162
163


I suppose this happens when using the 'remove', 'immediateremove', 'take', 'takeall' and probably other commands, to temove entities from the game, (or when they are automatically removed by the game)
And then when you spawn a new entity, that new entity will get a previously used entnum to "fill the gaps" of the list.

The thing is: This method is inconsistent. Sometimes it returns the expected output and sometimes it doesn't, depending on what mods the server is running. So, heads up with that.