View previous topic :: View next topic |
Author |
Message |
JollyOrc
Joined: 15 May 2005 Posts: 10
|
Posted: Sun May 15, 2005 18:26 Post subject: Using NPCs as Persistant Chests |
|
|
Let me explain the general idea:
Using the Object Storage system of NWNx2, we can store NPCs in the database. With their complete inventory.
Now, the system we have come up with does the following:
- A player can buy a chest from a merchant. The merchant puts a chest placeable on the ground, and gives the player a key to it.
- the player can use the chest, which causes it to open. The script checks if this chest already has an NPC in the database assigned. If not, it creates one.
If yes, it retrieves it from the db and spawns it as an invisible NPC,attaches it as the players henchman and opens the henchmen inventory.
- when the player uses the chest again, it closes. The henchmen gets unattached, and the NPC gets written to the database, and despawned.
rinse repeat as the player puts stuff into the chest.
All this works nicely, Sindol even added functionality for moving the chest by picking it up and putting it down again, etc.
BUT: Every now and then, very infrequently, the NPC can't be fetched from the database. Aparently the database entry is "corrupt", and can't be read correctly. Thus, the script creates a completely new one, resulting in an empty chest, with the player loosing everything. Not nice.
The normal NPCs we store and retrieve undergo literally dozens of store-and-retrieve cycles every day, and we don't loose them. But then, they don't change their inventory as much. Does anyone have any idea what might cause this, or wants to have a closer look at everything ?
In this rar are the most important scripts this system uses, although not all. I will make a better package should someone want to go into details. |
|
Back to top |
|
|
Acrodania
Joined: 02 Jan 2005 Posts: 208
|
Posted: Sun May 15, 2005 19:34 Post subject: |
|
|
Try putting a delay on the "save" process of the chest object. It seems to take a certain amount of time to actually put the item in the chest and if you do it too quickly you might be copying an object with an invalid state...
There is a system on the vault that does something similar and works well, so the idea is sound |
|
Back to top |
|
|
wendel1978
Joined: 21 Apr 2005 Posts: 5
|
Posted: Fri May 20, 2005 18:39 Post subject: |
|
|
Did anyone ever reliably solve the issues for this system? We're talking about using npcs as chests in the #nwscript chat, and I would love to use this system.
Thanks!
W |
|
Back to top |
|
|
JollyOrc
Joined: 15 May 2005 Posts: 10
|
Posted: Thu Jun 02, 2005 16:38 Post subject: |
|
|
currently, no user has reported a corrupted chest... |
|
Back to top |
|
|
teleri
Joined: 28 Jan 2005 Posts: 21
|
Posted: Sat Jun 04, 2005 3:04 Post subject: |
|
|
wendel1978 wrote: | Did anyone ever reliably solve the issues for this system? We're talking about using npcs as chests in the #nwscript chat, and I would love to use this system.
Thanks!
W |
What server is that on? |
|
Back to top |
|
|
Alosynth
Joined: 06 Jan 2005 Posts: 24
|
Posted: Sun Jun 05, 2005 6:07 Post subject: |
|
|
If you mean what irc server #nwscript is on, I believe it is on irc.neverwinterconnections.com. |
|
Back to top |
|
|
Primogenitor
Joined: 08 Jan 2005 Posts: 88
|
Posted: Sun Jun 05, 2005 21:05 Post subject: |
|
|
One potential problem, NPCs have a finite inventory space but chests hold an infinite amount. |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Mon Jun 06, 2005 7:57 Post subject: |
|
|
I think it is not infinite, but limited to 15 pages or so. _________________ Papillon |
|
Back to top |
|
|
JollyOrc
Joined: 15 May 2005 Posts: 10
|
Posted: Mon Jun 06, 2005 9:24 Post subject: |
|
|
Primogenitor wrote: | One potential problem, NPCs have a finite inventory space but chests hold an infinite amount. |
well, RL chests don't hold infinite items either. |
|
Back to top |
|
|
Primogenitor
Joined: 08 Jan 2005 Posts: 88
|
Posted: Mon Jun 06, 2005 11:35 Post subject: |
|
|
The point I was making is that a player can put more items in a chest than an NPC can hold, the exact details are irrelevant. So take this example;
A player puts 27 suits of armor in their chest.
The script copies/moves those items to the NPC. However, the NPC cant hold all of them, so some drop to the floor.
The NPC is SCOd, server restarts, NPC is RCO'd.
Player goes to open their chest, items are copied back from the NPC, player finds that 7 suits of armor are missing and is not amused.
Its not an insurmountable problem, but its a potential issue I though people should be aware of. Its not strictly applicable to this process, since it works by attatching the NPC as a henchmen to the player, |
|
Back to top |
|
|
JollyOrc
Joined: 15 May 2005 Posts: 10
|
Posted: Mon Jun 06, 2005 12:05 Post subject: |
|
|
I remember the "putting more items in chest than chest has pages" issue. That happened a few times on Avlis.
If people put in more things than possible and don't see their stuff on the ground, it's their loss if you ask me. |
|
Back to top |
|
|
Alosynth
Joined: 06 Jan 2005 Posts: 24
|
Posted: Mon Jun 06, 2005 16:27 Post subject: |
|
|
I suppose you could put something in the unaquire event that will give the PC back any items the storage NPC's drop with a message saying there is no more room. |
|
Back to top |
|
|
JollyOrc
Joined: 15 May 2005 Posts: 10
|
Posted: Tue Mar 09, 2010 17:18 Post subject: |
|
|
hiya everyone
I'm still using this system (after the server was on hold for a few years) and still have a problem with it. But at least I've narrowed things down a bit:
The Problem seems to be that saving a NPC with a big inventory to the database takes time - sometimes >1 minute. If the PC reopens (and thus triggering a reload of the NPC) before it's fully saved, there's a problem.
Is there a way to check if a setpersistentobject has finished properly? |
|
Back to top |
|
|
Zebranky
Joined: 04 Jun 2006 Posts: 415
|
Posted: Wed Mar 10, 2010 17:31 Post subject: |
|
|
I'm pretty sure SetPersistentObject is synchronous, so that's unlikely to be the real cause. Could you store each object individually, along with the identity of the owner, and then recreate each object on the invisible NPC when you spawn it? _________________ Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/
<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.
<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for? |
|
Back to top |
|
|
JollyOrc
Joined: 15 May 2005 Posts: 10
|
Posted: Wed Mar 10, 2010 17:45 Post subject: |
|
|
Zebranky wrote: | I'm pretty sure SetPersistentObject is synchronous, so that's unlikely to be the real cause. Could you store each object individually, along with the identity of the owner, and then recreate each object on the invisible NPC when you spawn it? |
Probably, but it would certainly complicate the code quite a bit & necessitate quite a bit of rewriting - and I'd loose one of the cosmetic advantages (namely that the inventory stays sorted)
I do know for sure that if the server is under load or stressed, the chance of chest-content corruption rises. Also, it rises if there are lots of items in the chest (as opposed to just a few). |
|
Back to top |
|
|
|