Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------
- -- CONFIGURATION START --
- -------------------------
- local INTERVAL = 900000
- local SPECIAL_ACCOUNT_PREFIXES = {"test", "dev", "RNDBOT"}
- local MIN_SPECIAL_ACCOUNTS = 2 -- minimum required special accounts to start charging
- local MAX_SPECIAL_ACCOUNTS = 4 -- maximum counted special account before reaching cost limit
- local CHARGE_COOLDOWN = 5000 -- minimum time between charges per player (ms)
- local LEVEL_FEES = {
- {min = 1, max = 14, cost = 10}, -- 10 copper per hour
- {min = 15, max = 19, cost = 1250}, -- 50 silver per hour
- {min = 20, max = 24, cost = 2500}, -- 1 gold per hour
- {min = 25, max = 29, cost = 2500}, -- 1 gold per hour
- {min = 30, max = 34, cost = 3125}, -- 1.25 gold per hour
- {min = 35, max = 39, cost = 3125}, -- 1.25 gold per hour
- {min = 40, max = 44, cost = 3750}, -- 1.5 gold per hour
- {min = 45, max = 50, cost = 3750}, -- 1.5 gold per hour
- {min = 51, max = 54, cost = 4375}, -- 1.75 gold per hour
- {min = 55, max = 59, cost = 5000}, -- 2 gold per hour
- {min = 60, max = 60, cost = 6250}, -- 2.5 gold per hour
- {min = 61, max = 63, cost = 12500}, -- 5 gold per hour
- {min = 64, max = 66, cost = 12500}, -- 5 gold per hour
- {min = 67, max = 69, cost = 18750}, -- 7.5 gold per hour
- {min = 70, max = 70, cost = 25000}, -- 10 gold per hour
- {min = 71, max = 73, cost = 31250}, -- 12.5 gold per hour
- {min = 74, max = 76, cost = 31250}, -- 12.5 gold per hour
- {min = 77, max = 79, cost = 33750}, -- 13.5 gold per hour
- {min = 80, max = 80, cost = 37500}, -- 15 gold per hour
- }
- -----------------------
- -- CONFIGURATION END --
- -----------------------
- -- table to track last charge timestamps
- local lastChargeTime = {}
- local function GetAccName(player)
- return player:GetAccountName()
- end
- local function GetFeeForLevel(level)
- for _, bracket in ipairs(LEVEL_FEES) do
- if level >= bracket.min and level <= bracket.max then
- return bracket.cost
- end
- end
- return 0
- end
- local function IsSpecialAccount(accName)
- if not accName then return false end
- local lowerName = string.lower(accName)
- for _, prefix in ipairs(SPECIAL_ACCOUNT_PREFIXES) do
- if string.sub(lowerName, 1, #prefix) == string.lower(prefix) then
- return true
- end
- end
- return false
- end
- local function CountSpecialAccounts(group)
- local count = 0
- if not group then return count end
- for _, member in pairs(group:GetMembers()) do
- if IsSpecialAccount(GetAccName(member)) then
- count = count + 1
- if count >= MAX_SPECIAL_ACCOUNTS then
- return MAX_SPECIAL_ACCOUNTS
- end
- end
- end
- return count
- end
- local function FormatMoneyColored(copper)
- local gold = math.floor(copper / 10000)
- local silver = math.floor((copper % 10000) / 100)
- local copperLeft = copper % 100
- local parts = {}
- if gold > 0 then table.insert(parts, "|cFFFFD700"..gold.."g|r") end
- if silver > 0 then table.insert(parts, "|cFFC0C0C0"..silver.."s|r") end
- if copperLeft > 0 or #parts == 0 then table.insert(parts, "|cFFB87333"..copperLeft.."c|r") end
- return table.concat(parts, " ")
- end
- local function ChargeGroupMembers(group)
- if not group then return end
- local specialCount = CountSpecialAccounts(group)
- if specialCount < MIN_SPECIAL_ACCOUNTS then return end
- for _, member in pairs(group:GetMembers()) do
- if not IsSpecialAccount(GetAccName(member)) then
- local now = os.time() * 1000
- if lastChargeTime[member:GetGUID()] and now - lastChargeTime[member:GetGUID()] < CHARGE_COOLDOWN then
- goto continue
- end
- local baseCost = GetFeeForLevel(member:GetLevel())
- local totalCost = baseCost * specialCount
- if totalCost > 0 then
- if member:GetCoinage() >= totalCost then
- member:ModifyMoney(-totalCost)
- member:SendBroadcastMessage(string.format(
- "%s has been collected for grouping with %d special account(s).",
- FormatMoneyColored(totalCost), specialCount
- ))
- else
- member:SendBroadcastMessage("You do not have enough money for the special group fee. You are being removed from the group.")
- group:RemoveMember(member:GetGUID()) -- fixed
- end
- end
- lastChargeTime[member:GetGUID()] = now
- end
- ::continue::
- end
- end
- local function PeriodicCheck(eventId, delay, calls, data)
- for _, player in pairs(GetPlayersInWorld()) do
- local group = player:GetGroup()
- if group and group:GetLeaderGUID() == player:GetGUID() then
- ChargeGroupMembers(group)
- end
- end
- end
- local function OnServerStart(event)
- CreateLuaEvent(PeriodicCheck, INTERVAL, 0)
- end
- RegisterServerEvent(33, OnServerStart)
Advertisement
Add Comment
Please, Sign In to add comment