Possessing Other Characters

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
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:

Possessing Other Characters

Post by Xuri »

The following script allows possession (or near enough) of other characters by GMs or anyone with commandlevel 2 or higher, through the command 'POSSESS. And unlike the possess command in ancient UOX3 times, this one shouldn't mess up your character if the server crashes/you log out/possess another character after the first. :)

To use this script, save it as possess.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):

1050=commands/custom/possess.js
(NOTE: Use a different (unique!) script-id if 1050 is already taken.)
// Possessing Other Characters
// v0.5
// by Xuri (xuri@sensewave.com)
// Last Updated: 15. January 2006

// This script allows GM characters to virtually possess other characters, by first morphing
// into their appearance then taking their place, while the original character is left standing
// where it was in a state of invulnerability, immovability and without responding to speech.

// When the GM either possesses a new character or returns to normal (targets self), the original
// character is teleported to the GMs current location and is turned visible at the same time as
// the GM is hidden from view.

// To use this script, save it as possess.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)
// 1050=commands/custom/possess.js
// (NOTE: Use a different (unique!) script-id if 1050 is already taken.)

// Then execute the 'POSSESS command ingame after either restarting UOX3 or reloading all JScripts from the console

var delCloneItems = true;
//var cloneSkills = true;
//var skillArray = new Array( "alchemy", "anatomy", "animallore", "etc" );


function CommandRegistration()
{
    RegisterCommand( "possess", 2, true );
}
function command_POSSESS( socket, cmdString )
{
    socket.CustomTarget( 0, "Target NPC for possession:" );
}

function onCallback0( socket, myTarget )
{
    var pUser = socket.currentChar;
    if( !socket.GetWord( 1 ) && myTarget.isChar )
    {
        //Check if our target is our own character
        if( pUser.serial == myTarget.serial )
        {
            //Check to see if we've already possessed someone, if yes, unpossess
            if( pUser.GetTag( "possessing" ) == 1 )
            {
                var cloneNPCserial = pUser.GetTag( "cloneSerial" );
                if( cloneNPCserial )
                    var cloneNPC = CalcCharFromSer( cloneNPCserial );
                //Let's retrieve the character's old tagvalues
                getOldTags( pUser );
                //Lets remove the cloned items
                undressGM( pUser );
                cloneNPC.Teleport( pUser );
                cloneNPC.direction = pUser.direction;
                cloneNPC.visible = 0;
                cloneNPC.vulnerable = true;
                cloneNPC.squelch = 0;
                cloneNPC.frozen = false;
                pUser.visible = 3;
                pUser.SetTag( "possessing", null );
                pUser.SetTag( "cloneSerial", null );
                pUser.SysMessage( "You are no longer possessing anyone." );
               
            }
            else
                pUser.SysMessage( "You haven't possessed anyone." );
        }
        else
        { //Start the cloning process!
            pUser.visible = 3;
            //Clone the beard and hair
            cloneBeard( pUser, myTarget );
            cloneHair( pUser, myTarget );
            //Lets clone the gender, name, title, etc
            //Remember to save tags about the original attributes, so we can unpossess properly later.
            if( pUser.GetTag( "possessing" ) != 1 )
                setOriginalTags( pUser );
            setNewTags( pUser, myTarget );
            //Lets undress the GM! whee!
            undressGM( pUser );
            //Let's re-dress the GM with the clone's clothing! Woo!
            cloneItems( pUser, myTarget );
            var cloneNPCserial = pUser.GetTag( "cloneSerial" );
            if( cloneNPCserial )
            {
                var cloneNPC = CalcCharFromSer( cloneNPCserial );
                cloneNPC.Teleport( pUser );
                cloneNPC.direction = pUser.direction;
                cloneNPC.visible = 0;
                cloneNPC.vulnerable = true;
                cloneNPC.squelch = 0;
                cloneNPC.frozen = false;
            }
            pUser.Teleport( myTarget );
            pUser.SetTag( "cloneSerial", ( myTarget.serial & 0x00FFFFFF ) );
            myTarget.visible = 3;
            myTarget.vulnerable = false;
            myTarget.squelch = 1;
            myTarget.frozen = true;
            myTarget.target = null;
            myTarget.attacker = null;
            myTarget.Teleport( 8000, 4000, 0);
            pUser.visible = 0;
            pUser.SysMessage( "You have possessed "+myTarget.name+" the NPC." );
            pUser.SysMessage( "Target yourself with the possess command to return to normal." );
            pUser.SetTag( "possessing", 1 );
        }
    }
    else
        pUser.SysMessage( "You must target a character!" );
}

