Author Topic: Merchant clean script  (Read 318 times)

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Merchant clean script
« on: October 29, 2010, 08:54:08 pm »


               Hi all,

Im needing a script that will be able to clear a merchant inventory after a set amount of time and be able to warn players server wide before it clears the merchant.

Thx
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Merchant clean script
« Reply #1 on: October 29, 2010, 09:27:06 pm »


               Off the top of my head...could do a hearbeat script to keep track of how much time has passed. Came up with this:



//Heartbeat script
void main()
{
    int iBeats = GetLocalInt(OBJECT_SELF, "BEATS");
    SetLocalInt(OBJECT_SELF, "BEATS", iBeats + 1);
    iBeats = GetLocalInt(OBJECT_SELF, "BEATS");

    //@ approx 10 seconds per heartbeat, 360 HBs is approx 1 hour real time.
    if (iBeats == 348)//2 minutes until inventory is deleted.
    {
        object oPC = GetFirstPC();
        while (GetIsObjectValid(oPC))
        {
            SendMessageToPC(oPC, "The store inventory will be deleted in approx. two minutes.");
            oPC = GetNextPC();
        }
    }

    if (iBeats == 360)
    {
        object oStore = GetObjectByTag("Tag of your store");
        object oItem = GetFirstItemInInventory(oStore);
        while (GetIsObjectValid(oItem))
        {
            DestroyObject(oItem);
            oItem = GetNextItemInInventory(oStore);
        }
        //Set beats back to 0 and start the proccess over again.
        SetLocalInt(OBJECT_SELF, "BEATS", 0);
    }
}


This destroys the inventory of the store after about 1 hour of real time. And gives a 2 minute warning to players before the inventory is deleted. You can playe around with the amount of beats if you want different timing.
You can add this to the HB of the module, the area the merchant is in, the merchant himself, or anything else with a heartbeat that can't be destroyed.
This is untested and there are other ways of doing this. This was just my first thought.

Good luck.
               
               

               


                     Modifié par GhostOfGod, 29 octobre 2010 - 08:31 .
                     
                  


            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Merchant clean script
« Reply #2 on: October 29, 2010, 10:27:05 pm »


               Hey Ghost

Thanks for the quick reply, I have just tested this and seems to do exactly what i need, will see how it goes with a live test. '<img'>



Thanks
               
               

               
            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Merchant clean script
« Reply #3 on: November 14, 2010, 09:06:52 pm »


               Hi all, ok i need to add the ability for the above script to clear the store of items below a certain value ie  - clear all below 25000gp



thanks
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Merchant clean script
« Reply #4 on: November 14, 2010, 10:32:11 pm »


               //Heartbeat script
void main()
{
    int iBeats = GetLocalInt(OBJECT_SELF, "BEATS");
    SetLocalInt(OBJECT_SELF, "BEATS", iBeats + 1);
    iBeats = GetLocalInt(OBJECT_SELF, "BEATS");

    //@ approx 10 seconds per heartbeat, 360 HBs is approx 1 hour real time.
    if (iBeats == 348)//2 minutes until inventory is deleted.
    {
        object oPC = GetFirstPC();
        while (GetIsObjectValid(oPC))
        {
            SendMessageToPC(oPC, "The store inventory will be deleted in approx. two minutes.");
            oPC = GetNextPC();
        }
    }

    if (iBeats == 360)
    {
        object oStore = GetObjectByTag("Tag of your store");
        object oItem = GetFirstItemInInventory(oStore);
        while (GetIsObjectValid(oItem))
        {
            // change the 25000 below to the value you want to use.  
            if(GetGoldPieceValue(oItem) > 25000) DestroyObject(oItem);
            oItem = GetNextItemInInventory(oStore);
        }
        //Set beats back to 0 and start the proccess over again.
        SetLocalInt(OBJECT_SELF, "BEATS", 0);
    }
}
               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Merchant clean script
« Reply #5 on: November 18, 2010, 03:10:21 am »


               on close of merchant

//Refreshes merchant list
void main()
{
  object oItem = GetModuleItemLost();
object oOwner = GetItemPossessor(oItem);
if (GetObjectType(oOwner) == OBJECT_TYPE_STORE)
{
if (GetGoldPieceValue(oItem) < 7500) DestroyObject(oItem, 0.1f);
}
}

Doesnt shout to players about clearing items
               
               

               
            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Merchant clean script
« Reply #6 on: November 18, 2010, 10:50:29 pm »


               Thanks
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Merchant clean script
« Reply #7 on: November 19, 2010, 01:06:16 am »


               

Builder_Anthony wrote...

on close of merchant

//Refreshes merchant list
void main()
{
  object oItem = GetModuleItemLost();
object oOwner = GetItemPossessor(oItem);
if (GetObjectType(oOwner) == OBJECT_TYPE_STORE)
{
if (GetGoldPieceValue(oItem) < 7500) DestroyObject(oItem, 0.1f);
}
}

Doesnt shout to players about clearing items


Im having trouble following this.  It looks to me like you are saying to place the script above into the OnClosed Event of the store.  Then you are useing a module Event function (GetModuleItemLost) in a non module event. 

This script being placed in the closing event of a store will have some strange effects.   When the store closes it will look at the last item that was unaquired from any where in the module. then destroy it if it is in a store.  It may be the store that was just closed. Or the item just sold to a different store by another PC.   It also may not get ride of any items when it runs.  A monster could loot a barral in a different area just befor you close the store to cause it to do nothing. 

Either  add it to your module UnAqure event (Effects all stores).   Or rewrite it to not use module event functions.  
               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Merchant clean script
« Reply #8 on: November 20, 2010, 02:21:22 pm »


               Hmm...well i had this script wriiten in these forums sometime back ago from what i remember it checks the gold peice vaule of items sold or in the shop and as listed above 7500....well anything less then 7500 would be sold and high priced items would stay in the shop.Like high value magic items that are hard to find in my server.The script would then delete them after the time amount in the script of 0.1.I think the time amount is editable so you could delay the delete.As for it being in the module events tab.Ill try to see if i have anything in the mod for that but i have to check.