aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
author1F616EMO <root@1f616emo.xyz>2024-10-22 06:59:16 +0800
committerorwell <orwell@bleipb.de>2024-11-09 22:00:33 +0100
commit6d3c5a5f38d66a74c7b2bc219ee16f258ba50a2b (patch)
tree1d0953ac7bab3a28a499402e88ea32d39db49711 /advtrains/trainlogic.lua
parent96f4ac7f6c2ff7fae56102640e9e63305ca64b16 (diff)
downloadadvtrains-6d3c5a5f38d66a74c7b2bc219ee16f258ba50a2b.tar.gz
advtrains-6d3c5a5f38d66a74c7b2bc219ee16f258ba50a2b.tar.bz2
advtrains-6d3c5a5f38d66a74c7b2bc219ee16f258ba50a2b.zip
Wagon iterator, lookup by id, and use them in code
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r--advtrains/trainlogic.lua19
1 files changed, 6 insertions, 13 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index f136577..ce646da 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -142,13 +142,8 @@ minetest.register_on_joinplayer(function(player)
local pname = player:get_player_name()
local id=advtrains.player_to_train_mapping[pname]
if id then
- for _,wagon in pairs(minetest.luaentities) do
- if wagon.is_wagon and wagon.initialized and wagon.id then
- local wdata = advtrains.wagons[wagon.id]
- if wdata and wdata.train_id == id then
- wagon:reattach_all()
- end
- end
+ for _, wagon in advtrains.wagon_entity_pairs_in_train(id) do
+ wagon:reattach_all()
end
end
end)
@@ -160,12 +155,10 @@ minetest.register_on_dieplayer(function(player)
if id then
local train=advtrains.trains[id]
if not train then advtrains.player_to_train_mapping[pname]=nil return end
- for _,wagon in pairs(minetest.luaentities) do
- if wagon.is_wagon and wagon.initialized and wagon.train_id==id then
- --when player dies, detach him from the train
- --call get_off_plr on every wagon since we don't know which one he's on.
- wagon:get_off_plr(pname)
- end
+ for _, wagon in advtrains.wagon_entity_pairs_in_train(id) do
+ --when player dies, detach him from the train
+ --call get_off_plr on every wagon since we don't know which one he's on.
+ wagon:get_off_plr(pname)
end
-- just in case no wagon felt responsible for this player: clear train mapping
advtrains.player_to_train_mapping[pname] = nil