function getOldTags( pUser )
{
    pUser.gender = pUser.GetTag( "oldgender" );
    pUser.id = pUser.GetTag( "oldid" );
    pUser.name = pUser.GetTag( "oldname" );
    if( pUser.GetTag( "oldtitle") != "" )
        pUser.title = pUser.GetTag( "oldtitle" );
    else
        pUser.title = null;
    pUser.colour = pUser.GetTag( "oldcolour" );
    pUser.dexterity = pUser.GetTag( "olddexterity" );
    pUser.strength = pUser.GetTag( "oldstrength" );
    pUser.intelligence = pUser.GetTag( "oldintelligence" );
    pUser.mana = pUser.GetTag( "oldmana" );
    pUser.stamina = pUser.GetTag( "oldstamina" );
    pUser.health = pUser.GetTag( "oldhealth" );
    pUser.fame = pUser.GetTag( "oldfame" );
    pUser.karma = pUser.GetTag( "oldkarma" );
    pUser.hunger = pUser.GetTag( "oldhunger" );
    pUser.race = pUser.GetTag( "oldraceid" );
    pUser.murdercount = pUser.GetTag( "oldmurdercount" );
    pUser.sayColour = pUser.GetTag( "oldsaycolour" );
    pUser.aitype = pUser.GetTag( "oldaitype" );
    //Get old beard back
    var myBeard = pUser.FindItemLayer(16);
    if( myBeard )
    {      
        myBeard.id = pUser.GetTag( "oldbeardid" );
        myBeard.colour = pUser.GetTag( "oldbeardcolour" );
    }
    else
    {
        var oldBeard = pUser.GetTag( "oldbeardid" );
        pUser.SysMessage( oldBeard );
        if( oldBeard != null && oldBeard != 0 )
        {
            var HexBeard = oldBeard.toString(16);
            var newBeard = CreateDFNItem( pUser.socket, pUser, "0x"+HexBeard, 1, "ITEM", true );
            if( newBeard )
                newBeard.colour = pUser.GetTag( "oldbeardcolour");
        }
    }
    //Get old hair back
    var myHair = pUser.FindItemLayer(11);
    if( myHair )
    {      
        myHair.id = pUser.GetTag( "oldhairid" );
        myHair.colour = pUser.GetTag( "oldhaircolour" );
    }
    else
    {
        var oldHair = pUser.GetTag( "oldhairid" );
        pUser.SysMessage( oldHair );
        if( oldHair != null && oldHair != 0 )
        {
            var HexHair = oldHair.toString(16);
            var newHair = CreateDFNItem( pUser.socket, pUser, "0x"+HexHair, 1, "ITEM", true );
            if( newHair )
                newHair.colour = pUser.GetTag( "oldhaircolour" );
        }
    }
    //Clear out the tags
    pUser.SetTag( "oldbeardid", null );
    pUser.SetTag( "oldbeardcolour", null );
    pUser.SetTag( "oldhairid", null );
    pUser.SetTag( "oldhaircolour", null );
    pUser.SetTag( "oldgender", null );
    pUser.SetTag( "oldid", null );
    pUser.SetTag( "oldname", null );
    pUser.SetTag( "oldtitle", null );
    pUser.SetTag( "oldcolour", null );
    pUser.SetTag( "olddexterity", null );
    pUser.SetTag( "oldstrength", null );
    pUser.SetTag( "oldintelligence", null );
    pUser.SetTag( "oldmana", null );
    pUser.SetTag( "oldstamina", null );
    pUser.SetTag( "oldhealth", null );
    pUser.SetTag( "oldfame", null );
    pUser.SetTag( "oldkarma", null );
    pUser.SetTag( "oldhunger", null );
    pUser.SetTag( "oldrace", null );
    pUser.SetTag( "oldcriminal", null );
    pUser.SetTag( "oldinnocent", null );
    pUser.SetTag( "oldmurdercount", null );
    pUser.SetTag( "oldvulnerable", null );
    pUser.SetTag( "oldaitype", null );
}

