[APPROVED] Repeating Commands (v1.06 - December 23rd 2005)

Want to contribute to the Ultima Offline eXperiment? Submit your JS/DFN/Code fixes and/or other UOX3 improvements here!
Locked
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Repeating Commands (v1.06 - December 23rd 2005)

Post by Xuri »

This script takes advantage of a recent feature-addition in UOX3 which allows one to easily add custom commands. You'll need version 0.98.1 or newer (currently only available in the CVS).

These custom commands are repeated over and over again until you cancel the targeting cursor, so if you do 'RADD 0x04a9 and target the ground, a floor tile is added - before you get another targeting cursor allowing you to add another floor tile. And another. And another. etc.

To set the script up, you need to do the following steps:

1) Open JSE_FILEASSOCIATIONS.SCP and scroll to the very bottom. Add the following lines after the last } bracket, but before the EOS line(if that section is already present, just add the SCRIPT= line):
[COMMAND_SCRIPTS]
{
SCRIPT=command/repeatingcmds.js
}
2) Create a new sub-folder in the JS folder, called COMMAND. Copy the script listed below, and paste it into an empty text file (in notepad?) which you then save as repeatingcmds.js in the UOX3\JS\COMMAND folder. Make sure the file-extension is ".js" and not ".txt" or ".js.txt"

3) Login, and use either of these commands at your pleasure:
'RINCX <value> // increase X value of target(s) by <value>
'RINCY <value> // increase Y value of target(s) by <value>
'RINCZ <value> // increase Z value of target(s) by <value>
'RTYPE <type> // Set targeted item(s) to TYPE <type>
'RDYE <hex-id> // Dye target(s) with the colour <hex-id>
'RADD <hex-id> //Add item <hex-id> at target location(s).
'RREMOVE <target> //Remove targeted item(s).
'RRADDITEM <item-id from DFNs> - Add scripted item at target loc
'RTELE <target location> - Teleport to multiple target locations
'RADDNPC <id from DFNs> - Add specified NPC at multiple target locations.
// Repeating Commands || by Xuri (xuri at sensewave.com)
// v1.07
// Last updated: December 23rd 2005
//
// This script contains commands which will make worldbuilding and constructing buildings ingame easier for the GMs.
// Any of the commands will, when used, be repeated over and over again after a target has been selected, so there will
// be no need for the user to repeatedly enter the same command.

ReqNum = "You need to enter a numerical value with this command!";

function CommandRegistration()
{
    RegisterCommand( "rincx", 2, true ); // USE 'RINCX <value> - increases X value of multiple targets by <value>
    RegisterCommand( "rincy", 2, true ); // USE 'RINCY <value> - increases Y value of multiple targets by <value>
    RegisterCommand( "rincz", 2, true ); // Use 'RINCZ <value> - increases Z value of multiple targets by <value>
    RegisterCommand( "rtype", 2, true ); // Use 'RTYPE <type> - sets multiple targeted objects to TYPE <type>
    RegisterCommand( "rdye", 2, true ); // Use 'RDYE <hex-id> - dyes multiple targeted objects with colour <hex-id>
    RegisterCommand( "radd", 2, true ); // Use 'RADD <hex-id> - adds item <hex-id> at multiple targeted locations
    RegisterCommand( "rremove", 2, true ); // Use 'RREMOVE - Removes multiple targeted items.
    RegisterCommand( "radditem", 2, true ); // Use 'RADDITEM <item-id from dfns>
    RegisterCommand( "rtele", 2, true ); //Use 'RTELE <target teleport location>
    RegisterCommand( "raddnpc", 2, true ); //Use 'RADDNPC <id from DFNs> - Adds specified NPC at multiple targeted locations
}

//Repeated Command: INCX <value>
function command_RINCX( pSock, execString )
{
    var pUser = pSock.currentChar;
    if( !isNaN(execString))
    {
        pSock.xText = execString;
        pUser.CustomTarget( 0, "Select target to reposition by "+execString+" X:" );
    }
    else
        pUser.SysMessage( ReqNum );
}
function onCallback0( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var incXValue = pSock.xText;
    var incXValue = Number(incXValue);
    var StrangeByte = pSock.GetWord( 1 );
    if( StrangeByte == 0 )
    {
            myTarget.x+= incXValue;
    }
    pUser.CustomTarget( 0, "Select target to reposition by "+incXValue+" X:" );
}

//Repeated Command: INCY <value>
function command_RINCY( pSock, execString )
{
    pUser = pSock.currentChar;
    if( !isNaN(execString))
    {
        pSock.xText = execString;
        pUser.CustomTarget( 1, "Select target to reposition by "+execString+" Y:" );
    }
    else
        pUser.SysMessage( ReqNum );
}
function onCallback1( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var incYValue = pSock.xText;
    var incYValue = Number(incYValue);
    var StrangeByte = pSock.GetWord( 1 );
    if( StrangeByte == 0 )
    {
            myTarget.y += incYValue;
    }
    pUser.CustomTarget( 1, "Select target to reposition by "+incYValue+" Y:" );
}
//Repeated Command: INCZ <value>
function command_RINCZ( pSock, execString )
{
    pUser = pSock.currentChar;
    if( !isNaN(execString))
    {
        pSock.xText = execString;
        pUser.CustomTarget( 2, "Select target to reposition by "+execString+" Z:" );
    }
    else
        pUser.SysMessage( ReqNum );
}
function onCallback2( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var incZValue = pSock.xText;
    var incZValue = Number(incZValue);
    var StrangeByte = pSock.GetWord( 1 );
    if( StrangeByte == 0 )
    {
            myTarget.z += incZValue;
    }
    pUser.CustomTarget( 2, "Select target to reposition by "+incZValue+" Z:" );
}

