XWALK and XRUN commands to control NPC movement
Posted: Fri May 26, 2023 8:09 pm
Just a quick an dirty set of custom GM commands to make controlling NPCs a bit easier:
'xwalk will cause a targeted NPC to walk to a targeted location
'xrun will cause a targeted NPC to run to a targeted location
Each time a location is targeted for either command, another cursor immediately pops up requesting another location - that way one can keep moving the same NPC without having to re-issue the command over and over.
To use, save the below script as 'xmove.js' in your UOX3/js/commands/custom/ folder, then assign the script a unique ID in the [COMMAND_SCRIPTS] section of UOX3/js/jse_fileassocations.scp. Example:
'xwalk will cause a targeted NPC to walk to a targeted location
'xrun will cause a targeted NPC to run to a targeted location
Each time a location is targeted for either command, another cursor immediately pops up requesting another location - that way one can keep moving the same NPC without having to re-issue the command over and over.
To use, save the below script as 'xmove.js' in your UOX3/js/commands/custom/ folder, then assign the script a unique ID in the [COMMAND_SCRIPTS] section of UOX3/js/jse_fileassocations.scp. Example:
Reload javascript engine/restart UOX3, and start controlling those NPCs![COMMAND_SCRIPTS]
{
...
1100=commands/custom/xmove.js
}
// Remote Movement Commands!
// 21/03/2021 - by Xuri
//
// Use 'XWALK <target> <target-location> to make the targeted character walk to targeted location
// Use 'XRUN <target> <target-location> to make the targeted character run to targeted location
function CommandRegistration()
{
RegisterCommand( "xwalk", 2, true );
RegisterCommand( "xrun", 2, true );
RegisterCommand( "xturn", 2, true );
}
function command_XWALK( socket, cmdString )
{
var pUser = socket.currentChar;
socket.xText = "walk";
pUser.CustomTarget( 0, "Target character for xwalk:" );
}
function command_XRUN( socket, cmdString )
{
var pUser = socket.currentChar;
socket.xText = "run";
pUser.CustomTarget( 0, "Target character for xrun:" );
}
function command_XTURN( socket, cmdString )
{
var pUser = socket.currentChar;
socket.xText = "turn";
pUser.CustomTarget( 0, "Target character for xturn:" );
}
function onCallback0( socket, myTarget )
{
var pUser = socket.currentChar;
if( !socket.GetWord( 1 ) && ValidateObject( myTarget ) && myTarget.isChar )
{
socket.tempObj = myTarget;
pUser.CustomTarget( 1, "Select target location:" );
}
else
{
pUser.SysMessage( "You must target a character!" );
}
}
function onCallback1( socket, myTarget )
{
// If user cancels targeting with Escape, ClassicUO still sends a targeting response (unlike
// regular UO client), but one byte in the packet is always 255 when this happens
var cancelCheck = parseInt( socket.GetByte( 11 ));
if( cancelCheck != 255 )
{
var pUser = socket.currentChar;
var StrangeByte = socket.GetWord( 1 );
var targetChar = socket.tempObj;
var targX = socket.GetWord( 11 );
var targY = socket.GetWord( 13 );
if( ValidateObject( targetChar ))
{
var walkType = socket.xText;
if( walkType == "walk" )
{
targetChar.WalkTo( targX, targY, 15 );
}
else if( walkType == "run" )
{
targetChar.RunTo( targX, targY, 15 );
}
else if( walkType == "turn" )
{
targetChar.TurnToward( targX, targY );
}
pUser.CustomTarget( 1, "Select target location:" );
}
}
else
{
// User cancelled target cursor
socket.xText = "";
socket.tempObj = null;
}
}
// 21/03/2021 - by Xuri
//
// Use 'XWALK <target> <target-location> to make the targeted character walk to targeted location
// Use 'XRUN <target> <target-location> to make the targeted character run to targeted location
function CommandRegistration()
{
RegisterCommand( "xwalk", 2, true );
RegisterCommand( "xrun", 2, true );
RegisterCommand( "xturn", 2, true );
}
function command_XWALK( socket, cmdString )
{
var pUser = socket.currentChar;
socket.xText = "walk";
pUser.CustomTarget( 0, "Target character for xwalk:" );
}
function command_XRUN( socket, cmdString )
{
var pUser = socket.currentChar;
socket.xText = "run";
pUser.CustomTarget( 0, "Target character for xrun:" );
}
function command_XTURN( socket, cmdString )
{
var pUser = socket.currentChar;
socket.xText = "turn";
pUser.CustomTarget( 0, "Target character for xturn:" );
}
function onCallback0( socket, myTarget )
{
var pUser = socket.currentChar;
if( !socket.GetWord( 1 ) && ValidateObject( myTarget ) && myTarget.isChar )
{
socket.tempObj = myTarget;
pUser.CustomTarget( 1, "Select target location:" );
}
else
{
pUser.SysMessage( "You must target a character!" );
}
}
function onCallback1( socket, myTarget )
{
// If user cancels targeting with Escape, ClassicUO still sends a targeting response (unlike
// regular UO client), but one byte in the packet is always 255 when this happens
var cancelCheck = parseInt( socket.GetByte( 11 ));
if( cancelCheck != 255 )
{
var pUser = socket.currentChar;
var StrangeByte = socket.GetWord( 1 );
var targetChar = socket.tempObj;
var targX = socket.GetWord( 11 );
var targY = socket.GetWord( 13 );
if( ValidateObject( targetChar ))
{
var walkType = socket.xText;
if( walkType == "walk" )
{
targetChar.WalkTo( targX, targY, 15 );
}
else if( walkType == "run" )
{
targetChar.RunTo( targX, targY, 15 );
}
else if( walkType == "turn" )
{
targetChar.TurnToward( targX, targY );
}
pUser.CustomTarget( 1, "Select target location:" );
}
}
else
{
// User cancelled target cursor
socket.xText = "";
socket.tempObj = null;
}
}