function undressGM( pUser )
{
    var i = 0;
    for( i = 0; i <= 24; i++ )
    {
        var tempObj = pUser.FindItemLayer(i);
        if( tempObj != null )
        {
            if( i != 11 && i != 16 && i != 21 )
            {
                tempObj.container = pUser.pack;
                if( delCloneItems = true && pUser.GetTag( "possessing" ) == 1 )
                    tempObj.Delete();
            }
        }
    }
}

function setOriginalTags( pUser )
{
    pUser.SetTag( "oldgender", pUser.gender );
    pUser.SetTag( "oldid", pUser.id );
    pUser.SetTag( "oldname", pUser.name );
    pUser.SysMessage( pUser.title );
    pUser.SetTag( "oldtitle", pUser.title );
    pUser.SetTag( "oldcolour", pUser.colour );
    pUser.SetTag( "olddexterity", pUser.dexterity );
    pUser.SetTag( "oldstrength", pUser.strength );
    pUser.SetTag( "oldintelligence", pUser.intelligence );
    pUser.SetTag( "oldmana", pUser.mana );
    pUser.SetTag( "oldstamina", pUser.stamina );
    pUser.SetTag( "oldhealth", pUser.health );
    pUser.SetTag( "oldfame", pUser.fame );
    pUser.SetTag( "oldkarma", pUser.karma );
    pUser.SetTag( "oldhunger", pUser.hunger );
    var origRace = pUser.race;
    pUser.SetTag( "oldraceid", origRace.id );
    pUser.SetTag( "oldcriminal", pUser.criminal );
    pUser.SetTag( "oldinnocent", pUser.innocent );
    pUser.SetTag( "oldmurdercount", pUser.murdercount );
    pUser.SetTag( "oldsaycolour", pUser.sayColour );
    pUser.SetTag( "oldvulnerable", pUser.vulnerable );
    pUser.SetTag( "oldaitype", pUser.aitype );
}

function setNewTags( pUser, myTarget )
{
    pUser.gender = myTarget.gender;
    pUser.id = myTarget.id;
    pUser.name = myTarget.name;
    pUser.title = myTarget.title;
    pUser.colour = myTarget.colour;
    pUser.dexterity = myTarget.dexterity;
    pUser.strength = myTarget.strength;
    pUser.intelligence = myTarget.intelligence;
    pUser.mana = myTarget.mana;
    pUser.stamina = myTarget.stamina;
    pUser.health = myTarget.health;
    pUser.fame = myTarget.fame;
    pUser.karma = myTarget.karma;
    pUser.hunger = myTarget.hunger;
    var targetRace = myTarget.race;
    pUser.race = targetRace.id;
    pUser.murdercount = myTarget.murdercount;
    pUser.sayColour = myTarget.sayColour;
    pUser.vulnerable = myTarget.vulnerable;
    pUser.aitype = myTarget.aitype;
    //Let's clone the skillvalues as well
    /*if( cloneSkills == true )
    {
        for( var i = 0; i < skillArray.length; i++ )
        {
            pUser.SysMessage( skillArray[i] );
            pUser.SysMessage( pUser.skills+"."+skillArray[i] );
            pUser.skills.skillArray[i] = myTarget.skills.skillArray[i];
        }
    }*/

}

