Author Topic: Selling to store infinite goods  (Read 966 times)

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Selling to store infinite goods
« on: July 26, 2010, 04:08:15 pm »


               Hey, I made persistent stores, but found an issue that if you sell to store item that is already in shop and infinite (which is most of them, cos you cant store item count in store) the item when UnAcquire is fired is invalid (but not OBJECT_INVALID) and his possessor therefore too, so I cant fire script "store_bought". I would like to avoid using inventory to selling items. So I thought if I would alter all DestroyObject commands to set local int on item, then I would be able to tell if the item was sold to store or destroyed. Problem is Im not sure if there isnt any other potentional risk that could PC lose his items other than via DestroyObject which would have same symptoms (not valid object when UnAcquire).

Anyone know?
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Selling to store infinite goods
« Reply #1 on: July 26, 2010, 04:37:16 pm »


               Not sure what you even said there...let me see if this would help.



Add onAquire a int to every item the pc gets. Call it PCITEM int 1.



Then everything that is sold to a store, when a store closes it destroys any item that has a PCITEM int 1 on it. We do it via on Area exit script though so after the third time the store is open by a player it clears all the itmes and remakes the store.



Would that be something that would help or did I miss the whole set up of the question and am way off base?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Selling to store infinite goods
« Reply #2 on: July 26, 2010, 05:06:52 pm »


               sorry for poor explanatiion, so again...

If you try to sell item that is already in store and has infinite flag, this item is immediately destroyed. Thats why I cant increase count of this item in store. The same behaviour has DestroyObject, but I can control DestroyObject and set integer on Item before I will destroy it, so in theory my UnAcquire script would look like

object oItem = GetModuleItemLost();
 if(!GetIsObjectValid(oItem))
  {
    if(!GetLocalInt(oItem,"DestroyObject"))
    {
    //now this should happen only when PC sell item to store
    object oPC = GetModuleItemLostBy();
    object oStore = GetLocalObject(oPC,"OPENED_STORE");
      if(oStore != OBJECT_INVALID)
      {
      string sResRef = GetLocalString(oItem,"GetResRef");
      ExecuteScript("sh_store_bought",OBJECT_SELF);
      }
    }
  }
 }

But thats only in theory, Im asking if anyone knows what else could destroy item, so my script would not work correctly.
               
               

               


                     Modifié par ShaDoOoW, 26 juillet 2010 - 04:12 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Selling to store infinite goods
« Reply #3 on: July 26, 2010, 05:46:30 pm »


               Can Disturbed Inventory Work?
               
               

               
            

Legacy_the.gray.fox

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Selling to store infinite goods
« Reply #4 on: July 26, 2010, 06:15:42 pm »


               Hello.



Once DestroyObject() has destroyed an item, _all_ info about that item are permanently lost.

Local variables too are gone. And you can not perform any query of any type on the destroyed item.

The one thing that remains is the former OID of the object.



So, at best you can tell that the item was destroyed by DestroyObject() because the OnUnAcquireItem event will fire. You receive a valid-looking OID, but the function GetIsObjectValid() shall return FALSE for it. And that is how you can tell that the object unacquired was destroyed by DestroyObject().



If you want to keep track of an object destroyed by DestroyObject(), you have only 1 option.

You must keep a list of all objects you are interested into. And when you unacquire something, and you determine that it was destroyed by DestroyObject(), you compare the OID of the object against the OIDs you have saved in your list.

And that is how you can tell exactly what was just destroyed.



I know it looks ugly...





-fox
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Selling to store infinite goods
« Reply #5 on: July 26, 2010, 06:18:25 pm »


               

Genisys wrote...

Can Disturbed Inventory Work?

stores dont have this event, also Im not certain I want to workaround the selling via placeable/creature inventory. Also you can open via script  only inventory of familiar and henchman.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Selling to store infinite goods
« Reply #6 on: July 26, 2010, 06:22:39 pm »


               

the.gray.fox wrote...

Local variables too are gone.

Ah shame... guess i will use another way to do it then.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Selling to store infinite goods
« Reply #7 on: July 26, 2010, 10:15:27 pm »


               Do you have to have the Infinite flag marked on your items.

