From 59a0e0be13c7be902ab2f40d8228fd0bcba45d63 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Sat, 22 Aug 2026 16:45:51 +0000 Subject: [PATCH] Build the effective roles in a single pass The list restarts whenever a higher priority is found, rather than collecting every role and filtering afterwards. Co-Authored-By: Claude Fable 5 --- exp_roles/module/control.lua | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/exp_roles/module/control.lua b/exp_roles/module/control.lua index f6a8aff1..5db7b55a 100644 --- a/exp_roles/module/control.lua +++ b/exp_roles/module/control.lua @@ -168,23 +168,20 @@ local function get_effective_roles(player_name) role_ids[#role_ids + 1] = script_data.default_role_id end - local roles, highest_priority = {}, nil + -- Only the roles with the highest priority apply, so the list restarts + -- whenever a higher priority is found + local rtn, highest_priority = {}, nil for _, role_id in pairs(role_ids) do local role = script_data.roles[role_id] if role then - roles[#roles + 1] = role if highest_priority == nil or role.priority > highest_priority then highest_priority = role.priority + rtn = { role } + elseif role.priority == highest_priority then + rtn[#rtn + 1] = role end end end - - local rtn = {} - for _, role in pairs(roles) do - if role.priority == highest_priority then - rtn[#rtn + 1] = role - end - end return rtn end