aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--couple.lua19
-rw-r--r--wagons.lua17
2 files changed, 33 insertions, 3 deletions
diff --git a/couple.lua b/couple.lua
index 5e6d81b..a846c8b 100644
--- a/couple.lua
+++ b/couple.lua
@@ -26,9 +26,26 @@ minetest.register_entity("advtrains:discouple", {
self.object:remove()
return
end
+ self.object:set_armor_groups({immortal=1})
end,
get_staticdata=function() return "DISCOUPLE" end,
- on_punch=function(self)
+ on_punch=function(self, player)
+ --only if player owns at least one wagon next to this
+ local own=player:get_player_name()
+ if self.wagon.owner and self.wagon.owner~=own then
+ local train=advtrains.trains[self.wagon.train_id]
+ local nextwgn_id=train.trainparts[self.wagon.pos_in_trainparts-1]
+ for aoi, le in pairs(minetest.luaentities) do
+ if le and le.is_wagon then
+ if le.unique_id==nextwgn_id then
+ if le.owner and le.owner~=own then
+ minetest.chat_send_player(own, "You need to own at least one neighboring wagon to destroy this couple.")
+ return
+ end
+ end
+ end
+ end
+ end
advtrains.split_train_at_wagon(self.wagon)--found in trainlogic.lua
end,
on_step=function(self, dtime)
diff --git a/wagons.lua b/wagons.lua
index 7511f5d..c0a2f77 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -17,7 +17,7 @@ local wagon={
function wagon:on_rightclick(clicker)
- print("[advtrains] wagon rightclick")
+ --print("[advtrains] wagon rightclick")
if not clicker or not clicker:is_player() then
return
end
@@ -64,6 +64,7 @@ function wagon:on_activate(staticdata, dtime_s)
self.unique_id=tmp.unique_id
self.train_id=tmp.train_id
self.wagon_flipped=tmp.wagon_flipped
+ self.owner=tmp.owner
end
end
@@ -106,6 +107,7 @@ function wagon:get_staticdata()
unique_id=self.unique_id,
train_id=self.train_id,
wagon_flipped=self.wagon_flipped,
+ owner=self.owner,
})
end
@@ -114,6 +116,10 @@ function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direct
if not puncher or not puncher:is_player() then
return
end
+ if self.owner and puncher:get_player_name()~=self.owner then
+ minetest.chat_send_player(puncher:get_player_name(), "This wagon is owned by "..self.owner..", you can't destroy it.")
+ return
+ end
if minetest.setting_getbool("creative_mode") then
self:destroy()
@@ -361,7 +367,14 @@ function advtrains.register_wagon(sysname, traintype, prototype, desc, inv_img)
if not pointed_thing.type == "node" then
return
end
- local le=minetest.env:add_entity(pointed_thing.under, "advtrains:"..sysname):get_luaentity()
+ local ob=minetest.env:add_entity(pointed_thing.under, "advtrains:"..sysname)
+ if not ob then
+ print("[advtrains]couldn't add_entity, aborting")
+ end
+ local le=ob:get_luaentity()
+
+ le.owner=placer:get_player_name()
+ le.infotext=desc..", owned by "..placer:get_player_name()
local node=minetest.env:get_node_or_nil(pointed_thing.under)
if not node then print("[advtrains]Ignore at placer position") return itemstack end