From b53ced4e75701218310f5dd09e83375b622f75a6 Mon Sep 17 00:00:00 2001 From: Lucy Date: Wed, 22 Jan 2025 19:46:14 -0500 Subject: [PATCH] Add a SS13.check_tick lua function (#89081) ## About The Pull Request This adds a new function for Lua scripts: `SS13.check_tick()` - it acts pretty much exactly like the `CHECK_TICK` macro in DM. It accepts a single argument, a boolean, which if true - it will act like `CHECK_TICK_HIGH_PRIORITY` instead. ## Why It's Good For The Game this function is a repeated code pattern in lua scripts, so having it in the SS13 lua library is useful. ## Changelog :cl: admin: Added a new function in Lua scripting, SS13.check_tick, to avoid causing too much lag during loops and such. /:cl: --- lua/SS13_base.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/SS13_base.lua b/lua/SS13_base.lua index 23f464bf328..470288af87e 100644 --- a/lua/SS13_base.lua +++ b/lua/SS13_base.lua @@ -39,6 +39,13 @@ function SS13.is_valid(datum) return dm.is_valid_ref(datum) and not datum.gc_destroyed end +function SS13.check_tick(high_priority) + local tick_limit = if high_priority then 95 else dm.global_vars.Master.current_ticklimit + if dm.world.tick_usage > tick_limit then + sleep() + end +end + function SS13.await(thing_to_call, proc_to_call, ...) if not SS13.istype(thing_to_call, "/datum") then thing_to_call = SS13.global_proc