Add setting for death behavior and implement damage checks better

This commit is contained in:
orwell96 2019-03-09 11:29:22 +01:00
parent bc31f205cd
commit 7149137990
3 changed files with 34 additions and 14 deletions

View File

@ -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

View File

@ -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
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

View File

@ -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