landsandboat/scripts/commands/pos.lua
sruon 495ccff91c Enable ximesh files support
Co-Authored-By: InoUno <774909+InoUno@users.noreply.github.com>
Co-Authored-By: atom0s <atom0s@users.noreply.github.com>
Co-Authored-By: Mike Murphy <6765305+xenonsmurf@users.noreply.github.com>
2026-03-31 20:16:57 -06:00

129 lines
3.5 KiB
Lua

-----------------------------------
-- func: pos <x> <y> <z> <optional zone> <optional target>
-- desc: Sets the players position. If none is given, prints out the position instead.
-----------------------------------
---@type TCommand
local commandObj = {}
commandObj.cmdprops =
{
permission = 1,
parameters = 's',
}
local terrainNames =
{
[xi.terrain.OBJECT] = 'Object',
[xi.terrain.PATH] = 'Path',
[xi.terrain.GRASS] = 'Grass',
[xi.terrain.SAND] = 'Sand',
[xi.terrain.SNOW] = 'Snow',
[xi.terrain.STONE] = 'Stone',
[xi.terrain.METAL] = 'Metal',
[xi.terrain.WOOD] = 'Wood',
[xi.terrain.SHALLOW_WATER] = 'Shallow Water',
[xi.terrain.DEEP_WATER] = 'Deep Water',
[xi.terrain.UNKNOWN] = 'Unknown',
[xi.terrain.NONE] = 'None',
}
local function error(player, msg)
player:printToPlayer(msg)
player:printToPlayer('!pos (x) (y) (z) (zone ID) (player)')
end
local function printPosition(player, targ)
local zone = targ:getZone()
local pos = targ:getPos()
local terrainType = zone:getTerrainType(pos)
local terrainName = terrainNames[terrainType] or string.format('Unknown (%d)', terrainType)
player:printToPlayer(string.format('%s: X %.4f Y %.4f Z %.4f Rot %i Zone %i Floor %i Terrain: %s',
targ:getName(),
targ:getXPos(),
targ:getYPos(),
targ:getZPos(),
targ:getRotPos(),
targ:getZoneID(),
zone:getFloorId(pos),
terrainName
), xi.msg.channel.SYSTEM_3)
end
commandObj.onTrigger = function(player, arg)
local target
local zoneId
local x
local y
local z
local targ
if arg == nil then
printPosition(player, player)
return
end
local args = utils.splitArg(arg)
-- shift arguments depending on number passed
if args[5] ~= nil then
x = tonumber(args[1])
y = tonumber(args[2])
z = tonumber(args[3])
zoneId = tonumber(args[4])
target = args[5]
elseif args[4] ~= nil then
x = tonumber(args[1])
y = tonumber(args[2])
z = tonumber(args[3])
if GetPlayerByName(args[4]) == nil then
zoneId = args[4]
else
target = args[4]
end
elseif args[3] ~= nil then
x = tonumber(args[1])
y = tonumber(args[2])
z = tonumber(args[3])
elseif args[1] ~= nil then
target = args[1]
end
-- validate target
if target == nil then
targ = player
else
targ = GetPlayerByName(target)
if targ == nil then
error(player, string.format('Player named "%s" not found!', target))
return
end
end
-- validate zone
if zoneId ~= nil then
zoneId = tonumber(zoneId)
if zoneId == nil or zoneId < 0 or zoneId > 298 then
error(player, 'Invalid zone ID.')
return
end
end
-- report or move position
if x == nil or y == nil or z == nil then
printPosition(player, targ)
else
if zoneId == nil then
zoneId = targ:getZoneID()
targ:setPos(x, y, z, 0)
else
targ:setPos(x, y, z, 0, zoneId)
end
if player:getID() ~= targ:getID() then
player:printToPlayer(string.format('Moved %s to (%.4f, %.4f, %.4f) in zone %i.', targ:getName(), x, y, z, targ:getZoneID()), xi.msg.channel.SYSTEM_3)
end
end
end
return commandObj