landsandboat/scripts/commands/packetmod.lua
claywar 55de6a5440
Fix issues reported in command scripts
Additional nil checks
2024-08-25 12:01:53 -04:00

43 lines
1.1 KiB
Lua

-----------------------------------
-- func: packetmod
-- desc: Adds a modifier for S->C packets
-----------------------------------
---@type TCommand
local commandObj = {}
commandObj.cmdprops =
{
permission = 5,
parameters = 'ssss'
}
local function error(player, msg)
player:printToPlayer(msg
.. '\n!packetmod (operation) (packet id) (offset) (value)'
.. '\nOperations: add / del / clear / print')
end
commandObj.onTrigger = function(player, operation, packetId, offset, value)
if
operation == nil or
operation == '' or
tonumber(operation) ~= nil
then
error(player, 'Usage:')
return
end
if operation == 'add' then
-- TODO: Find the best way to handle number->int conversion
---@diagnostic disable-next-line param-type-mismatch
player:addPacketMod(tonumber(packetId), tonumber(offset), tonumber(value))
elseif operation == 'del' then
-- TODO
elseif operation == 'clear' then
player:clearPacketMods()
else
-- TODO: Print list of mods
end
end
return commandObj