Author Topic: OnStoreClosed Script  (Read 552 times)

Legacy_Mephisto Gladius

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
OnStoreClosed Script
« on: September 07, 2010, 02:51:00 pm »


               Is there any way to remove all the merchant inventory items after PC closes store? This merchant only buy stuff, and it's causing lag by having lots of items, so I want to remove them.

There's a way? 'Image
               
               

               
            

Legacy_TheSpiritedLass

  • Hero Member
  • *****
  • Posts: 1118
  • Karma: +0/-0
OnStoreClosed Script
« Reply #1 on: September 07, 2010, 03:35:20 pm »


               Does the shop have a blueprint in the palette?  I have a generic script around here somewhere that destroys a shop and drops a new one based on the shop tag set on the NPC.  But the shop must be in the palette for that to work.
               
               

               
            

Legacy_Mephisto Gladius

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
OnStoreClosed Script
« Reply #2 on: September 07, 2010, 03:37:48 pm »


               Yes, the shop is in my custom palette.
               
               

               
            

Legacy_TheSpiritedLass

  • Hero Member
  • *****
  • Posts: 1118
  • Karma: +0/-0
OnStoreClosed Script
« Reply #3 on: September 07, 2010, 03:44:52 pm »


               Give me a couple minutes and I'll dig up the script for you. =)
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
OnStoreClosed Script
« Reply #4 on: September 07, 2010, 03:56:06 pm »


               Use the link below...both are old but work awesome and with ese to set up.

http://nwvault.ign.c...s.Detail&id=991


This one from the same guy I like a little better as you can make it so the store cleans itself after every 3rd opening so it looks like its inventory is changing.

http://nwvault.ign.c...s.Detail&id=990
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
OnStoreClosed Script
« Reply #5 on: September 07, 2010, 03:57:38 pm »


               You can also tag items on the OnAquire script as setting an Int on them with say PCITEM then on close of the store it checks in the stores items and will delete the items marked as so.
               
               

               


                     Modifié par TSMDude, 07 septembre 2010 - 02:57 .
                     
                  


            

Legacy_TheSpiritedLass

  • Hero Member
  • *****
  • Posts: 1118
  • Karma: +0/-0
OnStoreClosed Script
« Reply #6 on: September 07, 2010, 03:59:17 pm »


               OKay, the header of the file explains most of how to use this.  What it doesn't explain is the MYTHOS_SHOP_NUKE_MAX variable you can set on the shop blueprint.  What that does is determine how offen the shop is nuked.  I typically had this set to 5.  So every 5th time the shop was nuked and remade.  If you want the shop to nuke every time, then you don't even need to set this variable, since GetLocalInt returns 0 if a variable isn't set, which tells the script 'Nuke away!'

Let me know if any of this does not make sense...

Hmmm... Now how did it work to put stuff in a code box again?  *takes a guess*


/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
* File Name: m_recreate_shop
*
* Purpose: Goes in the onClose event of a shop. It will destroy the shop object
* and drop a new one. The shop object must have a blueprint in the
* palette for this to work.
*
* Used to clean up inventory of shops that a player is not likely to
* want to purchase items that other player's have sold.
*
* Example: Bijou's gem shop in Genesia.
*
* Created By: Mistress
* Created On: 7-22-09
*
* Modeled after and adapted from:
*
* Change Log:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
void main()
{
// Save off the tag so we can recreate it later
string sStoreTag = GetTag(OBJECT_SELF);

// Save off the location of the shop
location lStoreLoc = GetLocation(OBJECT_SELF);

// See if the shop has a counter.
int nCounterMax = GetLocalInt(OBJECT_SELF, "MYTHOS_SHOP_NUKE_MAX");
int nCounterCur = GetLocalInt(OBJECT_SELF, "MYTHOS_SHOP_NUKE_CURRENT");

// Increase the counter for the close we just did.
nCounterCur++;

// Nuke the shop if there is no counter or we have reached the max number of
// closes
if(0 == nCounterMax || nCounterCur >= nCounterMax)
{
// Destroy the shop
DestroyObject(OBJECT_SELF);

// Now drop a new copy of the shop on the map
object oMerchant = CreateObject(OBJECT_TYPE_STORE, sStoreTag, lStoreLoc, FALSE);
if(oMerchant == OBJECT_INVALID)
{
WriteTimestampedLogEntry("ERROR: " + sStoreTag + " failed to recreate in script m_recreate_shop.");
}
}

// If we aren't nuking the shop, then see if we need to update the counter
else if(0 != nCounterMax)
{
SetLocalInt(OBJECT_SELF, "MYTHOS_SHOP_NUKE_CURRENT", nCounterCur);
}
} // END of void main()

               
               

               
            

