random_snippets/snippet_canary.lua

36 lines
1.2 KiB
Lua

whosit = _G.whosit or {}
_G.whosit = whosit
local t = "farming_tomato.png"
whosit.counter = whosit.counter or 0
core.register_entity(
":canary",
{
initial_properties = {
visual = "cube",
textures = {t,t,t,t,t,t},
use_texture_alpha = true,
hp_max = 1,
physical = true,
static_save = true,
},
on_activate = function(self, s, d)
whosit.counter = (whosit.counter or 0) + 1
self.__id = whosit.counter
core.chat_send_all(string.format("canary %s activated", self.__id))
self.lifetime = 0
end,
on_step = function(self, dtime, movres)
self.timer = self.timer or 0
self.lifetime = (self.lifetime or 0) + dtime
if self.timer > 30 then
core.chat_send_all(string.format("canary %s chirp %s", self.__id, self.lifetime))
self.timer = 0
end
self.timer = self.timer + dtime
end,
on_deactivate = function(self, removal)
core.chat_send_all(string.format("canary %s deactivated %s", self.__id, self.lifetime))
end
}
)