aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2016-12-29 00:27:07 +0100
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2016-12-29 00:27:07 +0100
commit176ee0627ebc397c60650fc5b059829788fe3cdc (patch)
tree2608687c638bd8a7f24f38a812c95e63e22e0213
parentb4b4936b15127b48f527eccdcee0a5de82a2a2fb (diff)
downloadadvtrains-176ee0627ebc397c60650fc5b059829788fe3cdc.tar.gz
advtrains-176ee0627ebc397c60650fc5b059829788fe3cdc.tar.bz2
advtrains-176ee0627ebc397c60650fc5b059829788fe3cdc.zip
Added privilege to remove trains
-rw-r--r--trainlogic.lua10
-rw-r--r--wagons.lua19
2 files changed, 20 insertions, 9 deletions
diff --git a/trainlogic.lua b/trainlogic.lua
index 5e3936f..94dcb69 100644
--- a/trainlogic.lua
+++ b/trainlogic.lua
@@ -325,10 +325,12 @@ function advtrains.train_step(id, train, dtime)
if found_uids[w_id] then
--print(w_id.." still loaded")
elseif advtrains.wagon_save[w_id] then
- --print(w_id.." not loaded, but save available")
- --spawn a new and initialize it with the properties from wagon_save
- local le=minetest.env:add_entity(ori_pos, advtrains.wagon_save[w_id].entity_name):get_luaentity()
- le:init_from_wagon_save(w_id)
+ --print(w_id.." not loaded, but save available")
+ --spawn a new and initialize it with the properties from wagon_save
+ local le=minetest.add_entity(ori_pos, advtrains.wagon_save[w_id].entity_name):get_luaentity()
+ if le then -- Don't crash if traintype has been removed
+ le:init_from_wagon_save(w_id)
+ end
else
print(w_id.." not loaded and no save available")
--what the hell...
diff --git a/wagons.lua b/wagons.lua
index ca31590..8a96c39 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -2,6 +2,15 @@
--local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end
local print=function() end
+minetest.register_privilege("train_place", {
+ description = "Player can place trains on tracks not owned by player",
+ give_to_singleplayer= false,
+});
+minetest.register_privilege("train_remove", {
+ description = "Player can remove trains not owned by player",
+ give_to_singleplayer= false,
+});
+
local wagon={
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
--physical = true,
@@ -164,9 +173,9 @@ 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
+ if self.owner and puncher:get_player_name()~=self.owner and (not minetest.check_player_privs(puncher, {train_remove = true })) 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
@@ -534,7 +543,7 @@ function advtrains.register_wagon(sysname, traintype, prototype, desc, inv_img)
return
end
- local node=minetest.env:get_node_or_nil(pointed_thing.under)
+ local node=minetest.get_node_or_nil(pointed_thing.under)
if not node then print("[advtrains]Ignore at placer position") return itemstack end
local nodename=node.name
if(not advtrains.is_track_and_drives_on(nodename, advtrains.all_traintypes[traintype].drives_on)) then
@@ -544,7 +553,7 @@ function advtrains.register_wagon(sysname, traintype, prototype, desc, inv_img)
local conn1=advtrains.get_track_connections(node.name, node.param2)
local id=advtrains.create_new_train_at(pointed_thing.under, advtrains.dirCoordSet(pointed_thing.under, conn1), traintype)
- local ob=minetest.env:add_entity(pointed_thing.under, "advtrains:"..sysname)
+ local ob=minetest.add_entity(pointed_thing.under, "advtrains:"..sysname)
if not ob then
print("[advtrains]couldn't add_entity, aborting")
end