Author Topic: Inventories and Magic Bags  (Read 786 times)

Legacy_Sadira of Tyr

  • Sr. Member
  • ****
  • Posts: 299
  • Karma: +0/-0
Inventories and Magic Bags
« on: September 09, 2012, 12:12:23 am »


               I'm not sure if this is the best place to ask this, so please move it if I am wrong.

Our server has been crashing a lot lately. About once every one to three days. We believe it may be linked to character inventories. Is it possible that characters with too many filled magic bags can crash a server? also are there any known bugs that involve character inventories? Thank you for any help you may provide.
               
               

               
            

Legacy_acomputerdood

  • Sr. Member
  • ****
  • Posts: 378
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #1 on: September 09, 2012, 02:57:54 am »


               enormous inventories can definitely drain the server's resources.  i don't know exact numbers, and i'd imagine that the only study done on it would have been years ago.  presumably one might this this wasn't an issue anymore with more modern computers, but you never know.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #2 on: September 09, 2012, 07:58:18 am »


               

Sadira of Tyr wrote...

I'm not sure if this is the best place to ask this, so please move it if I am wrong.

Our server has been crashing a lot lately. About once every one to three days. We believe it may be linked to character inventories. Is it possible that characters with too many filled magic bags can crash a server? also are there any known bugs that involve character inventories? Thank you for any help you may provide.

nope i dont think so, definitely shouldnt crash because that, it fires one script for every item each time player log in this character but thats not really an issue
               
               

               


                     Modifié par ShaDoOoW, 09 septembre 2012 - 07:08 .
                     
                  


            

Legacy_Khuzadrepa

  • Sr. Member
  • ****
  • Posts: 347
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #3 on: September 10, 2012, 05:16:33 am »


               

Sadira of Tyr wrote...

I'm not sure if this is the best place to ask this, so please move it if I am wrong.

Our server has been crashing a lot lately. About once every one to three days. We believe it may be linked to character inventories. Is it possible that characters with too many filled magic bags can crash a server? also are there any known bugs that involve character inventories? Thank you for any help you may provide.

It can definitely contribute.  I've seen this on several PWs... a player logs in, and the server is brought to a grinding halt for some amount of time.  Usually, the server recovers, and play continues... but not always.  If this is what you are experiencing, then you might be on the right track.

Check your OnEnter and OnAcquire scripts for optimization.  Also, are you using Creature Skins on your players?

It's also not a bad step to have players reduce their inventory, especially containers.  If you don't have one already, maybe give them some kind of other persistent storage option?
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #4 on: September 10, 2012, 06:05:03 am »


               My server has a small script on client enter that, if not run already after the last reset, counts a PC's inventory items and writes it to the server log.  Many of my players are pack-rats.  Most seem to carry an average of 75-150 items.  A few carry over 800.  And this is in addition to persistent storage chests.

In the servervault, I can see which player files belong to pack-rats.  The .bic files of such characters tend to run in the 350-500 kb size range. Yup, loading in a 1/2 MB character file, before the server runs their entire inventory and associated on-acquire script checks. ':whistle:'

I think I'm going to start having the script actually give this number to PCs in-game.  It might influence some of them to clear their inventory of some things they never use.
               
               

               


                     Modifié par The Amethyst Dragon, 10 septembre 2012 - 05:07 .
                     
                  


            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #5 on: September 10, 2012, 10:36:37 pm »


               AD, I suspect that would actually help somewhat, assuming they know that hauling around so much stuff causes problems. There is some psychology that indicates people will respond to feedback and metrics about possible misbehavior, even when the feedback is automated and otherwise unmonitored and carries no penalty. That's why there are so many of those "Your speed" radar signs on roads that show the speed of the car as it approaches. It turns out that, if you put one of those right near the speed limit sign, speeders do slow down. ':whistle:'
               
               

               


                     Modifié par MrZork, 10 septembre 2012 - 09:37 .
                     
                  


            

Legacy_Sadira of Tyr

  • Sr. Member
  • ****
  • Posts: 299
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #6 on: September 11, 2012, 12:04:26 am »


               Thanks guys! I appreciate the help. 'Posted

We do have some players with a lot of bags, and crashes usually occur while players are selling items.

We do use creature skins for our undead subraces. Does that make it worse?

Our module on client enter script also excutes our subrace script, which adds properties to creature skins for undead characters.
               
               

               


                     Modifié par Sadira of Tyr, 10 septembre 2012 - 11:33 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #7 on: September 11, 2012, 12:59:19 am »


               Creature skins on PCs shouldn't be that hard on a server.  It's only one item on the PC.  The game having to handle hundreds of items in PC and merchant inventories, that one's hard on the server.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #8 on: September 11, 2012, 05:08:30 am »


               Would it be worth it to escape out of the OnAcquire script when a player is logging in?

