aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-07-21 16:43:37 +0200
committerorwell96 <orwell@bleipb.de>2018-08-12 18:01:50 +0200
commit3dc5b28774670b3c7b505f3f6f9603ba683a299e (patch)
treefe41329d96d7376df6ca46d182a3d1a9b5606a73
parentb80ba056d9ba993109ceae11eac403139afec39f (diff)
downloadadvtrains-3dc5b28774670b3c7b505f3f6f9603ba683a299e.tar.gz
advtrains-3dc5b28774670b3c7b505f3f6f9603ba683a299e.tar.bz2
advtrains-3dc5b28774670b3c7b505f3f6f9603ba683a299e.zip
Teleport player to their train every 2 seconds instead of just on_joinplayer
Solves problem of wagon being unloaded while player sitting inside it because of network lag
-rw-r--r--advtrains/trainlogic.lua47
1 files changed, 31 insertions, 16 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index c032937..861c042 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -46,6 +46,8 @@ local t_accel_eng={
[4] = 1.5,
}
+tp_player_tmr = 0
+
advtrains.mainloop_trainlogic=function(dtime)
--build a table of all players indexed by pts. used by damage and door system.
advtrains.playersbypts={}
@@ -56,6 +58,16 @@ advtrains.mainloop_trainlogic=function(dtime)
advtrains.playersbypts[ptspos]=player
end
end
+
+ if tp_player_tmr<=0 then
+ -- teleport players to their train every 2 seconds
+ for _, player in pairs(minetest.get_connected_players()) do
+ advtrains.tp_player_to_train(player)
+ end
+ tp_player_tmr = 2
+ else
+ tp_player_tmr = tp_player_tmr - dtime
+ end
--regular train step
--[[ structure:
1. make trains calculate their occupation windows when needed (a)
@@ -87,28 +99,31 @@ advtrains.mainloop_trainlogic=function(dtime)
endstep()
end
-minetest.register_on_joinplayer(function(player)
+function advtrains.tp_player_to_train(player)
+ local pname = player:get_player_name()
+ local id=advtrains.player_to_train_mapping[pname]
+ if id then
+ local train=advtrains.trains[id]
+ if not train then advtrains.player_to_train_mapping[pname]=nil return end
+ --set the player to the train position.
+ --minetest will emerge the area and load the objects, which then will call reattach_all().
+ --because player is in mapping, it will not be subject to dying.
+ player:setpos(train.last_pos_prev)
+ end
+end
+minetest.register_on_joinplayer(function()
return advtrains.pcall(function()
- local pname=player:get_player_name()
- local id=advtrains.player_to_train_mapping[pname]
- if id then
- local train=advtrains.trains[id]
- if not train then advtrains.player_to_train_mapping[pname]=nil return end
- --set the player to the train position.
- --minetest will emerge the area and load the objects, which then will call reattach_all().
- --because player is in mapping, it will not be subject to dying.
- player:setpos(train.last_pos_prev)
- --independent of this, cause all wagons of the train which are loaded to reattach their players
- --needed because already loaded wagons won't call reattach_all()
- for _,wagon in pairs(minetest.luaentities) do
- if wagon.is_wagon and wagon.initialized and wagon.train_id==id then
- wagon:reattach_all()
- end
+ --independent of this, cause all wagons of the train which are loaded to reattach their players
+ --needed because already loaded wagons won't call reattach_all()
+ for _,wagon in pairs(minetest.luaentities) do
+ if wagon.is_wagon and wagon.initialized and wagon.train_id==id then
+ wagon:reattach_all()
end
end
end)
end)
+
minetest.register_on_dieplayer(function(player)
return advtrains.pcall(function()
local pname=player:get_player_name()