From a71041b66b0518625083560a4acb7f38bbc18148 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Fri, 24 Aug 2018 09:58:23 +0200 Subject: Fix teleporting player to train The previous commit did the teleporting in the wrong place, causing the teleports to be sent as many times as there are trains in the world A similar commit is included in the tss branch, there it is included in one single commit --- advtrains/trainlogic.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index f2ed831..c3fbe4a 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -46,6 +46,8 @@ local t_accel_eng={ [4] = 1.5, } +local tptimer = 0 + advtrains.mainloop_trainlogic=function(dtime) --build a table of all players indexed by pts. used by damage and door system. advtrains.playersbypts={} @@ -55,6 +57,14 @@ advtrains.mainloop_trainlogic=function(dtime) local ptspos=minetest.pos_to_string(vector.round(player:getpos())) advtrains.playersbypts[ptspos]=player end + + if tptimer<=0 then + -- teleport players to their train + advtrains.tp_player_to_train(player) + tptimer = 2 + else + tptimer = tptimer - dtime + end end --regular train step -- do in two steps: @@ -430,12 +440,6 @@ function advtrains.train_step_a(id, train, dtime) train.check_trainpartload=(train.check_trainpartload or 0)-dtime local node_range=(math.max((minetest.settings:get("active_block_range") or 0),1)*16) if train.check_trainpartload<=0 then - -- teleport players to their train - for _, player in pairs(minetest.get_connected_players()) do - advtrains.tp_player_to_train(player) - end - - local ori_pos=train_pos --see 3a. --atprint("[train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos))) -- cgit v1.2.3