landsandboat/scripts/commands/setplayerlevel.lua

51 lines
1.2 KiB
Lua
Raw Permalink Normal View History

-----------------------------------
-- func: setplayerlevel
2016-01-16 01:26:33 -05:00
-- desc: Sets the target players level.
-----------------------------------
---@type TCommand
local commandObj = {}
2016-01-16 01:26:33 -05:00
commandObj.cmdprops =
2016-01-16 01:26:33 -05:00
{
permission = 1,
parameters = 'ss'
}
2016-01-16 01:26:33 -05:00
local function error(player, msg)
player:printToPlayer(msg)
player:printToPlayer('!setplayerlevel (player) <level>')
end
commandObj.onTrigger = function(player, arg1, arg2)
local targ
local level
-- validate target
if arg2 ~= nil then
targ = GetPlayerByName(arg1)
if targ == nil then
error(player, string.format('Player named "%s" not found!', arg1))
return
end
level = tonumber(arg2)
elseif arg1 ~= nil then
targ = player
level = tonumber(arg1)
2016-01-16 01:26:33 -05:00
end
-- validate level
if level == nil or level < 1 or level > 99 then
error(player, 'Invalid level. Must be between 1 and 99.')
return
2016-01-16 01:26:33 -05:00
end
-- set level
targ:setLevel(level)
if targ:getID() ~= player:getID() then
player:printToPlayer(string.format('Set %s\'s level to %i.', targ:getName(), level))
2016-01-16 01:26:33 -05:00
end
end
return commandObj