diff options
author | Singularis <singularis@volny.cz> | 2024-12-08 12:05:36 +0100 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2025-05-27 20:22:01 +0200 |
commit | c46cf7d336f2004371efca60adb4a4937cd73f46 (patch) | |
tree | 7bed183ac578588e970f6fb9c28850afbfaf7dc8 /advtrains | |
parent | 5ae5aaa402f520ccddea25d93c48aef5b828aae2 (diff) | |
download | advtrains-c46cf7d336f2004371efca60adb4a4937cd73f46.tar.gz advtrains-c46cf7d336f2004371efca60adb4a4937cd73f46.tar.bz2 advtrains-c46cf7d336f2004371efca60adb4a4937cd73f46.zip |
[advtrains,ch_overrides] Implementováno sražení postavy vlakem (prvotní implementace)
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/helpers.lua | 5 | ||||
-rw-r--r-- | advtrains/protection.lua | 7 | ||||
-rw-r--r-- | advtrains/trainlogic.lua | 22 |
3 files changed, 30 insertions, 4 deletions
diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua index 58a21f6..db5023b 100644 --- a/advtrains/helpers.lua +++ b/advtrains/helpers.lua @@ -236,10 +236,11 @@ 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 not minetest.check_player_privs(name, "train_ghost") + --[[ if minetest.check_player_privs(name, "train_admin") then return false end - return minetest.settings:get_bool("enable_damage") + return minetest.settings:get_bool("enable_damage") ]] end function advtrains.ms_to_kmh(speed) diff --git a/advtrains/protection.lua b/advtrains/protection.lua index 7474977..edeef37 100644 --- a/advtrains/protection.lua +++ b/advtrains/protection.lua @@ -25,6 +25,13 @@ minetest.register_privilege("railway_operator", { give_to_singleplayer= true, }); +-- Other privileges +minetest.register_privilege("train_ghost", { + description = "Poskytuje imunitu proti sražení vlakem.", + give_to_singleplayer = false, +}); + + -- there is a configuration option "allow_build_only_owner". If this is active, a player having track_builder can only build rails and operate signals/turnouts in an area explicitly belonging to him -- (checked using a dummy player called "*dummy*" (which is not an allowed player name)) diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 9e5d19a..4177bc2 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -62,10 +62,17 @@ local LZB_ZERO_APPROACH_DIST = 0.1 -- Speed the train temporarily approaches the stop point with local LZB_ZERO_APPROACH_SPEED = 0.2 - +local on_player_overrun = {} tp_player_tmr = 0 +function advtrains.register_on_player_overrun(func) + -- func = function(player, train_id, train_velocity) + -- train_velocity is a vector with direction of the train's move and length of the train's current speed + assert(type(func) == "function") + table.insert(on_player_overrun, func) +end + advtrains.mainloop_trainlogic=function(dtime, stepno) --build a table of all players indexed by pts. used by damage and door system. advtrains.playersbypts={} @@ -771,10 +778,20 @@ function advtrains.train_step_c(id, train, dtime) end --- 8b damage players --- - if is_loaded_area and train.velocity > 3 and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") then + if is_loaded_area and train.velocity > 3 --[[ and (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 player:get_hp()>0 and advtrains.is_damage_enabled(player:get_player_name()) then + local train_nextpos = advtrains.path_get(train, atround(collindex) + 1) + if train_nextpos == nil or vector.equals(train_nextpos, collpos) then + minetest.log("error", "Player "..player:get_player_name().." was overrun by train "..train.id..", but can't determine the train's direction!") + else + local train_direction = vector.direction(collpos, train_nextpos) + for _, func in ipairs(on_player_overrun) do + func(player, train.id, train_direction, train.velocity) + end + end + --[[ --atdebug("damage found",player:get_player_name()) if setting_overrun_mode=="drop" then --instantly kill player @@ -791,6 +808,7 @@ function advtrains.train_step_c(id, train, dtime) player_inv:set_list("craft", {}) end player:set_hp(0) + ]] end end end |