Author Topic: Inventory Modification script help needed :)  (Read 392 times)

Legacy_DarkAnya

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inventory Modification script help needed :)
« on: November 03, 2010, 09:44:08 am »


               Hi guys!
I need a little help with a script which would cycle through six players and:
 a. delete all items worth less than 20K gold
 b. transfer all the rest of the items to a chest with a specific tag

I can do the "while" functions for selecting and cycling through players, but I don't know how to do inventory things like deleting the items worth less than 20k or transferring the others to another object.

Help? '<img'>
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Inventory Modification script help needed :)
« Reply #1 on: November 03, 2010, 04:49:46 pm »


               Well, i haven't teseted this and I wasnt sure how you meant to only loop through six players, but this will loop through all the players on the server and do what you need. If i did it right:whistle:.
This is probably going to be a lag monster and not something you want to do all the time. Two loops inside a loop can't be good. But anyway:


void main()
{
    object oChest = GetObjectByTag("Tag of chest here");//put your chest's tag here
    object oPC = GetFirstPC();
    while (GetIsObjectValid(oPC))
    {
        object oItem;
        int iValue;
        oItem = GetFirstItemInInventory(oPC);
        while (GetIsObjectValid(oItem))
        {
            iValue = GetGoldPieceValue(oItem);
            if (iValue < 20000)
                DestroyObject(oItem);
            else
            {
                CopyItem(oItem, oChest, TRUE);
                DestroyObject(oItem);
            }
            oItem = GetNextItemInInventory(oPC);
        }

        int iSlot;
        for (iSlot=0; iSlot<NUM_INVENTORY_SLOTS; iSlot++)
        {
            oItem = GetItemInSlot(iSlot, oPC);
            iValue = GetGoldPieceValue(oItem);
            if (iValue < 20000)
                DestroyObject(oItem);
            else
            {
                CopyItem(oItem, oChest, TRUE);
                DestroyObject(oItem);
            }
        }
        oPC = GetNextPC();
    }
}


This also gets equipped items. Not sure if you wanted to get those as well.

Hope this helps.

NOTE: This will also destroy plot items. And when checking the gold cost value of an item that is not identified, it will get it's base value...not its idendified value. If these things need to be taken into consideration then let me know so we can update the script above.
               
               

               


                     Modifié par GhostOfGod, 03 novembre 2010 - 08:12 .
                     
                  


            

Legacy_DarkAnya

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inventory Modification script help needed :)
« Reply #2 on: November 04, 2010, 01:32:43 am »


               Thanks a lot! I'll try to test it and report back. '<img'>
               
               

               
            

Legacy_DarkAnya

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inventory Modification script help needed :)
« Reply #3 on: November 04, 2010, 01:35:35 am »


               There is one other thing I thought of. Instead of putting everything in one chest, is it possible to split it between four chests, AT RANDOM? Like each item goes randomly into one of the four chests. That way the players have to find all four chests to retrieve their stuff?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Inventory Modification script help needed :)
« Reply #4 on: November 04, 2010, 04:11:56 am »


               Maybe something like so:

void main()
{
    object oChest1 = GetObjectByTag("Tag of chest1 here");
    object oChest2 = GetObjectByTag("Tag of chest2 here");
    object oChest3 = GetObjectByTag("Tag of chest3 here");
    object oChest4 = GetObjectByTag("Tag of chest4 here");
    object oPC = GetFirstPC();
    while (GetIsObjectValid(oPC))
    {
        object oItem;
        int iValue;
        int iRandom;
        oItem = GetFirstItemInInventory(oPC);
        while (GetIsObjectValid(oItem))
        {
            iValue = GetGoldPieceValue(oItem);
            if (iValue < 20000)
                DestroyObject(oItem);
            else
            {
                iRandom = d4();
                switch (iRandom)
                {
                    case 1: CopyItem(oItem, oChest1, TRUE); break;
                    case 2: CopyItem(oItem, oChest2, TRUE); break;
                    case 3: CopyItem(oItem, oChest3, TRUE); break;
                    case 4: CopyItem(oItem, oChest4, TRUE); break;
                }
                DestroyObject(oItem);
            }
            oItem = GetNextItemInInventory(oPC);
        }

        int iSlot;
        for (iSlot=0; iSlot<NUM_INVENTORY_SLOTS; iSlot++)
        {
            oItem = GetItemInSlot(iSlot, oPC);
            iValue = GetGoldPieceValue(oItem);
            if (iValue < 20000)
                DestroyObject(oItem);
            else
            {
                iRandom = d4();
                switch (iRandom)
                {
                    case 1: CopyItem(oItem, oChest1, TRUE); break;
                    case 2: CopyItem(oItem, oChest2, TRUE); break;
                    case 3: CopyItem(oItem, oChest3, TRUE); break;
                    case 4: CopyItem(oItem, oChest4, TRUE); break;
                }
                DestroyObject(oItem);
            }
        }
        oPC = GetNextPC();
    }
}
               
               

               
            

Legacy_DarkAnya

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inventory Modification script help needed :)
« Reply #5 on: November 06, 2010, 10:51:53 am »


               It seems to compile alright. But does it also take into consideration the objects that are equipped?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Inventory Modification script help needed :)
« Reply #6 on: November 06, 2010, 04:12:04 pm »


               Yes it does.