Delete items in shop?
#1
Posté 03 octobre 2015 - 11:50
#2
Posté 03 octobre 2015 - 01:07
i didn't make this bit of code, but place in your merchant OnHeartbeat handler, then add your stores tag.
there might be a more suitable way to do this, because heartbeat scripts can cause lag. this is what i use though... just thought i'd return the favor.
//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.
//if (iBeats == 20)//2 minutes until inventory is deleted.
{
ActionSpeakString("The Vendor inventory will be deleted in two minutes!", TALKVOLUME_SHOUT);
object oPC = GetFirstPC();
while (GetIsObjectValid(oPC))
{
SendMessageToPC(oPC, "The Vendor inventory will be deleted in two minutes!");
oPC = GetNextPC();
}
}
if (iBeats == 360)
{
object oStore = GetObjectByTag("tagofstore");
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);
}
}
- Who said that I aime ceci
#3
Posté 05 octobre 2015 - 02:08
If the intent is for the script to delete items in the store's inventory that only are there because a PC sold them, then the script may have to do more than that. Since (to my initial read) it deletes all items on the store, not just sold items from the player/
There are probably several ways to do this. Two come immediately to mind.
First, use OnStoreOpened to check when the store is first opened and make a list of the resrefs (and maybe stack sizes) of all the items in inventory. Then, write an OnStoreClosed script that runs through the store's inventory when the PC closes the store and gets rid of any items not in the original items list. The OnStoreClosed event could also be done as a heartbeat script and it could do things like delay if any PC is still in the area, etc.
Another approach would be to create a duplicate store and, every time the store is closed (or on a heartbeat, but I would hesitate to do this more often than needed, especially if it is potentially running for many stores) delete all the items from the store that the PCs interact with and then copy the items from the duplicate store over. The second approach is similar to the first, the main difference being that it uses another store to (effectively) keep the list of original items. It's potentially lest efficient than the first approach, but it might have the advantage of not allowing multiple copies of items to show up in the store (for instance when a sold item has the same resref as an original item). Whether that's something desired or not is up to the builder.
#4
Posté 05 octobre 2015 - 02:54
You can also set a local variable on the store items as well, though this will allow store bought items to be sold and retained in any store.First, use OnStoreOpened to check when the store is first opened and make a list of the resrefs
#5
Posté 05 octobre 2015 - 04:08
If your original store and items are from a blueprint, you could just delete the original store and create a new one.
EDIT: example, the following script placed in the OnClosed event will clean the store on every 5th closing.
void main()
{
int x = GetLocalInt(OBJECT_SELF,"store_usage")+1;
if (x>4)
{
CreateObject(OBJECT_TYPE_STORE,GetResRef(OBJECT_SELF),
GetLocation(OBJECT_SELF),FALSE,GetTag(OBJECT_SELF));
DestroyObject(OBJECT_SELF);
}
SetLocalInt(OBJECT_SELF,"store_usage", x);
// no need to ever reset the local int it will be destroyed along with
// the old store.
}
#6
Posté 05 octobre 2015 - 05:57
If the intent is for the script to delete items in the store's inventory that only are there because a PC sold them, then the script may have to do more than that. Since (to my initial read) it deletes all items on the store, not just sold items from the player/
If thats the intent then this feature is implemented in community patch as an optional module switch.
So either install it or copy the feature from it its in x2_def_mod_aqu script
#7
Posté 05 octobre 2015 - 04:31
If the desire is to clean out all items a PC sells to ANY NPC Merchant, then try the following in your Module's OnUnAcquireItem event:
#include "x2_inc_switches"
void main()
{
object oItem = GetModuleItemLost();
if (GetObjectType(GetItemPossessor(oItem)) == OBJECT_TYPE_STORE) DestroyObject(oItem, 0.1f);
if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
{
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_UNACQUIRE);
int nRet = ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
if (nRet == X2_EXECUTE_SCRIPT_END)
{
return;
}
}
}
This will auto delete ALL sold items as they are sold to a merchant.





Retour en haut







