]> git.lizzy.rs Git - crafter_client.git/blob - fire_handling.lua
Add fire animation when player is on fire
[crafter_client.git] / fire_handling.lua
1 local on_fire = 0
2 local fire_id = nil
3 local fire_animation_timer = 0
4 local fire_animation_tile = 0
5 --receive the server states
6 minetest.register_on_modchannel_message(function(channel_name, sender, message)
7         if channel_name == name..":fire_state" then
8         on_fire = tonumber(message)
9         end
10 end)
11
12 minetest.register_globalstep(function(dtime)
13     if on_fire == 0 then 
14         if fire_id then
15             minetest.localplayer:hud_remove(fire_id)
16             fire_id = nil
17         end
18     elseif on_fire == 1 then
19         if fire_id == nil then
20             fire_id = minetest.localplayer:hud_add({
21                                 hud_elem_type = "image", -- see HUD element types, default "text"
22                                 position = {x=0.5, y=0.5},
23                                 name = "",    -- default ""
24                                 scale = {x=-100, y=-100}, -- default {x=0,y=0}
25                                 text = "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile,
26             })
27         else
28             fire_animation_timer = fire_animation_timer + dtime
29             if fire_animation_timer >= 0.05 then
30                 fire_animation_timer = 0
31                 fire_animation_tile = fire_animation_tile + 1
32                 if fire_animation_tile > 7 then
33                     fire_animation_tile = 0
34                 end
35                 minetest.localplayer:hud_change(fire_id, "text", "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile)
36             end
37         end
38     end
39 end)