[APPROVED] OSI Commodity Deeds (v1.01 - 14. April 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:

OSI Commodity Deeds (v1.01 - 14. April 2005)

Post by Xuri »

// Commodity Deeds || by Xuri (xuri at sensewave.com)
// v1.01
// Last Updated: 15. April 2005
//
// Tried to get it working like the OSI Commodity Deeds
//
// To use a Commodity Deed, the player needs to place it in his/her bankbox and double click it. They can then target
// a valid resource, which then gets magically teleported INTO the Commodity Deed. When double-clicked later on (also
// while in bankbox), the items are returned to the bankbox.
//
// A blank Commodity Deed uses ID 0x14F0, dyed in a light green color, named "an unfilled Commodity Deed"
// Either add them manually ingame using 'ADD 0x14F0, or by adding a new item to your item-DFN files which
// uses ID=0x14F0, but a different section header, like [comdeed] since [0x14f0] is already taken.

function onUseChecked( pUser, iUsed )
{
    var bankBox = pUser.FindItemLayer( 29 );
    if( iUsed.container && bankBox && iUsed.container.serial == bankBox.serial )           
    {
        var Filled = iUsed.GetTag( "Filled" );
        if( Filled == null || Filled == 0 )
        {
            pUser.SetTag( "ComDeedSer1", iUsed.GetSerial(1) );
            pUser.SetTag( "ComDeedSer2", iUsed.GetSerial(2) );
            pUser.SetTag( "ComDeedSer3", iUsed.GetSerial(3) );
            pUser.SetTag( "ComDeedSer4", iUsed.GetSerial(4) );
            pUser.CustomTarget( 0, "Target the commodity to fill this deed with.." );
            return false;
        }
        else
        {
            var ComID = iUsed.GetTag( "ComID" );
            var ComID = ComID.toString(16);                                        
            if( ComID.length == 3 )
                ComID = "0x0"+ComID;
            else
                ComID = "0x"+ComID;
            var ComID = Number( ComID );
            var ComAmount = iUsed.GetTag( "ComAmount" );
            var ComName = iUsed.GetTag( "ComName" );
            var ComColour = iUsed.GetTag( "ComColour" );
            var ComItem = CreateBlankItem( pUser.socket, pUser, ComAmount, ComName, ComID, ComColour, "ITEM", false );
            ComItem.container = bankBox;
            pUser.SysMessage( "The commodity has been redeemed." );
            iUsed.Delete();
            return false;
        }
    }
    pUser.SysMessage( "To claim the resources represented by this deed, double-click it in your bank box." );
    return false;
}

function onCallback0( pSock, myTarget )
{
    var pUser = pSock.currentChar;
    var StrangeByte = pSock.GetWord( 1 );
    if( StrangeByte == 0 && !myTarget.isChar )
    {
        if(( myTarget.id >= 0x0f78 && myTarget.id <= 0x0f91 ) || ( myTarget.id >= 0x175d && myTarget.id <= 0x1768 ) || ( myTarget.id == 0x1bef || myTarget.id == 0x1bf2 || myTarget.id == 0x1078 || myTarget.id == 0x1079 || myTarget.id == 0x1bfb || myTarget.id == 0x0f3f || myTarget.id == 0x1bd4 || myTarget.id == 0x1bd7 || myTarget.id == 0x1bda || myTarget.id == 0x1bdd || myTarget.id == 0x1be0 ))
        {
            var bankBox = pUser.FindItemLayer(29);
            if( myTarget.container && bankBox && myTarget.container.serial == bankBox.serial )
            {
                pUser.SysMessage( "The commodity deed has been filled with: "+myTarget.amount+" "+myTarget.name );
                var ComDeed = CalcItemFromSer( pUser.GetTag( "ComDeedSer1"), pUser.GetTag( "ComDeedSer2"), pUser.GetTag( "ComDeedSer3"),  pUser.GetTag( "ComDeedSer4"));                       
                ComDeed.name = "A filled Commodity Deed ("+myTarget.amount+" "+myTarget.name+")";
                ComDeed.SetTag( "ComID", myTarget.id );
                ComDeed.SetTag( "ComAmount", myTarget.amount );
                ComDeed.SetTag( "ComName", myTarget.name );
                ComDeed.SetTag( "ComColour", myTarget.colour );
                ComDeed.SetTag( "Filled", 1 );
                myTarget.Delete();
                pUser.SetTag( "ComDeedSer1", null );               
                pUser.SetTag( "ComDeedSer2", null );
                pUser.SetTag( "ComDeedSer3", null );
                pUser.SetTag( "ComDeedSer4", null );
                return false;
            }
            pUser.SysMessage( "The targeted commodity must be in your bank box!" );        
            return false;
        }
    }
    pUser.SysMessage( "The only valid targets are: Cloth, Hides, Leather, Bolts, Arrows, Shafts, Boards, Logs, Regular Reagents or Ingots." );
}
Last edited by Xuri on Sun Jun 22, 2008 4:14 pm, edited 2 times in total.
-= Ho Eyo He Hum =-
Galbuu
UOX3 Neophyte
Posts: 45
Joined: Mon Jul 05, 2004 9:20 am
Location: Orlando, FL
Has thanked: 0
Been thanked: 0
Contact:

Post by Galbuu »

Good job. How come you're not on irc?
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Not sure if you still need this, but here's how to put it in the bankbox:

Replace this:

Code: Select all

               var ComItem = CreateDFNItem( pUser.socket, pUser, ComID, false, 1, true, true );
               ComItem.amount = ComAmount;
               ComItem.name = ComName;
               ComItem.colour = ComColour;
               ComItem.layer = 0x1d; 
With this:

Code: Select all

               var ComItem = CreateDFNItem( pUser.socket, pUser, ComID, ComAmount, "ITEM", true );
               ComItem.name = ComName;
               ComItem.colour = ComColour;
               ComItem.container = bankItem;
Notably, to save yourself some extra cycles, you could also just ensure the items container (that they used) == the players bankbox, instead of doing the loop

IE:

Code: Select all

var bankItem = pUser.FindItemLayer( 0x1D );
if( iUsed.container && bankItem && iUsed.container.serial == bankItem.serial )
{
Do it
}
else
Not in bankbox
Scott
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:

Post by Xuri »

Thanks, I'll take a look once I get home from school :)
-= Ho Eyo He Hum =-
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:

Post by Xuri »

Finally took your advice and got rid of the for-loops, giwo ;)
-= Ho Eyo He Hum =-
Locked