Author Topic: Fetching multiple items with RetrieveCampaignObject  (Read 395 times)

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« on: January 10, 2012, 01:18:50 am »


               Hi,

I wonder if there is a better way of doing this than calling the DB(MySQL) via RetrieveCampaignObject() for each item, in a loop, since upon retrieving, say, 150 items to fill a store, it makes lots of DB calls.

Thanks for any info!


Kato
 
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« Reply #1 on: January 10, 2012, 01:33:35 am »


               I am kind of a fish out of water when it comes to MySQL, since I dont use it.   Form your previous post however I am guessing that you decided against the Idea of storing the items on a creature and retriving the items that way.   May i ask why you do not like that method?
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« Reply #2 on: January 10, 2012, 01:40:30 am »


               

Lightfoot8 wrote...

I am kind of a fish out of water when it comes to MySQL, since I dont use it.   Form your previous post however I am guessing that you decided against the Idea of storing the items on a creature and retriving the items that way.   May i ask why you do not like that method?


Well, since NPCs cannot carry much items, mostly when they're big like armors etc... I would need many NPCs to contain all the items for each store, thus it looked ugly at first sight considering all the potential operations invloved, yet I may be wrong on this...


Kato
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« Reply #3 on: January 10, 2012, 01:58:36 am »


               I agree with Lightfoot8

The code is a bit more complicated, but it does reduce db calls by a lot if you use the creature inventory trick.

Make an invisible creature. Make a loop that fills its inventory. Save the creature to the db. Create the next creature and repeat until you are finished.
Reverse the process to get all of the items back.
It does seem messy... In fact, it is messy.

However, if you want to speed things up, this is the best way I know of.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« Reply #4 on: January 10, 2012, 02:00:47 am »


               I have not worked it all out either. I guess it comes down to the order the events fire in, for packing the items onto the NPC. Could it be as simple as when you create the item into the NPC's inventory, A check to see if the npc has the item or not. ( It hit the ground ) determins if another one needs to be created?

As far as the NPC themselves, If they aquire all of there inventory before the OnSpawn event. (not sure it has been awhile since I have looked at the orderof the events, again) Place a script in there OnSpawn event that just moves all of there inventory to a store refferenced by a local on the NPC. That way all you have to do is spawn the NPC and you are done. An additinal benifit that I see is that Items may get auto stacked for you in the NPC inventory.

The disadvantage I see, is that it will be harder to loop through the list in the DB to see what is in it.

EDIT:  I forgot to say have the NPC destroy himself after moving the items.
               
               

               


                     Modifié par Lightfoot8, 10 janvier 2012 - 02:02 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« Reply #5 on: January 10, 2012, 02:05:43 am »


               Okay, I'll consider all this, many thanks for the infos '<img'>


Kato
               
               

               


                     Modifié par Kato_Yang, 10 janvier 2012 - 02:09 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« Reply #6 on: January 10, 2012, 02:19:08 am »


               lol.  I just thought of a major flaw in my plan.   How would you spawn the NPC to place the items on him.  He would destroy himself.  

Answer: If no local is on the NPC or no items in his inventory he is a new PackRat and does nothing.   If the local is there.  1 Place all items in that object. 2. Check to see if he has an underling in the DB and summons him if he does.   3. Destroy self.  

For a new NPC(No Items/Local)   Place a Userdefined Event on him.  A custom function can set the Local on the NPC and signal the event.  The UserDefined Event  Checks the local.  copys all items from that Object to Self.  If one is dropped.  Summons an underling,  Gives him the dropped item, signials the User Event on him, Stores himself in the DB and self destructs.  

Sorry, Just thinking out loud.
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Fetching multiple items with RetrieveCampaignObject
« Reply #7 on: January 10, 2012, 02:38:16 am »


               Thank you once more, Lightfoot.


Kato