Add setting for death behavior and implement damage checks better
parent
bc31f205cd
commit
7149137990
|
@ -232,6 +232,16 @@ function advtrains.is_creative(name)
|
||||||
return minetest.settings:get_bool("creative_mode")
|
return minetest.settings:get_bool("creative_mode")
|
||||||
end
|
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)
|
function advtrains.ms_to_kmh(speed)
|
||||||
return speed * 3.6
|
return speed * 3.6
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,3 +33,9 @@ advtrains_prot_range_up (Track protection range [up]) int 3 0 10
|
||||||
# Players without the 'track_builder' privilege can not build within a box around any tracks determined by these range settings
|
# 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
|
# 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
|
|
@ -1,6 +1,7 @@
|
||||||
--trainlogic.lua
|
--trainlogic.lua
|
||||||
--controls train entities stuff about connecting/disconnecting/colliding trains and other things
|
--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 benchmark=false
|
||||||
local bm={}
|
local bm={}
|
||||||
|
@ -534,10 +535,12 @@ function advtrains.train_step_c(id, train, dtime)
|
||||||
collided = true
|
collided = true
|
||||||
end
|
end
|
||||||
--- 8b damage players ---
|
--- 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 testpts = minetest.pos_to_string(testpos)
|
||||||
local player=advtrains.playersbypts[testpts]
|
local player=advtrains.playersbypts[testpts]
|
||||||
if player and not minetest.check_player_privs(player, "creative") and train.velocity>3 then
|
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
|
--instantly kill player
|
||||||
--drop inventory contents first, to not to spawn bones
|
--drop inventory contents first, to not to spawn bones
|
||||||
local player_inv=player:get_inventory()
|
local player_inv=player:get_inventory()
|
||||||
|
@ -550,6 +553,7 @@ function advtrains.train_step_c(id, train, dtime)
|
||||||
-- empty lists main and craft
|
-- empty lists main and craft
|
||||||
player_inv:set_list("main", {})
|
player_inv:set_list("main", {})
|
||||||
player_inv:set_list("craft", {})
|
player_inv:set_list("craft", {})
|
||||||
|
end
|
||||||
player:set_hp(0)
|
player:set_hp(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue