forked from Dumpster-Studios/fire_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.lua
More file actions
145 lines (125 loc) · 3.74 KB
/
api.lua
File metadata and controls
145 lines (125 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
local armor_mod = minetest.get_modpath("3d_armor")
-- Replace min/max table with random value from min to max
local function get_val(val)
if type(val) == "table" then
val = math.random(val.min or 1, val.max or 5)
end
return val
end
function fire_plus.burn_player(player, burns, damage, not_initial)
if not player then
minetest.log("warning", "[Fire Plus] (burn_player): player is nil")
end
local name = player
if type(player) == "string" then
player = minetest.get_player_by_name(player)
end
if not player or player:get_hp() <= 0 then
fire_plus.extinguish_player(name)
return
end
name = player:get_player_name()
-- 3d_armor fire protection puts out flames
if armor_mod and armor.def[name].fire > 1 then
fire_plus.extinguish_player(name)
end
-- Fire was extinguished
if not fire_plus.burning[name] and not_initial then
return
end
if not fire_plus.burning[name] then
burns = get_val(burns)
fire_plus.burning[name] = {
burns_left = burns,
hud_id = player:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.95},
offset = {x = 0, y = 0},
text = "fire_basic_flame.png",
alignment = -1,
scale = {x = 100, y = 32},
number = 0xFFFFFF,
}),
sound_id = minetest.sound_play("fire_fire", {
to_player = name,
gain = 1.0,
loop = true,
}),
particlespawner_id = minetest.add_particlespawner({
amount = 10,
time = 0,
minpos = vector.new(-0.3, 0.5, -0.3),
maxpos = vector.new( 0.3, 2, 0.3),
minvel = {x = -1, y = 0, z = -1},
maxvel = {x = 1, y = 1, z = 1},
minacc = {x = 0, y = 2, z = 0},
maxacc = {x = 0, y = 3, z = 0},
minexptime = 0.5,
maxexptime = 1,
minsize = 3,
maxsize = 3,
texture = "smoke_puff.png",
collisiondetection = true,
glow = 0,
attached = player,
}),
particlespawner_id2 = minetest.add_particlespawner({
amount = 5,
time = 0,
minpos = vector.new(0, 0.5, -0.3),
maxpos = vector.new( 0, 0.5, 0.3),
minvel = {x = 0, y = 0, z = 0},
maxvel = {x = 0, y = 0, z = 0},
minacc = {x = 0, y = 0, z = 0},
maxacc = {x = 0, y = 0, z = 0},
minexptime = 0.5,
maxexptime = 1,
minsize = 10,
maxsize = 10,
texture = "fire_basic_flame_animated.png",
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 1,},
collisiondetection = false,
glow = minetest.LIGHT_MAX,
attached = player,
})
}
else
player:set_hp(player:get_hp() - get_val(damage), {type = "set_hp", fire_plus = true})
if minetest.get_modpath("tnt") then
local tntpos = minetest.find_node_near(player:get_pos(), fire_plus.tnt_explode_radius, {"tnt:tnt"}, true)
if tntpos then
tnt.boom(tntpos, {radius = fire_plus.tnt_explode_radius, damage_radius = fire_plus.tnt_explode_radius})
end
end
if not_initial then
fire_plus.burning[name].burns_left = fire_plus.burning[name].burns_left - 1
else
fire_plus.burning[name].burns_left = burns
end
end
if fire_plus.burning[name].burns_left > 0 then
minetest.after(fire_plus.burn_interval, function()
fire_plus.burn_player(name, burns, damage, true)
end)
else
fire_plus.extinguish_player(name)
end
end
function fire_plus.extinguish_player(player)
local name = player
if player then
if type(name) ~= "string" then
name = player:get_player_name()
else
player = minetest.get_player_by_name(name)
end
end
if not fire_plus.burning[name] then return end
if player then
player:hud_remove(fire_plus.burning[name].hud_id)
minetest.sound_fade(fire_plus.burning[name].sound_id, 1, 0)
end
minetest.delete_particlespawner(fire_plus.burning[name].particlespawner_id)
minetest.delete_particlespawner(fire_plus.burning[name].particlespawner_id2)
fire_plus.burning[name] = nil
end