local originalExpRate, originalSpawnRate, originalSkillRate, originalMagicRate, originalLootRate
function onSay(player, words, param)
if not player:getGroup():getAccess() then
return true
end
param = param:lower():gsub(",", " "):gsub("%s+", " ")
local setting, rate, duration = param:match("(%w+)%s+(%d+)%s*(%d*)")
rate = tonumber(rate)
duration = tonumber(duration)
if not setting or not rate then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Invalid parameter.")
return true
end
if not originalExpRate or not originalSpawnRate or not originalSkillRate or not originalMagicRate or not originalLootRate then
originalExpRate = configManager.getNumber(configKeys.RATE_EXPERIENCE)
originalSpawnRate = configManager.getNumber(configKeys.RATE_SPAWN)
originalSkillRate = configManager.getNumber(configKeys.RATE_SKILL)
originalMagicRate = configManager.getNumber(configKeys.RATE_MAGIC)
originalLootRate = configManager.getNumber(configKeys.RATE_LOOT)
end
if not originalExpRate or not originalSpawnRate or not originalSkillRate or not originalMagicRate or not originalLootRate then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Error: Could not read current rates from config.")
return true
end
local configFilePath = "config.lua"
local file = io.open(configFilePath, "r")
if not file then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Error: Could not open config.lua file.")
return true
end
local content = file:read("*all")
file:close()
local settingsMap = {
exp = {key = "rateExp", original = originalExpRate, message = "Experience"},
spawn = {key = "rateSpawn", original = originalSpawnRate, message = "Spawn"},
skill = {key = "rateSkill", original = originalSkillRate, message = "Skill"},
magic = {key = "rateMagic", original = originalMagicRate, message = "Magic"},
loot = {key = "rateLoot", original = originalLootRate, message = "Loot"}
}
local settingConfig = settingsMap[setting]
if not settingConfig then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Invalid parameter.")
return true
end
content = content:gsub(settingConfig.key .. " = %d+", settingConfig.key .. " = " .. rate)
local broadcastMessage = os.date("%H:%M") .. " An event has begun! " .. settingConfig.message .. " rate is now set to " .. rate .. "x"
if duration then
broadcastMessage = broadcastMessage .. " for " .. duration .. " minutes. Enjoy!"
else
broadcastMessage = broadcastMessage .. ". Enjoy!"
end
Game.broadcastMessage(broadcastMessage, MESSAGE_STATUS_WARNING)
file = io.open(configFilePath, "w")
if not file then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Error: Could not write to config.lua file.")
return true
end
file:write(content)
file:close()
Game.reload("config")
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Rates successfully changed. Configurations reloaded.")
if duration and duration > 0 then
addEvent(function()
local restoreContent = content
for key, config in pairs(settingsMap) do
restoreContent = restoreContent:gsub(config.key .. " = %d+", config.key .. " = " .. config.original)
end
local restoreFile = io.open(configFilePath, "w")
if not restoreFile then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Error: Could not write to config.lua file for restoration.")
return
end
restoreFile:write(restoreContent)
restoreFile:close()
Game.reload("config")
Game.broadcastMessage("The event has ended! Rates have been restored to their original values. Thank you for participating!", MESSAGE_STATUS_WARNING)
end, duration * 60 * 1000)
end
return true
end