From 9a17550b74414d541f35b4777013fc8ea6a59692 Mon Sep 17 00:00:00 2001
From: NullBite <me@nullbite.com>
Date: Wed, 22 Jun 2022 22:26:48 -0400
Subject: [PATCH] Register wrapper functions for ticks/render

Apparently dying breaks player entity checks, this fixes that. The
function will only run the tick/render if the player is alive.
---
 script.lua | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/script.lua b/script.lua
index 7f76ab8..46c8c0f 100644
--- a/script.lua
+++ b/script.lua
@@ -259,7 +259,7 @@ do
 		end
 	end
 
-	events.TICK:register(tick, "timer")
+	events.TICK:register(function() if player:exists() then tick() end end, "timer")
 end
 
 -- named timers (this one is mine but heavily based on the other) --
@@ -279,7 +279,7 @@ do
 			end
 		end
 	end
-	events.TICK:register(tick, "named_timer")
+	events.TICK:register(function() if player:exists() then tick() end end, "named_timer")
 end
 
 -- named cooldowns
@@ -299,7 +299,7 @@ do
 			end
 		end
 	end
-	events.TICK:register(tick, "cooldown")
+	events.TICK:register(function() if player:exists() then tick() end end, "cooldown")
 end
 
 function rateLimit(ticks, next, name)
@@ -1192,7 +1192,7 @@ function tick()
 	old_state.color_check=color_check
 	local_state.anim=player:getPose()
 end
-events.TICK:register(tick, "main_tick")
+events.TICK:register(function() if player:exists() then tick() end end, "main_tick")
 -- }}}
 
 -- Render function {{{
@@ -1207,5 +1207,6 @@ function render(delta)
 		animateTail((lerp(old_state.anim_cycle, anim_cycle, delta)))
 	end
 end
-events.RENDER:register(render, "main_render")
+-- TODO this may break animation during death
+events.RENDER:register(function(delta) if player:exists() then render(delta) end end, "main_render")
 -- }}}