Persistent Database in NWN:EE
Valeriya
Member Posts: 57
I'm developing a PW and currently the main missing ingredient is persistent database. I assume that if I don't have a server database set up, then nothing is saved including the characters the players create. Is that correct?
What would you recommend I use for a database? I'm running windows. Should I use NWNX (which is apparently only available on Linux) with "Docker" (a linux simulator)?
I'm trying to implement CNR/HCR, so player crafting skills and their last known location for example is also something that needs to be recorded somewhere so after the server restarts it remembers it.
What would you recommend I use for a database? I'm running windows. Should I use NWNX (which is apparently only available on Linux) with "Docker" (a linux simulator)?
I'm trying to implement CNR/HCR, so player crafting skills and their last known location for example is also something that needs to be recorded somewhere so after the server restarts it remembers it.
0
Comments
https://github.com/mtijanic/nwnxlite
All this does is allow you to connect NWN to MySQL on Windows and execute your SQL queries.
If you find this pointlessly complicated, you can just go with the built-in database with the {Get,Set}Campaign{Int,Float,String,Object} functions. They work reasonably well for small servers.
You can also use these wrappers, which make it trivial for you to switch from the built-in to SQL later, without changing your code:
https://neverwintervault.org/project/nwn1/script/persistence-facade-ee
That's not quite correct. The characters the players create are saved, their XP/levels are saved, their entire inventory is saved. CNR can be configured to be saved without the database, but it's better if it goes in the database.
More scripting specific, local variables on the player object are not saved, but local variables on items in the player's inventory (including the hidden ones, like the character 'skin') are saved, and can be used for persistence as well.
BTW I used The Get,Set Campaign functions and it works fine; pretty fast too. It only takes like half a second to update, I don't get why people prefer NWNX for database (I do understand that NWNX can help change the core game I just have no need for that at the moment...wondering about it purely from a database PoV).
mysql also lets you have relational tables and SQL queries that greatly simplify a lot of things. For example, suppose you want to make a loot system; you make one chest where you can put items that will show up as loot, with a script like:
// CREATE TABLE loot ( INT id PRIMARY KEY AUTO_INCREMENT, INT value, TEXT item ); NWNX_SQL_PrepareQuery("INSERT INTO loot VALUES(?,?)"); NWNX_SQL_PreparedInt(0, GetGoldPieceValue(oLootItem); NWNX_SQL_PreparedObjectFull(1, oLootItem);
And then when you want a piece of loot, you have:
object SpawnLoot(object oOwner, int nLowPrice, int nHighPrice) { NWNX_SQL_ExecuteQuery("SELECT item FROM loot WHERE value >= " + IntToString(nLowPrice) + " AND value <= " + IntToString(nHighPrice) + " ORDER BY RAND() LIMIT 1"); return NWNX_SQL_ReadFullObjectInActiveRow(0, oOwner); }
You can then add stuff like item types so you only spawn weapons, etc. Or sets of items, so goblins spawn different than elves.
What I wanna say is, it opens many other possibilities that a basic persistence mechanism does not have. A lot of servers are built with the SQL being the central pillar and everything is controlled from it. That way, you can also live edit the data from an external program and have the changes show up in game without any restart.