Badgermilk

AzerothCore Party Fee for specified account prefixes

Aug 19th, 2025 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.03 KB | Gaming | 0 0
  1. -------------------------
  2. -- CONFIGURATION START --
  3. -------------------------
  4.  
  5. local INTERVAL = 900000
  6. local SPECIAL_ACCOUNT_PREFIXES = {"test", "dev", "RNDBOT"}
  7. local MIN_SPECIAL_ACCOUNTS = 2   -- minimum required special accounts to start charging
  8. local MAX_SPECIAL_ACCOUNTS = 4   -- maximum counted special account before reaching cost limit
  9. local CHARGE_COOLDOWN = 5000     -- minimum time between charges per player (ms)
  10.  
  11. local LEVEL_FEES = {
  12.     {min = 1,  max = 14,  cost = 10}, -- 10 copper per hour
  13.     {min = 15, max = 19,  cost = 1250}, -- 50 silver per hour
  14.     {min = 20, max = 24,  cost = 2500}, -- 1 gold per hour
  15.     {min = 25, max = 29,  cost = 2500}, -- 1 gold per hour
  16.     {min = 30, max = 34,  cost = 3125}, -- 1.25 gold per hour
  17.     {min = 35, max = 39,  cost = 3125}, -- 1.25 gold per hour
  18.     {min = 40, max = 44,  cost = 3750}, -- 1.5 gold per hour
  19.     {min = 45, max = 50,  cost = 3750}, -- 1.5 gold per hour
  20.     {min = 51, max = 54,  cost = 4375}, -- 1.75 gold per hour
  21.     {min = 55, max = 59,  cost = 5000}, -- 2 gold per hour
  22.     {min = 60, max = 60,  cost = 6250}, -- 2.5 gold per hour
  23.     {min = 61, max = 63,  cost = 12500}, -- 5 gold per hour
  24.     {min = 64, max = 66,  cost = 12500}, -- 5 gold per hour
  25.     {min = 67, max = 69,  cost = 18750}, -- 7.5 gold per hour
  26.     {min = 70, max = 70,  cost = 25000}, -- 10 gold per hour
  27.     {min = 71, max = 73,  cost = 31250}, -- 12.5 gold per hour
  28.     {min = 74, max = 76,  cost = 31250}, -- 12.5 gold per hour
  29.     {min = 77, max = 79,  cost = 33750}, -- 13.5 gold per hour
  30.     {min = 80, max = 80,  cost = 37500}, -- 15 gold per hour
  31. }
  32.  
  33. -----------------------
  34. -- CONFIGURATION END --
  35. -----------------------
  36.  
  37. -- table to track last charge timestamps
  38. local lastChargeTime = {}
  39.  
  40. local function GetAccName(player)
  41.     return player:GetAccountName()
  42. end
  43.  
  44. local function GetFeeForLevel(level)
  45.     for _, bracket in ipairs(LEVEL_FEES) do
  46.         if level >= bracket.min and level <= bracket.max then
  47.             return bracket.cost
  48.         end
  49.     end
  50.     return 0
  51. end
  52.  
  53. local function IsSpecialAccount(accName)
  54.     if not accName then return false end
  55.     local lowerName = string.lower(accName)
  56.     for _, prefix in ipairs(SPECIAL_ACCOUNT_PREFIXES) do
  57.         if string.sub(lowerName, 1, #prefix) == string.lower(prefix) then
  58.             return true
  59.         end
  60.     end
  61.     return false
  62. end
  63.  
  64. local function CountSpecialAccounts(group)
  65.     local count = 0
  66.     if not group then return count end
  67.     for _, member in pairs(group:GetMembers()) do
  68.         if IsSpecialAccount(GetAccName(member)) then
  69.             count = count + 1
  70.             if count >= MAX_SPECIAL_ACCOUNTS then
  71.                 return MAX_SPECIAL_ACCOUNTS
  72.             end
  73.         end
  74.     end
  75.     return count
  76. end
  77.  
  78. local function FormatMoneyColored(copper)
  79.     local gold = math.floor(copper / 10000)
  80.     local silver = math.floor((copper % 10000) / 100)
  81.     local copperLeft = copper % 100
  82.     local parts = {}
  83.     if gold > 0 then table.insert(parts, "|cFFFFD700"..gold.."g|r") end
  84.     if silver > 0 then table.insert(parts, "|cFFC0C0C0"..silver.."s|r") end
  85.     if copperLeft > 0 or #parts == 0 then table.insert(parts, "|cFFB87333"..copperLeft.."c|r") end
  86.     return table.concat(parts, " ")
  87. end
  88.  
  89. local function ChargeGroupMembers(group)
  90.     if not group then return end
  91.     local specialCount = CountSpecialAccounts(group)
  92.    
  93.     if specialCount < MIN_SPECIAL_ACCOUNTS then return end
  94.  
  95.     for _, member in pairs(group:GetMembers()) do
  96.         if not IsSpecialAccount(GetAccName(member)) then
  97.             local now = os.time() * 1000
  98.             if lastChargeTime[member:GetGUID()] and now - lastChargeTime[member:GetGUID()] < CHARGE_COOLDOWN then
  99.                 goto continue
  100.             end
  101.  
  102.             local baseCost = GetFeeForLevel(member:GetLevel())
  103.             local totalCost = baseCost * specialCount
  104.  
  105.             if totalCost > 0 then
  106.                 if member:GetCoinage() >= totalCost then
  107.                     member:ModifyMoney(-totalCost)
  108.                     member:SendBroadcastMessage(string.format(
  109.                         "%s has been collected for grouping with %d special account(s).",
  110.                         FormatMoneyColored(totalCost), specialCount
  111.                     ))
  112.                 else
  113.                     member:SendBroadcastMessage("You do not have enough money for the special group fee. You are being removed from the group.")
  114.                     group:RemoveMember(member:GetGUID())  -- fixed
  115.                 end
  116.             end
  117.  
  118.             lastChargeTime[member:GetGUID()] = now
  119.         end
  120.         ::continue::
  121.     end
  122. end
  123.  
  124. local function PeriodicCheck(eventId, delay, calls, data)
  125.     for _, player in pairs(GetPlayersInWorld()) do
  126.         local group = player:GetGroup()
  127.         if group and group:GetLeaderGUID() == player:GetGUID() then
  128.             ChargeGroupMembers(group)
  129.         end
  130.     end
  131. end
  132.  
  133. local function OnServerStart(event)
  134.     CreateLuaEvent(PeriodicCheck, INTERVAL, 0)
  135. end
  136.  
  137. RegisterServerEvent(33, OnServerStart)
  138.  
Advertisement
Add Comment
Please, Sign In to add comment