//Repeated Command: SET TYPE <type>
function command_RTYPE( pSock, execString )
{
    pUser = pSock.currentChar;
    if( !isNaN(execString))
    {
        pSock.xText = execString;
        pUser.CustomTarget( 4, "Select target to make TYPE "+execString+":" );
    }
    else
        pUser.SysMessage( ReqNum );
}
function onCallback4( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var TempType = pSock.xText;
    var TempType = Number(TempType);
    var StrangeByte = pSock.GetWord( 1 );
    if( StrangeByte == 0 )
    {
            myTarget.type = TempType;
    }
    pUser.CustomTarget( 4, "Select target to make TYPE "+TempType+":" );
}

//Repeated Command: DYE <hex-id>
function command_RDYE( pSock, execString )
{
    pUser = pSock.currentChar;
    if( !isNaN(execString))
    {
        pSock.xText = execString;
        pUser.CustomTarget( 5, "Select target to DYE "+execString+":" );
    }
    else
        pUser.SysMessage( ReqNum );
}
function onCallback5( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var TempDye = pSock.xText;
    var TempDye = Number(TempDye);
    var StrangeByte = pSock.GetWord( 1 );
    if( StrangeByte == 0 )
    {
            myTarget.colour = TempDye;
    }
    pUser.CustomTarget( 5, "Select target to DYE "+TempDye+":" );
}

//Repeated Command: ADD <hex-id>
function command_RADD( pSock, execString )
{
    pUser = pSock.currentChar;
    if( !isNaN(execString))
    {
        pSock.xText = execString;
        pUser.CustomTarget( 6, "Select target location for item "+execString+":" );
    }
    else
        pUser.SysMessage( ReqNum );
}
function onCallback6( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var TempItemID = pSock.xText;
    var TempItemID = Number(TempItemID);
    var targX = pSock.GetWord( 11 );
    var targY = pSock.GetWord( 13 );
    var targZ = pSock.GetByte( 16 ) + GetTileHeight( pSock.GetWord( 17 ) );

    var tempItem = CreateBlankItem( pSock, pUser, 1, "#", TempItemID, 0x0, "ITEM", false );
    if( tempItem )
        tempItem.SetLocation( targX, targY, targZ );
    pUser.CustomTarget( 6, "Select target location for item "+TempItemID+":" );
}

//Repeated Command: REMOVE
function command_RREMOVE( pSock, execString )
{
    pUser = pSock.currentChar;
    pUser.CustomTarget( 7, "Which item do you wish to remove?" );
}
function onCallback7( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var StrangeByte = pSock.GetWord( 1 );
    if( StrangeByte == 0 && !myTarget.isChar )
    {
            myTarget.Delete();
    }
    else
    {
        pUser.SysMessage( "That's not an item you can remove!" );
    }
    pUser.CustomTarget( 7, "Which item do you wish to remove?" );
}

//Repeated Command: ADD ITEM <item-id from dfns>
function command_RADDITEM( pSock, execString )
{
    pUser = pSock.currentChar;
    pSock.xText = execString;
    pUser.CustomTarget( 8, "Select target location for item "+execString+":" );
}
function onCallback8( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var TempItemID = pSock.xText;
    if( !(TempItemID == null) )
    {
        var targX = pSock.GetWord( 11 );
        var targY = pSock.GetWord( 13 );
        var targZ = pSock.GetByte( 16 ) + GetTileHeight( pSock.GetWord( 17 ) );
        var tempItem = CreateDFNItem( pSock, pUser, TempItemID, 1, "ITEM", false );
        tempItem.x = targX;
        tempItem.y = targY;
        tempItem.z = targZ;
        pUser.CustomTarget( 8, "Select target location for item "+TempItemID+":" );
    }
    else
        pUser.SysMessage( "That doesn't seem to be a valid item-id from the DFNs." );
}

//Repeated Command: TELE <select target location>
function command_RTELE( pSock, execString )
{
    pUser = pSock.currentChar;
    pUser.CustomTarget( 9, "Select location to teleport to:" );
}
function onCallback9( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var targX = pSock.GetWord( 11 );
    var targY = pSock.GetWord( 13 );
    var targZ = pSock.GetByte( 16 ) + GetTileHeight( pSock.GetWord( 17 ) );
    pUser.Teleport( targX, targY, targZ );
    pUser.CustomTarget( 9, "Select location to teleport to:" );
}

//Repeated Command: ADD NPC <npc-id from DFNs>
function command_RADDNPC( pSock, execString )
{
    pUser = pSock.currentChar;
    pSock.xText = execString;
    pUser.CustomTarget( 10, "Select target location for the ["+execString+"]:" );
}
function onCallback10( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var TempNPCID = pSock.xText;
    if( !(TempNPCID == null ) )
    {
        var targX = pSock.GetWord( 11 );
        var targY = pSock.GetWord( 13 );
        var targZ = pSock.GetByte( 16 ) + GetTileHeight( pSock.GetWord( 17 ) );
        var newNPC = SpawnNPC( TempNPCID, targX, targY, targZ, pUser.worldnumber );
        pUser.CustomTarget( 10, "Select target location for the ["+TempNPCID+"]:" );
    }
    else
        pUser.SysMessage( "That doesn't seem to be a valid NPC-id from the DFNs." );
}
-= Ho Eyo He Hum =-
Locked