Forum

> > CS2D > Scripts > Bug in entitylist()?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Bug in entitylist()?

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Bug in entitylist()?

Happy Camper
User Off Offline

Zitieren
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.

alt Re: Bug in entitylist()?

Apache uwu
User Off Offline

Zitieren
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.

alt Re: Bug in entitylist()?

DC
Admin Off Offline

Zitieren
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.

alt Re: Bug in entitylist()?

DC
Admin Off Offline

Zitieren
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.

alt Re: Bug in entitylist()?

Apache uwu
User Off Offline

Zitieren
I recommend making the entity table a static, since entities do not change you only need to search for entities once.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht