Forum

> > CS2D > Scripts > Bug in entitylist()?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Bug in entitylist()?

7 replies
To the start Previous 1 Next To the start

old Bug in entitylist()?

Happy Camper
User Off Offline

Quote
I noticed some unexpected behaviour with the entitylist() function. For some maps it doesn't return all the entities in the map. Is this a know bug/limitation or have I missed something?

Here's a piece of code that can be used to show it:
1
2
3
4
5
6
7
8
addhook("serveraction", "serveraction")
function serveraction(id, action)
	local list = entitylist()

	for x, y in pairs(list) do
		parse("spawnitem 73 " .. x .. " " .. y)
	end
end
It will spawn a molotov cocktail on all entities when you press a server action key. When I tried it on ctf_cs2dfortress, approximately half of the entities were missing from the list.

old Re: Bug in entitylist()?

Apache uwu
User Off Offline

Quote
You can try manually getting all the entities through a loop instead.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
entitylist=function()
	local list={}
	for x=0,map("xsize") do
		for y=0,map("ysize") do
			if entity(x,y,"exists") then
				table.insert(list,x,y)
			end
		end
	end
	return list
end

addhook("serveraction", "serveraction")
function serveraction(id, action)
	local list = entitylist()
	for x, y in pairs(list) do
		parse("spawnitem 73 " .. x .. " " .. y)
	end
end

Seems to work fine for me.

old Re: Bug in entitylist()?

DC
Admin Off Offline

Quote
Entities can also be placed outside the map boundaries so this solution is not perfect. I'll add the problem to my todo list and fix it if something is wrong.

old Re: Bug in entitylist()?

DC
Admin Off Offline

Quote
It would work for entities which are in that area, yes. But what if there's an entity at (-1414908|-85854)? You would have to check a very huge area (integer boundaries) to be 100% sure to detect each entity at each possible position... and that would be super slow and inefficient.

Your method is a nice idea but of course not the best and fastest solution. It's a fine quick fix until I fix the original function.

old Re: Bug in entitylist()?

Apache uwu
User Off Offline

Quote
I recommend making the entity table a static, since entities do not change you only need to search for entities once.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview