Discussion in 'Scripts (LavishScript)' started by BackseatScripter, Apr 8, 2009.

  1. BackseatScripter

    BackseatScripter Active Member

    Messages:
    20
    I've been thinking about this for a while now but haven't had a lot of time to work on it. Consequently I've 'appropriated' (read stolen) whole chunks of MMOAddict's code from VGA and done my usual butchery work.

    Though I've not yet had a chance to even test it, I thought I may aswell post the concept code for those more experienced than me to give a once over.

    I'm definately leaning towards using a text box to add items to the trashlist, as you can't buy back what you destroy. I think the function would be best run as part of the loot code, probably immediately prior to the actual looting. Destroy only works when out of combat.

    Anyway here's what I have so far.

    Code (Text):
    function Trash()
    {
      variable int i = 1

      ; Loop through the inventory, incrementing "i" by one each time until
      ; Me.Inventory[i] isn't valid anymore

      do
    {
        if ${doTrash}
         {
        variable iterator Iterator
        Trash:GetSettingIterator[Iterator]
        Iterator:First
        while ( ${Iterator.Key(exists)} )
        {
            if ${Me.Inventory[${i}].Name.Equal[${Iterator.Key}]}
            {
            VGExecute /destroy "${Iterator.Key}"
            }
            Iterator:Next
        }
          }
          i:Inc
      }
      while ${Me.Inventory[${i}].ID(exists)}
      echo I've taken out the trash, chores complete. PLAY TIME!!      
    }




    ;********************************************
    /* Add item to the Trash list */
    ;********************************************
    atom(global) AddTrash(string aName)
    {
        if ( ${aName.Length} > 1 )
        {
            LavishSettings[VGA_General].FindSet[Trash]:AddSetting[${aName}, ${aName}]

        }
        else
        {
            return
        }
    }
    atom(global) RemoveTrash(string aName)
    {
        if ( ${aName.Length} > 1 )
        {
            Trash.FindSetting[${aName}]:Remove
        }
        else
        {
        }
    }

    atom(global) BuildTrash()
    {
        variable iterator Iterator
        Trash:GetSettingIterator[Iterator]
        UIElement[TrashList@TrashFrm@Trash@MainSubTab@MainFrm@Main@ABot@vga_gui]:ClearItems
        while ( ${Iterator.Key(exists)} )
        {
            UIElement[TrashList@TrashFrm@Trash@MainSubTab@MainFrm@Main@ABot@vga_gui]:AddItem[${Iterator.Key}]
            Iterator:Next
        }
    }
  2. mmoaddict

    mmoaddict Original Script Author: VGA

    Messages:
    200
    omg where did all my pristine viel thread go!

    looks good but you should use Me.Inventory[ExactName,NameofItem].. otherwise it will delete any item containing the name you put in there..

    so if you type in "iron ore" then it would also delete "black iorn ore" which would be bad.

    mmo
  3. BackseatScripter

    BackseatScripter Active Member

    Messages:
    20
    Thank you very much for that snippet of wisdom


    Code (Text):
    VGExecute /destroy "${Iterator.Key}"
    has been changed to

    Code (Text):
    Me.Inventory[ExactName,${Iterator.Key}]:Delete
  4. Amadeus

    Amadeus The Maestro Staff Member

    Messages:
    8,270
    Otherwise, this line:
    Code (Text):

    while ${Me.Inventory[${i}].ID(exists)}
     
    might be better as:
    Code (Text):

    while ${Me.Inventory[${i}](exists)}
     
    ...though, it may not make very much difference.


    Finally, your routine assumes that Me.Inventory[1] is valid. It's probably not an issue; however, in order to build good habits I should point it out.
  5. Amadeus

    Amadeus The Maestro Staff Member

    Messages:
    8,270
    Actually, why not do this:


    Code (Text):
     
            if ${Me.Inventory[${i}].Name.Equal[${Iterator.Key}]}
            {
                 Me.Inventory[${i}]:Delete
            }
            Iterator:Next
     
    That would be the most efficient.
  6. BackseatScripter

    BackseatScripter Active Member

    Messages:
    20
    Very nice, thanks for that.

    I finally got work to unfilter your wiki site but there's a lot of different ways to to implement a function and it seems I managed to start with the most illconceived.


    Looking at the changes suggested I now see that:

    My first attempt would have deleted an item from an unpredictable inventory slot and as MMO pointed out it was not geared to an exact name match

    My second attempt would have only deleted an exact name match but if there was more than one matching item there was no way to predict which item would be deleted

    Your code deletes exact name and from the inventory slot currently being tested.
    Last edited: Apr 9, 2009

Share This Page