function cloneHair( pUser, myTarget )
{
    //Lets clone the possible hair
    var cloneHair = myTarget.FindItemLayer(11);
    var myHair = pUser.FindItemLayer(11);
    if( myHair )
    {
        if( pUser.GetTag( "possessing" ) == 0 )
        {
            pUser.SetTag( "oldhairid", myHair.id );
            pUser.SetTag( "oldhaircolour", myHair.colour );
        }
        if( cloneHair )
        {
            myHair.id = cloneHair.id;
            myHair.colour = cloneHair.colour;
        }
        else
        {
            var myHair = pUser.FindItemLayer(11);
            if( pUser.FindItemLayer(11) != null )
                myHair.Delete();
        }
    }
    else
    {
        if( cloneHair )
        {
            var HexHair = cloneHair.id.toString(16);           
            var newHair = CreateDFNItem( pUser.socket, pUser, "0x"+HexHair, 1, "ITEM", true );
            if( newHair )
                newHair.colour = cloneHair.colour;
        }
    }
}

function cloneBeard( pUser, myTarget )
{
    //Lets clone the possible beard
    var cloneBeard = myTarget.FindItemLayer(16);
    var myBeard = pUser.FindItemLayer(16);
    if( myBeard )
    {
        if( pUser.GetTag( "possessing" ) == 0 )
        {
            pUser.SetTag( "oldbeardid", myBeard.id );
            pUser.SetTag( "oldbeardcolour", myBeard.colour );
        }
        if( cloneBeard )
        {
            myBeard.id = cloneBeard.id;
            myBeard.colour = cloneBeard.colour;
        }
        else
        {
            var myBeard = pUser.FindItemLayer(16);
            if( pUser.FindItemLayer(16) != null )
                myBeard.Delete();
        }
    }
    else
    {
        if( cloneBeard )
        {
            var HexBeard = cloneBeard.id.toString(16);
            var newBeard = CreateDFNItem( pUser.socket, pUser, "0x"+HexBeard, 1, "ITEM", true );
            if( newBeard )
                newBeard.colour = cloneBeard.colour;
        }
    }
}

function cloneItems( pUser, myTarget )
{
    var i = 0;
    for( i = 0; i <= 24; i++ )
    {
        var tempObj = myTarget.FindItemLayer(i);
        if( tempObj != null )
        {
            if( i != 11 && i != 16 && i != 21 )
            {
                var HexID = tempObj.id.toString(16);                       
                var newClothes = CreateDFNItem( pUser.socket, pUser, "0x"+HexID, 1, "ITEM", true );
                if( newClothes )
                {
                    newClothes.container = pUser;
                    newClothes.colour = tempObj.colour;
                    newClothes.layer = tempObj.layer;  
                }
            }
        }
    }
}
-= Ho Eyo He Hum =-
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Hello Xuri,

Let me say first that this command is very good. Congratulations!
I also know that you are very busy, but leave some comments here that I noticed about, if you want to see it again someday....

1-When you posses an NPC with the original color, everything ok! But, if you have the NPC is colored, the color of NPC will become the same color of your character, not the color that the NPC had before you owning him.

2-The command allows you owning other players, which I believe was no longer correct. However, if you own another player, if I'm not mistaken, and save the world or some other incident occurs, you will lose your character! The 0x01 space is empty, and a new space 0x07 is created automatically on the screen of choice character.

3-When you die is possessing an NPC, rather than getting the NPC's body on the floor, with their respective loot, will get your body and your loot in the floor! (I believe that if you die having an NPC, the body that should stay on the floor was his, and he did die, not you). When you die, your character back to human form, however the NPC is there, alive, "within you/inside you". Only when you use the command again it will leave you...

4-When you owning a human NPC that is equipped with armor or garment, and a mount, plus the fact stated in item 1, you get naked, as you does not equipped as him (If you dispossess him, the NPC back to normal, but when you owning it, you go out without their equipment or mount).
Post Reply