landsandboat/scripts/commands/mp.lua

57 lines
1.4 KiB
Lua
Raw Permalink Normal View History

-----------------------------------
-- func: mp <amount> <player>
2016-01-16 01:26:33 -05:00
-- desc: Sets the GM or target players mana.
-----------------------------------
---@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 = 'is'
}
2016-01-16 01:26:33 -05:00
local function error(player, msg)
player:printToPlayer(msg)
player:printToPlayer('!mp <amount> (player)')
end
commandObj.onTrigger = function(player, mp, target)
-- validate target
local targ
local cursorTarget = player:getCursorTarget()
if target then
targ = GetPlayerByName(target)
if not targ then
error(player, string.format('Player named "%s" not found!', target))
return
end
elseif cursorTarget and not cursorTarget:isNPC() then
targ = cursorTarget
else
targ = player
end
-- validate amount
if mp == nil or tonumber(mp) == nil then
error(player, 'You must provide an amount.')
return
elseif mp < 0 then
error(player, 'Invalid amount.')
return
end
-- set mp
if targ:isAlive() then
targ:setMP(mp)
if targ:getID() ~= player:getID() then
player:printToPlayer(string.format('Set %s\'s MP to %i.', targ:getName(), targ:getMP()))
2016-01-16 01:26:33 -05:00
end
else
player:printToPlayer(string.format('%s is currently dead.', targ:getName()))
2016-01-16 01:26:33 -05:00
end
end
return commandObj