aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains/helpers.lua10
-rw-r--r--advtrains/settingtypes.txt8
-rw-r--r--advtrains/trainlogic.lua30
3 files changed, 34 insertions, 14 deletions
diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua
index 3514f55..e04991e 100644
--- a/advtrains/helpers.lua
+++ b/advtrains/helpers.lua
@@ -232,6 +232,16 @@ function advtrains.is_creative(name)
return minetest.settings:get_bool("creative_mode")
end
+function advtrains.is_damage_enabled(name)
+ if not name then
+ error("advtrains.is_damage_enabled() called without name parameter!")
+ end
+ if minetest.check_player_privs(name, "train_admin") then
+ return false
+ end
+ return minetest.settings:get_bool("enable_damage")
+end
+
function advtrains.ms_to_kmh(speed)
return speed * 3.6
end
diff --git a/advtrains/settingtypes.txt b/advtrains/settingtypes.txt
index 49df423..26c6d5a 100644
--- a/advtrains/settingtypes.txt
+++ b/advtrains/settingtypes.txt
@@ -32,4 +32,10 @@ advtrains_prot_range_up (Track protection range [up]) int 3 0 10
# Track protection range (down)
# Players without the 'track_builder' privilege can not build within a box around any tracks determined by these range settings
# This setting determines the lower y bound of the box, a value of 1 means that the rail and 1 node below it are protected
-advtrains_prot_range_down (Track protection range [down]) int 1 0 10 \ No newline at end of file
+advtrains_prot_range_down (Track protection range [down]) int 1 0 10
+
+# Determine what effect "being overrun by a train" has.
+# none: No damage is dealt at all.
+# drop: Player is killed, all items are dropped as items on the tracks.
+# normal: Player is killed, game-defined behavior is applied as if the player died by other means.
+advtrains_overrun_mode (Overrun mode) enum drop none,drop,normal \ No newline at end of file
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 2371490..523e51d 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -1,6 +1,7 @@
--trainlogic.lua
--controls train entities stuff about connecting/disconnecting/colliding trains and other things
+local setting_overrun_mode = minetest.settings:get("advtrains_overrun_mode")
local benchmark=false
local bm={}
@@ -534,22 +535,25 @@ function advtrains.train_step_c(id, train, dtime)
collided = true
end
--- 8b damage players ---
- if not minetest.settings:get_bool("creative_mode") then
+ if setting_overrun_mode=="drop" or setting_overrun_mode=="normal" then
local testpts = minetest.pos_to_string(testpos)
local player=advtrains.playersbypts[testpts]
- if player and not minetest.check_player_privs(player, "creative") and train.velocity>3 then
- --instantly kill player
- --drop inventory contents first, to not to spawn bones
- local player_inv=player:get_inventory()
- for i=1,player_inv:get_size("main") do
- minetest.add_item(testpos, player_inv:get_stack("main", i))
+ if player and train.velocity>3 and player:get_hp()>0 and advtrains.is_damage_enabled(player:get_player_name()) then
+ --atdebug("damage found",player:get_player_name())
+ if setting_overrun_mode=="drop" then
+ --instantly kill player
+ --drop inventory contents first, to not to spawn bones
+ local player_inv=player:get_inventory()
+ for i=1,player_inv:get_size("main") do
+ minetest.add_item(testpos, player_inv:get_stack("main", i))
+ end
+ for i=1,player_inv:get_size("craft") do
+ minetest.add_item(testpos, player_inv:get_stack("craft", i))
+ end
+ -- empty lists main and craft
+ player_inv:set_list("main", {})
+ player_inv:set_list("craft", {})
end
- for i=1,player_inv:get_size("craft") do
- minetest.add_item(testpos, player_inv:get_stack("craft", i))
- end
- -- empty lists main and craft
- player_inv:set_list("main", {})
- player_inv:set_list("craft", {})
player:set_hp(0)
end
end