diff options
author | orwell96 <mono96.mml@gmail.com> | 2016-09-29 08:20:06 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2016-09-29 08:20:06 +0200 |
commit | bb50b390d4b0669718eb9872d294256e026b42ca (patch) | |
tree | 2c3808b05f289b9da538d37a3b0120a078b0e4e9 | |
parent | 2d59119e372996adeda7e37ae61f899e170d3514 (diff) | |
download | advtrains-bb50b390d4b0669718eb9872d294256e026b42ca.tar.gz advtrains-bb50b390d4b0669718eb9872d294256e026b42ca.tar.bz2 advtrains-bb50b390d4b0669718eb9872d294256e026b42ca.zip |
add owner system to prevent random train destroying
-rw-r--r-- | couple.lua | 19 | ||||
-rw-r--r-- | wagons.lua | 17 |
2 files changed, 33 insertions, 3 deletions
@@ -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) @@ -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
|