When My computer crashed awhile back I was messing with making a player store system. Lost most of my code and have not gotten back into it full strength yet. Never had any infinite items in them, so am not cretin as to the problems you are running into.


the.gray.fox wrote...

Once DestroyObject() has destroyed an item, _all_ info about that item are permanently lost.


Yes once an object is destroyed it can not be accessed. How ever the DestroyObject is a delayed command. So the object should not be destroyed until after the current script finishes, Even at a delay of 0.0f. If it is somehow getting destroyed with the 0.0f delay just increase the delay a little to make sure it sticks around until you are done with it.

There is no need to check for an open store. If the store is receiving an item and the OnUnquire Event is running some has to have it open. unless of course you are moving items to the store from a storage creature via ActionCommands.

When I did my player store test runs i was using a test against the tag of the store. Like this.

object oItem = GetModuleItemAcquired();
if (GetTag(GetModuleItemAcquiredFrom())=="PS_STORE_001")
   SendMessageToPC(GetFirstPC(),"Received Item From Player Store");

It would be just as easy to hook all items Taken by the store this way.


object oItem = GetModuleItemAcquired();
if (GetObjectType(GetModuleItemAcquiredFrom())==OBJECT_TYPE_STORE)
   SendMessageToPC(GetFirstPC(),"Received Item From a Store");

For Items sold to the store with a tag check I used:

object oItem = GetModuleItemLost();
if (GetTag(GetItemPossessor( oItem ))== "PS_STORE_001")
   SendMessageToPC(GetFirstPC(),"Sold Item To Player Store");

Again for a hook of all stores just as easy.(lol, I may say easy but it took me a long time to work it out.

object oItem = GetModuleItemLost();
if ( GetObjectType(GetItemPossessor( oItem ))== OBJECT_TYPE_STORE)
   SendMessageToPC(GetFirstPC(),"Sold Item To a Store");


If you wanted to have infinite Items in the store without having the inifinite flag set you could just recreate them if they where bought from the store.

In short if you wanted infinite items without having to set the Flag you could just add the item back into the store if it was ever bought. (keep in mind however that stackable items also have a mind of there own. If they get stacked with other items of there type they talk on the vars of the item they where stacked with. and lose there own. I also do not know if the Event even fires if a new stack is not created on the PC). So for inifinite nonstackable items.

object oItem = GetModuleItemAcquired();
object oStore= GetModuleItemAcquiredFrom();
if (GetObjectType(oStore)==OBJECT_TYPE_STORE)
{
    if (GetLocalInt(oItem,"inifinite"))
    {
        object oNewItem=CopyItem(oItem,oStore,TRUE);
        DeleteLocalInt(oItem,"inifinite");
    }
}

 
               
               

               


                     Modifié par Lightfoot8, 26 juillet 2010 - 09:24 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Selling to store infinite goods
« Reply #8 on: July 26, 2010, 11:13:14 pm »


               

Lightfoot8 wrote...
If you wanted to have infinite Items in the store without having the
inifinite flag set you could just recreate them if they where bought
from the store. 

It did came into my mind, but I thought that it will not work correctly because when you buy it other items aroun this item will make tetris (lol i dont know how to describe it, not so good in english), but nope its not visible, so player wont recognize that and that exactly what I want. So thanks, I got the scripting already, just find out the GetModuleItemLost is invalid so it didnt worked.
               
               

               
            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
Selling to store infinite goods
« Reply #9 on: July 26, 2010, 11:23:53 pm »


               The easiest way would most likely be to disable infinite stocks then simply copy the items into the stores inventory when purchased.

In OnAquire:

void main()
{
//Declare Variables
object oPC=GetModuleItemAcquiredBy();
object oItem=GetModuleItemAcquired();
object oStore=GetModuleItemAcquiredFrom();

if (GetObjectType(oStore)==OBJECT_TYPE_STORE)
{
//Spawn object that was sold into store's inventory.
CopyItem(oItem,oStore);
}

}


I'm sure there's a way to do it without disabling infinite stocks but it'll probably be a headache.