To use this script, save it as xattack.js in UOX3\JS\COMMANDS\CUSTOM\, then open JSE_FILEASSOCIATIONS.SCP
and find the [COMMAND_SCRIPTS] sections. Scroll to the bottom of it, then add a line saying (for instance):
1051=commands/custom/xattack.js
(NOTE: Use a different (unique!) script-id if 1050 is already taken.)
// Remote NPC Attack
// v0.6
// by Xuri (xuri@uox3.org)
// Last Updated: 21/03/2021
// xattack lets GM characters command NPCs to attack other characters
// If the target being attacked is innocent (blue), the attacking NPC
// will become a criminal.
//
// endfight will take a targeted character and their immediate target out of combat,
// essentially ending the battle. This does not stop them from re-engaging after if they
// are hostile to each other, though!
function CommandRegistration()
{
RegisterCommand( "xattack", 2, true );
RegisterCommand( "endfight", 2, true );
}
function command_XATTACK( socket, cmdString )
{
socket.CustomTarget( 0, "Which NPC should attack someone?" );
}
function onCallback0( socket, myTarget )
{
if( !socket.GetWord( 1 ) && myTarget.isChar )
{
if( myTarget.npc )
{
socket.tempObj = myTarget;
socket.CustomTarget( 1, "Which character should the NPC attack?", 1 );
}
else
socket.SysMessage( "You can only order NPCs to attack." );
}
else
socket.SysMessage( "You must target a character." );
}
function onCallback1( socket, myTarget )
{
var myNPC = socket.tempObj;
if( !ValidateObject( myNPC ))
{
socket.SysMessage( "Invalid NPC attacker!" );
return;
}
if( !socket.GetWord( 1 ) && ValidateObject( myTarget ) && myTarget.isChar )
{
if( myTarget == myNPC )
{
socket.SysMessage( "You cannot order an NPC to attack themselves." );
return;
}
if( !myTarget.vulnerable )
{
socket.SysMessage( "You cannot order an NPC to attack an invulnerable target." );
return;
}
if( myNPC.InitiateCombat( myTarget ))
{
socket.SysMessage( "Combat successfully initiated." );
}
else
{
socket.SysMessage( "Failed to initiate combat between the two characters!" );
}
}
else
socket.SysMessage( "You must target a valid character." );
}
function command_ENDFIGHT( pSock, execString )
{
pSock.CustomTarget( 14, "Subdue which fight?" );
}
function onCallback14( pSock, myTarget )
{
var pUser = pSock.currentChar;
if( !pSock.GetWord( 1 ) && myTarget.isChar )
{
if( myTarget.atWar == true )
{
var opponent = myTarget.target;
opponent.target = null;
opponent.atWar = 0;
opponent.attacker = null;
myTarget.target = null;
myTarget.atWar = 0;
myTarget.attacker = null;
pUser.SysMessage( "Fight between the target character and their opponent has been subdued." );
}
else
pUser.SysMessage( "That character is not in a fight." );
}
else
{
pUser.SysMessage( "You must select a valid character!" );
}
}
// v0.6
// by Xuri (xuri@uox3.org)
// Last Updated: 21/03/2021
// xattack lets GM characters command NPCs to attack other characters
// If the target being attacked is innocent (blue), the attacking NPC
// will become a criminal.
//
// endfight will take a targeted character and their immediate target out of combat,
// essentially ending the battle. This does not stop them from re-engaging after if they
// are hostile to each other, though!
function CommandRegistration()
{
RegisterCommand( "xattack", 2, true );
RegisterCommand( "endfight", 2, true );
}
function command_XATTACK( socket, cmdString )
{
socket.CustomTarget( 0, "Which NPC should attack someone?" );
}
function onCallback0( socket, myTarget )
{
if( !socket.GetWord( 1 ) && myTarget.isChar )
{
if( myTarget.npc )
{
socket.tempObj = myTarget;
socket.CustomTarget( 1, "Which character should the NPC attack?", 1 );
}
else
socket.SysMessage( "You can only order NPCs to attack." );
}
else
socket.SysMessage( "You must target a character." );
}
function onCallback1( socket, myTarget )
{
var myNPC = socket.tempObj;
if( !ValidateObject( myNPC ))
{
socket.SysMessage( "Invalid NPC attacker!" );
return;
}
if( !socket.GetWord( 1 ) && ValidateObject( myTarget ) && myTarget.isChar )
{
if( myTarget == myNPC )
{
socket.SysMessage( "You cannot order an NPC to attack themselves." );
return;
}
if( !myTarget.vulnerable )
{
socket.SysMessage( "You cannot order an NPC to attack an invulnerable target." );
return;
}
if( myNPC.InitiateCombat( myTarget ))
{
socket.SysMessage( "Combat successfully initiated." );
}
else
{
socket.SysMessage( "Failed to initiate combat between the two characters!" );
}
}
else
socket.SysMessage( "You must target a valid character." );
}
function command_ENDFIGHT( pSock, execString )
{
pSock.CustomTarget( 14, "Subdue which fight?" );
}
function onCallback14( pSock, myTarget )
{
var pUser = pSock.currentChar;
if( !pSock.GetWord( 1 ) && myTarget.isChar )
{
if( myTarget.atWar == true )
{
var opponent = myTarget.target;
opponent.target = null;
opponent.atWar = 0;
opponent.attacker = null;
myTarget.target = null;
myTarget.atWar = 0;
myTarget.attacker = null;
pUser.SysMessage( "Fight between the target character and their opponent has been subdued." );
}
else
pUser.SysMessage( "That character is not in a fight." );
}
else
{
pUser.SysMessage( "You must select a valid character!" );
}
}