From d5980144f6054ab74e8e4914715f8433048767dd Mon Sep 17 00:00:00 2001 From: Tal Ben-Eliezer Date: Mon, 13 May 2024 20:55:36 -0400 Subject: [PATCH] add GM command to ban or unban players from using /yell --- scripts/commands/yell.lua | 56 +++++++++++++++++++++++++++++++++++++++ src/map/packet_system.cpp | 7 ++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 scripts/commands/yell.lua diff --git a/scripts/commands/yell.lua b/scripts/commands/yell.lua new file mode 100644 index 00000000000..b702a15b296 --- /dev/null +++ b/scripts/commands/yell.lua @@ -0,0 +1,56 @@ +----------------------------------- +-- func: yell +-- desc: Bans a specified player from using /yell. +----------------------------------- +local commandObj = {} + +commandObj.cmdprops = +{ + permission = 1, + parameters = 'ssi' +} + +local function error(player, msg) + player:printToPlayer(msg) + player:printToPlayer('!yell (player) ') +end + +commandObj.onTrigger = function(player, value, target, days) + -- validate value + if + value ~= 'ban' or + value ~= 'unban' + then + error(player) + return + end + + -- validate target + target = GetPlayerByName(target) + if target == nil then + error(player, 'Invalid target specified') + return + end + + if value == 'unban' then + target:setCharVar('[YELL]Banned', 0) + player:printToPlayer(string.format('%s has been unbanned from using the /yell command.', target:getName())) + elseif value == 'ban' then + -- validate duration + if + days == nil or + days < 1 + then + -- indefinite ban + error(player, 'Invalid duration specified, defaulting to indefinite ban.') + days = 0 + end + + target:setCharVar('[YELL]Banned', 1, os.time() + utils.days(days)) + player:printToPlayer(string.format('%s has been banned from using the /yell command.', target:getName())) + else + error(player, 'Invalid value specified.') + end +end + +return commandObj diff --git a/src/map/packet_system.cpp b/src/map/packet_system.cpp index 0ee6cc9ce52..1367bc6badc 100644 --- a/src/map/packet_system.cpp +++ b/src/map/packet_system.cpp @@ -5668,7 +5668,12 @@ void SmallPacket0x0B5(map_session_data_t* const PSession, CCharEntity* const PCh { if (PChar->loc.zone->CanUseMisc(MISC_YELL)) { - if (gettick() >= PChar->m_LastYell) + int yellBanned = PChar->getCharVar("[YELL]Banned"); + if (yellBanned == 1) + { + PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, 0, 0, MSGBASIC_CANNOT_USE_IN_AREA)); + } + else if (gettick() >= PChar->m_LastYell) { PChar->m_LastYell = gettick() + settings::get("map.YELL_COOLDOWN") * 1000; int8 packetData[4]{};