Debuggers: Added the "/come" command to test mob pathfinding. (#3734)
This commit is contained in:
parent
a0341d561a
commit
226272fc63
@ -1576,6 +1576,56 @@ end
|
||||
|
||||
|
||||
|
||||
function HandleComeCmd(a_Split, a_Player)
|
||||
-- Find the first solid block under the player (in case they are flying):
|
||||
local playerWorld = a_Player:GetWorld()
|
||||
local playerPos = a_Player:GetPosition()
|
||||
local toPos = Vector3i(playerPos)
|
||||
if (toPos.y < 1) then
|
||||
a_Player:SendMessageFailure("Cannot navigate to you, you're too low in the world")
|
||||
return true
|
||||
end
|
||||
while not(cBlockInfo:IsSolid(playerWorld:GetBlock(toPos.x, toPos.y, toPos.z))) do
|
||||
if (toPos.y <= 0) then
|
||||
a_Player:SendMessageFailure("Cannot navigate to you, there's no solid block below you")
|
||||
return true
|
||||
end
|
||||
toPos.y = toPos.y - 1
|
||||
end
|
||||
|
||||
-- Find the mob to navigate:
|
||||
local mob
|
||||
local playerLook = a_Player:GetLookVector():NormalizeCopy()
|
||||
local maxDot = 0
|
||||
playerWorld:ForEachEntity(
|
||||
function (a_CBEntity)
|
||||
local dir = (a_CBEntity:GetPosition() - playerPos)
|
||||
dir:Normalize()
|
||||
local dot = dir:Dot(playerLook)
|
||||
if (dot > maxDot) then
|
||||
maxDot = dot
|
||||
mob = a_CBEntity
|
||||
end
|
||||
end
|
||||
)
|
||||
if not(mob) then
|
||||
a_Player:SendMessageFailure("Cannot navigate to you, there's no mob this way")
|
||||
return true
|
||||
end
|
||||
|
||||
mob:MoveToPosition(Vector3d(toPos))
|
||||
a_Player:SendMessageSuccess((
|
||||
string.format("Navigating the %s to position {%d, %d, %d}",
|
||||
cMonster:MobTypeToString(mob:GetMobType()), toPos.x, toPos.y, toPos.z
|
||||
)
|
||||
))
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleCompo(a_Split, a_Player)
|
||||
-- Send one composite message to self:
|
||||
local msg = cCompositeChat()
|
||||
|
@ -34,6 +34,12 @@ g_PluginInfo =
|
||||
Handler = HandleClientVersionCmd,
|
||||
HelpString = "Shows your client's protocol version",
|
||||
},
|
||||
["/come"] =
|
||||
{
|
||||
Permission = "debuggers.come",
|
||||
Handler = HandleComeCmd,
|
||||
HelpString = "Instruct the mob you're looking at to navigate to your position",
|
||||
},
|
||||
["/compo"] =
|
||||
{
|
||||
Permission = "debuggers",
|
||||
|
Loading…
Reference in New Issue
Block a user