-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshowhealth.lua
32 lines (29 loc) · 1.36 KB
/
showhealth.lua
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
-- Show the health of a player as a small piece of colored text above their head
-- A 3Ra Gaming creation
local function showhealth (event)
if game.tick % 30 ~= 0 then return end
for k, player in pairs(game.players) do
if player.connected then
if player.character then
if player.character.health == nil then return end
local index = player.index
local health = math.ceil(player.character.health)
if global.player_health == nil then global.player_health = {} end
if global.player_health[index] == nil then global.player_health[index] = health end
if global.player_health[index] ~= health then
global.player_health[index] = health
if health < 250 then
if health > 125 then
player.surface.create_entity { name = "flying-text", color = { b = 0.2, r = 0.1, g = 1, a = 0.8 }, text = (health), position = { player.position.x, player.position.y - 2 } }
elseif health > 74 then
player.surface.create_entity { name = "flying-text", color = { r = 1, g = 1, b = 0 }, text = (health), position = { player.position.x, player.position.y - 2 } }
else
player.surface.create_entity { name = "flying-text", color = { b = 0.1, r = 1, g = 0, a = 0.8 }, text = (health), position = { player.position.x, player.position.y - 2 } }
end
end
end
end
end
end
end
Event.register(defines.events.on_tick, showhealth)