Skip to content

Commit

Permalink
add GM command to ban or unban players from using /yell
Browse files Browse the repository at this point in the history
  • Loading branch information
Tal Ben-Eliezer committed May 16, 2024
1 parent bbdffc8 commit d598014
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
56 changes: 56 additions & 0 deletions scripts/commands/yell.lua
Original file line number Diff line number Diff line change
@@ -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 <ban/unban> (player) <days>')
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
7 changes: 6 additions & 1 deletion src/map/packet_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16>("map.YELL_COOLDOWN") * 1000;
int8 packetData[4]{};
Expand Down

0 comments on commit d598014

Please sign in to comment.