From 711145f4f628651d779dc4dc1d8db2a3b8e649c6 Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Sun, 7 Jun 2020 11:35:47 -0400 Subject: [PATCH] Add fire animation when player is on fire --- fire_handling.lua | 39 +++++++++++++++++++++++++++++++++++++++ init.lua | 5 ++++- version_send.lua | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 fire_handling.lua diff --git a/fire_handling.lua b/fire_handling.lua new file mode 100644 index 0000000..d4a6cd1 --- /dev/null +++ b/fire_handling.lua @@ -0,0 +1,39 @@ +local on_fire = 0 +local fire_id = nil +local fire_animation_timer = 0 +local fire_animation_tile = 0 +--receive the server states +minetest.register_on_modchannel_message(function(channel_name, sender, message) + if channel_name == name..":fire_state" then + on_fire = tonumber(message) + end +end) + +minetest.register_globalstep(function(dtime) + if on_fire == 0 then + if fire_id then + minetest.localplayer:hud_remove(fire_id) + fire_id = nil + end + elseif on_fire == 1 then + if fire_id == nil then + fire_id = minetest.localplayer:hud_add({ + hud_elem_type = "image", -- see HUD element types, default "text" + position = {x=0.5, y=0.5}, + name = "", -- default "" + scale = {x=-100, y=-100}, -- default {x=0,y=0} + text = "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile, + }) + else + fire_animation_timer = fire_animation_timer + dtime + if fire_animation_timer >= 0.05 then + fire_animation_timer = 0 + fire_animation_tile = fire_animation_tile + 1 + if fire_animation_tile > 7 then + fire_animation_tile = 0 + end + minetest.localplayer:hud_change(fire_id, "text", "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile) + end + end + end +end) \ No newline at end of file diff --git a/init.lua b/init.lua index c61eb85..bf07b14 100644 --- a/init.lua +++ b/init.lua @@ -7,6 +7,7 @@ nether = nil aether = nil name = nil version_channel = nil +fire_handling_channel = nil function initialize_all() --declare globals for now @@ -17,7 +18,8 @@ function initialize_all() nether = minetest.mod_channel_join(name..":nether_teleporters") aether = minetest.mod_channel_join(name..":aether_teleporters") version_channel = minetest.mod_channel_join(name..":client_version_channel") - + fire_handling_channel = minetest.mod_channel_join(name..":fire_state") + --next we load everything seperately because it's easier to work on individual files than have everything jammed into one file --not into seperate mods because that is unnecessary and cumbersome local path = minetest.get_modpath("crafter_client") @@ -30,6 +32,7 @@ function initialize_all() dofile(path.."/music_handling.lua") dofile(path.."/version_send.lua") dofile(path.."/colored_names/colored_names.lua") + dofile(path.."/fire_handling.lua") end --we must delay initialization until the player exists in the world diff --git a/version_send.lua b/version_send.lua index 06d7e78..cffcfeb 100644 --- a/version_send.lua +++ b/version_send.lua @@ -1,3 +1,3 @@ minetest.after(0,function() - version_channel:send_all("0.5002") + version_channel:send_all("0.5003") end) \ No newline at end of file -- 2.44.0