Loot Scatter on Death.

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
Humility
UOX3 Neophyte
Posts: 28
Joined: Mon Nov 21, 2016 7:51 am
Has thanked: 4 times
Been thanked: 5 times

Loot Scatter on Death.

Post by Humility »

deleteme.png
Quick little script that if applied in the npc.dfn file will have your monsters or npcs exploding loot diablo style.
all the better to annoy your friends and amaze your enemies by making it so much easier to pick a pvp fight.

Best used in conjunction with the upcoming 'walk over' to pickup loot script.
function onUseChecked(pUser, iUsed) {
    doJob(null, pUser, null, iUsed); //debug usage to test script on an item trigger
    return false;
}

function onDeathBlow(pDying, pKiller) {
    doJob(null, pDying, pKiller, null);
    return true;
}

function doJob(objSocket, objChar, objOpposingChar, objItem)
{
        var packContents = new Array();
        objChar.frozen = true;
        for (mItem = objChar.pack.FirstItem(); !objChar.pack.FinishedItems(); mItem = objChar.pack.NextItem()) {
            rndX = RandomNumber(-3, 3);
            rndY = RandomNumber(-3, 3);
            itemZ = GetMapElevation(objChar.x + rndX, objChar.y + rndY, objChar.worldnumber);

            if ((ValidateObject(mItem)) && (objChar.CanSee(objChar.x + rndX, objChar.y + rndY, itemZ))) {
                mItem.container = null;
                mItem.Teleport(objChar.x + rndX, objChar.y + rndY, itemZ, objChar.worldnumber);
            }

        }
    objChar.frozen = false;
    objChar.SoundEffect(0x037,true);

    return false;
}
Last edited by Humility on Mon Feb 21, 2022 9:09 am, edited 1 time in total.
These users thanked the author Humility for the post:
Xuri
Humility
UOX3 Neophyte
Posts: 28
Joined: Mon Nov 21, 2016 7:51 am
Has thanked: 4 times
Been thanked: 5 times

Post by Humility »

This here beasty will pick up gold and gems you step on and stack them in the least organized spot it can find in your pack.
you're welcome :P
// 2/21/2022 by DukeHastMich/Humility
function onCollide(trgSock, srcChar, trgItem) {
    //if not stackable or character overloaded or target is alive or target is locked down cancel
    let packCount = srcChar.pack.totalItemCount;
    if (!trgItem.isPileable ||  packCount >= 255 || trgItem.npc || trgItem.isChar || trgItem.movable > 1) { return false; }
    //otherwise if it clears the garbage list of movable lockdowns the client screws up and character has a pack.
    else if (!(chkGarbage(trgItem)) && (ValidateObject(srcChar.pack))) {
        // count the contents of their pack for overload check
        var packContents = srcChar.pack.totalItemCount; // Count
        for (mItem = srcChar.pack.FirstItem(); !srcChar.pack.FinishedItems(); mItem = srcChar.pack.NextItem()) {
 //           srcChar.TextMessage("debug");
            if (ValidateObject(mItem)) {
                let currentID = mItem.id;
                if (currentID == trgItem.id) {
                    if (mItem.amount + trgItem.amount < 65535) {
                        mItem.amount = mItem.amount + trgItem.amount;
                        trgItem.Delete();
                        return false;
                    } else {
                        trgItem.amount -= (65535 - mItem.amount);
                        mItem.amount = 65535;
                    }
                 }
            }
        }
    }
    // Place the item in the pack since we got this far
    if (!InTheBag(trgItem, srcChar, packContents)) {
        //srcChar.TextMessage("it puts the item in the pack or else it gets the ettin smack!", true)
        return false;
    }
}

function chkGarbage(trgItem) {
    if (trgItem.id == 4650) {
        return true;
    }
    else if (trgItem.id == 4651 || trgItem.id == 4652 || trgItem.id == 4653) {
        return true;
    }
    else if (trgItem.id == 4654 || trgItem.id == 4655) {
        return true;
    }
    else
        return false;
}

function DropItem(objItem, objChar) {
    objItem.container = null;
    objItem.Teleport(objChar.x, objChar.y, objChar.z + 5, objChar.worldnumber)
}

function InTheBag(objItem, objChar, packCount) { //This deletes it off the ground
    if (packCount < 255 && objItem.isPileable == true) {
        newItem = objItem.Dupe(objChar.socket);
        newItem.container = objChar.pack;
        newItem.PlaceInPack();
        objItem.Delete();
        newItem.Refresh();
        return true;
    }
    else { return false; }
}

function CreateItem(objChar, strID, intAmount) {
    let newItem = CreateDFNItem(objChar.socket, objChar, strID, intAmount, "ITEM", true);
    newItem.Container = objChar.pack;
    newItem.PlaceInPack();
    return true;

}
Post Reply