1
2
3
4
5
2
3
4
5
player(id,"x") player(id,"y") player(id,"tilex") player(id,"tiley") player(id,"rot")
Scripts
Does player(id,"<name>") increase network traffic?
Does player(id,"<name>") increase network traffic?
1

player(id,"x") player(id,"y") player(id,"tilex") player(id,"tiley") player(id,"rot")
DC:movetilehook seemed unreliable because high ping clients usually trigger it more than once and it breaks some of the scripts I made.
mozilla1: That's because of TPS. Your script had to interact with CS2D API too frequantly, so Lua script had to wait for the response from the API each time on hook event.. it's only single-threaded. Try considering some kind of caching/optimizing or ms100 as you mentioned.
movetile works by comparing the player position with the previous position on movement. If the tile (tilex/tiley) changed then movetile is invoked. If now movement packages arrive out of order (which they can because they are sent in an unreliable and unsorted way - which is probably CS2D's biggest network design flag) movetile may be invoked multiple times depending on the order of the packages even though the player actually moved from tile a to tile b only once.
Gaios: That explanation doesn't make sense to me. TPS = transactions per second? Didn't we just clarify that there are no extra network transactions going on?
movetile itself also doesn't cause extra traffic. Furthermore all CS2D Lua calls are synchronous (because it is a single thread like you said correctly) which means that the results are always returned instantly without any waiting time. The only problems (which come to my mind) related to that could be that the scripts are too heavy for the server to keep up a healthy tick rate - which shouldn't cause trouble with movetile being called multiple times. Or that the hooks invoke Lua methods which cause traffic - which may cause network lag and could indeed lead to problems with movetile.
DC:
DC has written
Gaios has writtenaddhookin CS2D scripting, the server registers a new event listener, in this case for the "movetile" event, which is triggered every time a player moves on the map. Additionally, within this function, as you mentioned, there are API queries like
player(id, "<type>")that fetch information about the player.
player(id, "<type>")commands also involves fetching data from the server to the Lua script, causing the server or script to freeze until a response is received. Importantly, this process is synchronous, not asynchronous, meaning that one operation has to complete before the next one can start.
player(id, "<type>")commands leads to a synchronous execution, causing potential freezes or delays in the server/script until the necessary data is retrieved. This can impact the performance, especially with frequent movements or API queries.
Ranu has written
Gaios has written
Ranu: Please stay friendly.
§3.1 - No posts which offend/provoke/insult (flame)
Gaios: Some of the things you said are a bit misleading
movetile.
move which actually triggers on each movement.player(id, "<type>")commands also involves fetching data from the server to the Lua script, causing the server or script to freeze until a response is received.
mozilla1: If your server has FPS / tick rate drops then the problems might be caused by too much Lua being executed. Otherwise they are most likely caused by CS2D's network protocol & bad client connections as I described earlier.
Gaios:
DC: function movetile( id, x, y ) 	if area[x][y] then 		-- Stuff 		wrapper_function(x, y) 	end end
wrapper_function(x, y)is actually called twice or more in some occasions, and even more if I use
setpossomewhere in the wrapper function.
for i = 1, 32 do
	tilex[i] = 0
	tiley[i] = 0
end
addhook("ms100","ms100")
function ms100()
	for index, id in pairs(player(0,"tableliving")) do
		local x, y = player(id,"tilex"), player(id,"tiley")
		if tilex[id] ~= x or tiley[id] ~= y then
			tilex[id] = x
			tiley[id] = y
		
			movetile(id, x, y)
		end
	end
end
mozilla1: Try that. This shouldn't make much server freezes. Also it has no performance reason to check if xor
ychanged to assign new values - especially if you don't use
movetilefunction.
for i = 1, 32 do
tilex[i] = 0
tiley[i] = 0
end
addhook('move', 'onMove')
function onMove(id, x, y)
tilex[id] = x
tiley[id] = y
end
movetilefunction look like? What do you want to achieve by the way?
mozilla1 has writtenfunction movetile( id, x, y ) 	if area[x][y] then 		-- Stuff 		wrapper_function(x, y) 	end end
mozilla1: What you're doing is basically what
movetile does. Only that movetile checks each movement instead of only checking the position every 100 ms.
Gaios: I don't see how this is helpful
mozilla1's code does. It only caches x and y positions in tables
move params contain the pixel position not the tile position. Storing its x/y params in variables called tilex and tiley is misleading/wrong
ms100 is only executed 10 times per second.player(id,"tilex")do NOT cause any network traffic and are relatively cheap on the CPU. There is no real difference between getting the position via
move and via
player. A good rule of thumb is: If you can call Lua less frequently (
move is called more often than
ms100 in most gameplay situations) then go that way.
player a few times.
1