Legacy_TheSpiritedLass

  • Hero Member
  • *****
  • Posts: 1118
  • Karma: +0/-0
OnStoreClosed Script
« Reply #7 on: September 07, 2010, 04:02:36 pm »


               Bah, so much for my guess on how to put the code in a pretty formatted box.  *Shudders at the all left justified code.*  If you plan on using it, I can just erf the thing out and email it to you.
               
               

               
            

Legacy_Mephisto Gladius

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
OnStoreClosed Script
« Reply #8 on: September 07, 2010, 04:27:14 pm »


               Wow, thank you for helping. This store will no more lag the entire server.
               
               

               
            

Legacy_TheSpiritedLass

  • Hero Member
  • *****
  • Posts: 1118
  • Karma: +0/-0
OnStoreClosed Script
« Reply #9 on: September 07, 2010, 06:29:16 pm »


               YW =)  If you do end up using it, the erf file would be better than that left justified mess.  *ughs*  Hmmm.  Not sure if this is worth posting to the vault as a "formal" download.  *shrugs*  I could do that if there is a need for it.
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
OnStoreClosed Script
« Reply #10 on: September 07, 2010, 06:38:26 pm »


               This is the script I use in all my stores to clear the store of item sold...

The reason we use OnOpenStore, rather than OnCloseStore, is because a PC could be viewing the store, other than the one closing it, and by doing so, they would wipe the store..  This can still happen if a PC opens the store while another PC is viewing it, but the benefit is, the PC cannot see what the PC just sold the store, so no spying..

// This script goes into OnOpenStore.
// Made by Darvin Kezar.
void main()
{

object oItem = GetFirstItemInInventory();
int nCount = GetLocalInt(OBJECT_SELF, "Count")+1;
SetLocalInt(OBJECT_SELF, "Count", nCount);
    if (nCount == 1)
    {
        while(oItem != OBJECT_INVALID)
        {
        SetLocalInt(oItem, "Default", 1);
        oItem = GetNextItemInInventory();
        }
    }
    else
    {
        while(oItem != OBJECT_INVALID)
        {
        if(GetLocalInt(oItem, "Default") == 0)
        DestroyObject(oItem);
        oItem = GetNextItemInInventory();
        }
    }
}
               
               

               


                     Modifié par Genisys, 07 septembre 2010 - 05:40 .
                     
                  


            

Legacy_Xovian

  • Full Member
  • ***
  • Posts: 158
  • Karma: +0/-0
OnStoreClosed Script
« Reply #11 on: September 07, 2010, 07:10:10 pm »


               ????



So much complication:



Step1> Make the store.

Step2> Let player browse buy/sell.

Step3> Close and destroy the store when they finish.

Step4> There is no step 4, it repeats every time you open or close the store.



My base module does this already. (Look at my projects)

It has it's pros and cons.

pro: It won't build much lag due to the store being opened or closed especially if cashe`.

con: It does not save any inventory that has been sold, and reopens a new each time the store opens.
               
               

               
            

Legacy_Jargh193

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
OnStoreClosed Script
« Reply #12 on: September 07, 2010, 10:02:30 pm »


               I think I've seen a store like your talking about in Aschbourne PW. there is a copy on the vault but not sure if that store was added after the mod hit the vault or not. I'll try to dig up a newer version and search for the code.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
OnStoreClosed Script
« Reply #13 on: September 07, 2010, 10:17:55 pm »


               

Mephisto Gladius wrote...

Is there any way to remove all the merchant inventory items after PC closes store? This merchant only buy stuff, and it's causing lag by having lots of items, so I want to remove them.

There's a way? 'Image



Put this on close for the store.  If a PC can not buy from the store, it does not matter if the Items vanish before his eyes or not. 

void main()
{
    float fDelay;
    object oItem = GetFirstItemInInventory();
    while(GetIsObjectValid(oItem))
    {
        DestroyObject(oItem,fDelay += 0.1);
        oItem = GetNextItemInInventory();
    }
}

  
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
OnStoreClosed Script
« Reply #14 on: September 07, 2010, 11:38:25 pm »


               

Xovian wrote...
It has it's pros and cons.
pro: It won't build much lag due to the store being opened or closed especially if cashe`.
con: It does not save any inventory that has been sold, and reopens a new each time the store opens.


Con: You must have it on your pallette which when you have a large server this becomes noteworthy as it takes up valuable resources.


If you add the little extra of it cleaning every now and then like the systems I linked then what happens after the third player who opens the store it gets cleaned when that player leaves the area. It is nice and works like a charm and causes very little fuss.


In a "SP Module" though yours does indeed work much better.

Did the OP who is the VIP specfiy if for MP or SP or just go MIA on the DL?