Scorch player when too close to explosion

This commit is contained in:
Wuzzy 2024-12-14 22:20:05 +01:00
parent d19d58a4d0
commit 4d5ac605b0
6 changed files with 46 additions and 4 deletions

View File

@ -7,6 +7,9 @@ Players can have 0 to lzr_damage.MAX_DAMAGE. Damage in this mod is
just a visual effect on the screen but has no gameplay effect on its own.
But it can be queried when the player has reached a certain damage.
Damage is never lethal.
Players may also receive damage of the type "scorched",
which will change the player model and wieldhand texture and wieldhand
to a scorched version until player_damage is reduced to 0.
The player damage can be added to, or reset to 0. When the player has
damage, it will slowly be reduced to 0 again.
@ -29,6 +32,9 @@ local HEAL_TIME = 3.0
-- and decreases while out of danger
local player_damage = 0
-- If true, player is using the scorched texture
local player_is_scorched = false
-- Count the time for how many consecutive seconds the player did
-- not take damage yet.
local safe_timer = 0
@ -58,12 +64,27 @@ local update_damage_screen = function(player)
end
end
local update_player_skin = function(player)
if player_is_scorched then
local state = lzr_gamestate.get_state()
if state ~= lzr_gamestate.EDITOR and state ~= lzr_gamestate.DEV then
lzr_hand.set_hand(player, "scorched")
player_api.set_textures(player, {"character_scorched.png"})
end
else
lzr_hand.set_hand(player, "normal")
player_api.set_textures(player, {"character.png"})
end
end
lzr_damage.reset_player_damage = function(player)
player_damage = 0
player_is_scorched = false
update_player_skin(player)
update_damage_screen(player)
end
lzr_damage.damage_player = function(player, damage)
lzr_damage.damage_player = function(player, damage, damage_type)
safe_timer = 0
player_damage = player_damage + (damage or 1)
if player_damage > lzr_damage.MAX_DAMAGE then
@ -78,12 +99,20 @@ lzr_damage.damage_player = function(player, damage)
gain = 0.4
end
local texture = "lzr_damage_screen_"..player_damage..".png"
if player_damage >= 1 and damage_type == "scorch" then
player_is_scorched = true
update_player_skin(player)
end
update_damage_screen(player)
minetest.sound_play({name="lzr_damage_damage", gain=gain}, {to_player=player:get_player_name()}, true)
end
local undamage_player = function(player)
player_damage = math.max(0, player_damage - 1)
if player_damage == 0 then
player_is_scorched = false
update_player_skin(player)
end
update_damage_screen(player)
end

View File

@ -1,3 +1,3 @@
name = lzr_damage
depends = lzr_gamestate
depends = lzr_gamestate, lzr_hand, player_api
description = Custom damage mechanic for players

View File

@ -60,14 +60,27 @@ end
editor_handdef.groups.not_in_creative_inventory = 1
minetest.register_item("lzr_hand:hand_editor", editor_handdef)
-- Scorched hand
-- Identical to default hand except it is scorched
local scorched_handdef = table.copy(handdef)
scorched_handdef.wield_image = "lzr_hand_hand_scorched.png"
scorched_handdef.inventory_image = "lzr_hand_hand_scorched.png"
if not scorched_handdef.groups then
scorched_handdef.groups = {}
end
scorched_handdef.groups.not_in_creative_inventory = 1
minetest.register_item("lzr_hand:hand_scorched", scorched_handdef)
-- Switch hand type for player.
-- hand_hype is one of "normal" or "editor"
-- hand_hype is one of "normal", "scorched" or "editor"
function lzr_hand.set_hand(player, hand_type)
local inv = player:get_inventory()
if hand_type == "normal" then
minetest.log("action", "[lzr_hand] Setting hand to normal hand")
inv:set_stack("hand", 1, "")
elseif hand_type == "scorched" then
minetest.log("action", "[lzr_hand] Setting hand to scorched hand")
inv:set_stack("hand", 1, "lzr_hand:hand_scorched")
elseif hand_type == "editor" then
minetest.log("action", "[lzr_hand] Setting hand to editor hand")
inv:set_stack("hand", 1, "lzr_hand:hand_editor")

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

View File

@ -643,7 +643,7 @@ lzr_laser.deal_bomb_damage = function(pos)
if objs[o]:is_player() then
local dist = vector.distance(pos, objs[o]:get_pos())
local ratio = math.max(0, math.min(1, 1 - dist / BOMB_DAMAGE_RADIUS))
lzr_damage.damage_player(objs[o], math.ceil(ratio * lzr_damage.MAX_DAMAGE))
lzr_damage.damage_player(objs[o], math.ceil(ratio * lzr_damage.MAX_DAMAGE), "scorch")
lzr_slowdown.slowdown(objs[o], ratio * BOMB_SLOWDOWN_TIME, BOMB_SLOWDOWN_TIME)
else
local dist = vector.distance(pos, objs[o]:get_pos())

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB