Server Totals
Underdark - (8)
Mikona - (2)
Ferrell - (0)
Elysia - (0)
Le'Or - (0)
M'Chek - (0)
Deglos - (0)
Wilderness - (0)
Visimontium - (0)
Total players: 10
  • Pure, Spiritkin
    Album name: DM Events
    Uploaded by: Ronan
    Uploaded: Wed Aug 20, 2014 12:07 am

Links Menu

How to use RetrieveCampaignObject with FETCHMODE (nwnx odbc)

Moderators: Nighthawk4, Dungeon Masters

How to use RetrieveCampaignObject with FETCHMODE (nwnx odbc)

PostAuthor: soulforge3 » Wed Apr 26, 2017 4:18 pm


I'm not actually a player on Avlis, I'm working on a persistent world called SoulForge. It has been around quite some time without any changes but now I'd like to add a few things to it.
So this is a guest question, I hope that's alright. I spoke to the friendly people on Avlis IRC chat and I was informed about this topic here. I'll go ahead with my question now :)
My goal is to have a chest with persistent storage for items using nwnx2-linux and the odmbc plugin.
I have nwnx2 and plugins working, I have the db connection working, the table exists. I can store items in the database using this:
Code: Select all
void PersstorStoreNew(string sPlayerName, object oSource)
    sPlayerName = SQLEncodeSpecialChars(sPlayerName);
    string sSQL = "INSERT INTO persistent_storage (PlayerName, StorageName, Object) VALUES('"+sPlayerName+"', 'default', %s)";
    SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
    object oItem = GetFirstItemInInventory(oSource);
        StoreCampaignObject("NWNX", "-", oItem);
        oItem = GetNextItemInInventory(oSource);

The above part is working, I see the entries showing up in the db.

Now it would be nice to retrieve items again. This is what I got:
Code: Select all
void PersstorRetrieveNew(object oPC, object oDestination)
    string sPlayerName = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
    string sSQL = "SELECT Object from persistent_storage WHERE PlayerName = '"+sPlayerName+"' AND StorageName = 'default'";
    //SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
    object oItem = RetrieveCampaignObject("NWNX", "FETCHMODE", GetLocation(oDestination), oDestination);
        oItem = RetrieveCampaignObject("NWNX", "FETCHMODE", GetLocation(oDestination), oDestination);
        SendMessageToPC(oPC, "valid item");

This is not working. If I leave out the loop and the "FETCHMODE" I can retrieve a single object. This leads me to believe that either FETCHMODE is not working or more likely I'm using it wrong.
I would be happy about any pointers you can give me on this. Do you have anything for persistent item storage in place on Avlis? I don't necesarily need FETCHMODE to work, just a way to retrieve items from a sql resultset.
Thank you!

Posts: 2
Joined: Wed Apr 26, 2017 4:05 pm

Re: How to use RetrieveCampaignObject with FETCHMODE (nwnx o

PostAuthor: tizmo » Wed Apr 26, 2017 10:21 pm

Yes, we have a persistent chest system. I cannot directly give you the code, but here are a few things that you need to do:

- In your db table, store both a hash of the object and the object itself in 2 columns. Then when you insert the object, insert both the hash and object. Then when you want to get the object, query for the hash. If you want to allow for the storage of more than one of an item across your playerbase, instead of storing multiple object instances, you may want a separate table to store the hash, quantity, PC / container identification data. Then just store one object in the campaign object storage table.

- Don't use "FETCHMODE" to get the item, just use the "-" for the second argument like you have in the StoreCampaignObject() method.

- Don't do an SQLExecDirect() on the query to retrieve the object, you need to use SetLocalString(GetModule(),...) like you have commented there.

That should get you started.

Posts: 1360
Joined: Thu May 19, 2005 2:53 pm
Location: Washington, DC
Timezone: GMT-4

Re: How to use RetrieveCampaignObject with FETCHMODE (nwnx o

PostAuthor: soulforge3 » Fri Apr 28, 2017 9:21 pm

Thank you! It took me a little while to figure out and it was not the direction I was going in originally but I get it now :D
I already have working storage, just need to improve a few details.
Thanks again and also thank you Gorgon from IRC, if you read this.

Posts: 2
Joined: Wed Apr 26, 2017 4:05 pm

Re: How to use RetrieveCampaignObject with FETCHMODE (nwnx o

PostAuthor: PlasmaJohn » Wed May 17, 2017 7:58 pm

Hey there.

Avlis' persistent storage is all menu (conversation) based.

I've been a bit out of the loop as far as NWN stuff goes so the following may have been mitigated by the NWNX crowd. Container events fail spectacularly when reporting stacked items making them hilariously prone to duplication exploits. Much rage coding has been spent trying to work around it but ultimately I gave up and went with convo's.
Calvin: This is so cool!
Hobbes: This is so stupid.
User avatar
Team Member; Retired with Honors; Has a Tom Selleck Stache
Posts: 8822
Joined: Fri Dec 26, 2003 10:37 pm
Location: New Eden
Timezone: US/Eastern

Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Google [Bot]