I'd flag a player OnClient enter.
And then delay deletion of the flag by one second.

If the flag is set, OnAcquire immediately exits.

Make sense? Or is this a waste of code?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #9 on: September 11, 2012, 05:18:52 am »


               I guess it depends on how much you do in the OnAquire event And if you need the scripts to set thing up or not.   Still if memory serves me correctly, All of the items are aquired before the OnEnter script ever fires.  If they where not, there would be no way of stripping player of there items in that event.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #10 on: September 11, 2012, 05:27:34 am »


               Well if a a PC has 500 items in inventory, it would be nice to avoid running OnAcquire 500 times when they are logging in. Or do I misunderstand how this event works?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #11 on: September 11, 2012, 05:41:16 am »


               Yes, It would be nice, If it was not needed in the module. But the question is:

Would the check of the local, to stop the running, be that much quicker the the standard TagBased script. 99% of the items aquired will not have a TBS after all.
 
Now if the OnAquire is the old style.  A bunch of chained if... else if... statments.  then yes I can see it being quite a drain.
               
               

               


                     Modifié par Lightfoot8, 11 septembre 2012 - 04:43 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #12 on: September 11, 2012, 12:51:09 pm »


               

Lightfoot8 wrote...

I guess it depends on how much you do in the OnAquire event And if you need the scripts to set thing up or not.   Still if memory serves me correctly, All of the items are aquired before the OnEnter script ever fires.  If they where not, there would be no way of stripping player of there items in that event.

Yes the OnAcquire, possibly OnEquip runs before the OnClientEnter script.

This is however easy to distinguish via local variable on module like this:

SetLocalInt(OBJECT_SELF,ObjectToString(oPC),1/0) in client enter/exit

there are also some other remarks such as that the oPC isnt valid object (but neither invalid), but im now not sure if that applies in all cases or just after first login atm
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #13 on: September 11, 2012, 04:58:27 pm »


               Inventories on players were designed with large quantities of items in mind.
I have a script that processes player inventories on player join, and to maximize performance, I store a local int on the item itself to say whether it has been harvested.
When finished with the items - I set the local int on the player to say he has been processed.

Variables on players only persist until a server restart - but this is by design, it means that next time I process the player - it will only capture/process items that do NOT have the harvested int set.
Meaning it will capture new items that were collected between the last login of the player in the last server instance.

Granted - you are saying that you are getting poor performance just on player login -
Yes onAcquire definitely fires.
Its ony of those things that sorta follows an xml/tree diagram.

When a Player logs in, their creature object is created,
the inventory items are all created from the serialized data inside the bic file.
But creating the inventory items is not enough - they need to be 'given' to the creature, in order for them to be valid objects.

Player logs in
Creature Created
Creature Inventory Created
Items Loaded into Inventory - trigger on Acquired per item
Any items going into slots - trigger the onEquipped per item in live slot.
onClientJoin probably fires here or above.
Creature Added to area
Area Enter Script fires


Best example of this heirarcy is spawning a creature via DM Creator.
When you spawn the creature
it spawns the Creature, Fires the onSpawnEvent - you will probably see the onAcquired event fire too, as well as the onAreaEnter event

There is an idea - you could create a creature - give it customized event scripts to SpeakString the name of its event.
Spawn the creature, and you would get alot of spam chat telling you what scripts were fired, and in what order.
(Since only one script can ever run at one time - it would tell you which event fires first, and which scripts are children of other scripts etc)


Anyway - kinda rambling now
If you feel that your onAcquired event is indeed the source of your trouble
You can tell it to ignore the player, until a certain INT value has been set on the player.

eg
onClientEnter

DelayCommand(10.00,SetLocalInt(oPlayer,"FULLY_JOINED",1));

Then in the onAcquire

object oPC = GetModuleItemAcquiredBy(); // think thats it?
if(!GetLocalInt(oPC,"FULLY_JOINED")) { return; }

This will exit out of the script, and discount onAcquired events during the players initial join.

Note - even the Tag Based scripting method - calls a script somewhere else
I think its in one of the X1_ or X2_ include files somewhere - if you follow the X2_default module scripts back for onModuleAcquire back far enough, you can find the actual parent function that fires the tag based script for individual items.

Or at least - I think I saw that once upon a time - I might have been high - but who knows.
               
               

               


                     Modifié par Baaleos, 11 septembre 2012 - 04:04 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Inventories and Magic Bags
« Reply #14 on: September 11, 2012, 05:34:09 pm »


               I like that method, Baelos. Thanks.

Set an onAcquire flag on an item, next time exit the event if the flag is already set. Very simple.