1
2
3
4
5
2
3
4
5
player(id,"x")
player(id,"y")
player(id,"tilex")
player(id,"tiley")
player(id,"rot")
player(id,"x")
player(id,"y")
player(id,"tilex")
player(id,"tiley")
player(id,"rot")
movetilehook seemed unreliable because high ping clients usually trigger it more than once and it breaks some of the scripts I made.
addhookin 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.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.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
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?
function movetile( id, x, y )
if area[x][y] then
-- Stuff
wrapper_function(x, y)
end
end
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.