Page 1 of 1

Release Pets Command

Posted: Tue May 06, 2025 6:20 am
by dragon slayer
// UOX3 JavaScript Command to select and release pets owned by the player's character using a gump
function CommandRegistration()
{
    RegisterCommand("releasepets", 0, true);
}

function command_RELEASEPETS(socket, cmdString )
{
    var character = socket.currentChar;

    if (!character)
    return;

    var followers = character.GetFollowerList();
    var myGump = new Gump;

    myGump.AddBackground(0, 0, 300, (followers.length * 33) + 70, 9270);
    myGump.AddText(20, 20, 1111, "Select pets to release:");

    for (var i = 0; i < followers.length; i++)
    {
        var pet = followers[i];
        myGump.AddCheckbox(20, 50 + (i * 25), 210, 211, 0, i);
        myGump.AddText(45, (50 + (i * 25)), 1111, pet.name.toString());
    }

    myGump.AddButton(220, 25 + (followers.length * 33), 247, 248, 1, 1, 1); // buttonID = 1

    myGump.Send(socket);
    myGump.Free();
}

function onGumpPress(pSock, buttonID, gumpData)
{
    var character = pSock.currentChar;
    if (!character || buttonID !== 1) return;

    var followers = character.GetFollowerList();
    var countReleased = 0;

    // Try all possible checkbox indexes to see if they were returned
    for (var i = 0; i < followers.length; i++)
    {
        var checkboxID = gumpData.getButton(i);

        if (typeof checkboxID !== "undefined" && checkboxID >= 0 && checkboxID < followers.length)
        {
            var pet = followers[checkboxID];
            if (pet) {
                pet.owner = null;
                    // Remove pet as an active follower
                character.RemoveFollower( pet );
                // Reduce control slots in use for player by amount occupied by pet that was on character
                character.controlSlotsUsed = Math.max( 0, character.controlSlotsUsed - pet.controlSlots );
                pet.TextMessage("I am free now!");
                countReleased++;
            }
        }
    }

    character.SysMessage(countReleased + " pets have been released.");
}