View previous topic :: View next topic |
Author |
Message |
Anya
Joined: 22 May 2007 Posts: 6
|
Posted: Tue May 22, 2007 5:43 Post subject: Converting scripts to NWNX for existing mod. |
|
|
I am trying to convert my mod to using the NWNX database. I created a table for pwdata and pwobjdata using the tables from the demo. So far I have gotten it to work for saving my players locations with pwdata, but the pwobjdata does not seem to be working.
This is my code which I have converted, using pretty much the same method I did for pwdata. The commented out script is the origional setup.
Code: |
// Used to save an item location.
void SaveCorpse( object oItem) {
else.
if( GetResRef( oItem) == PC_CORPSE_ITEM && !GetIsPC(GetItemPossessor(oItem)))
{
int nIndex = GetPersistentInt(oItem, CorpseDBCount, "pwobjdata") + 1;
//GetCampaignInt(CorpseDB, CorpseDBCount) + 1;
SetLocalInt(oItem, CorpseLocalIndex, nIndex);
StoreCampaignObject("pwobjdata", CorpseDBArray + IntToString(nIndex), oItem);
SetPersistentLocation(oItem, CorpseDBLocationArray + IntToString(nIndex), GetLocation(oItem), 0, "pwobjdata");
//SetCampaignLocation(CorpseDB, CorpseDBLocationArray + IntToString(nIndex),GetLocation(oItem));
SetPersistentInt(oItem, CorpseDBCount, nIndex, 0, "pwobjdata");
//SetCampaignInt(CorpseDB, CorpseDBCount, nIndex);
}
}
|
Did I make a little mistake somewhere? Or am I going about it completely wrong? Any help will be very appreciated. |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Tue May 22, 2007 7:01 Post subject: |
|
|
Is this NWNX2 or NWNX4? If NWNX4, the object persistence is not yet implemented. _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
Anya
Joined: 22 May 2007 Posts: 6
|
Posted: Tue May 22, 2007 7:26 Post subject: |
|
|
I am using NWNX2. |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Tue May 22, 2007 8:01 Post subject: |
|
|
Does your script even compile ? _________________ Papillon |
|
Back to top |
|
|
Anya
Joined: 22 May 2007 Posts: 6
|
Posted: Wed May 23, 2007 3:36 Post subject: |
|
|
I don't know how that else got there. Its not even in my origional script.
And..oops I don't know why I put that script there. The saving part seems to be working. Its the actual calling the object back after mod load that is not.
Here is the mod load script I converted, which I really think I didn't do right...
Code: |
#include "aps_include"
void main()
{
SQLInit();
SetLocalString( GetModule(), "X2_S_UD_SPELLSCRIPT", "_spell_hook");
object oMod = GetModule();
object oCorpse = OBJECT_INVALID;
location lCorpse;
int nCount = 0;
int nIndex = GetPersistentInt(oCorpse, CorpseDBCount, "pwobjdata");
//GetCampaignInt(CorpseDB, CorpseDBCount);
while ( nIndex > 0 )
{
lCorpse = GetPersistentLocation(oCorpse, CorpseDBLocationArray + IntToString(nIndex), "pwobjdata");
//lCorpse = GetCampaignLocation(CorpseDB, CorpseDBLocationArray + IntToString(nIndex));
oCorpse = RetrieveCampaignObject("pwobjdata", CorpseDBArray + IntToString(nIndex), lCorpse);
DeletePersistentVariable(oCorpse, CorpseDBLocationArray + IntToString(nIndex), "pwobjdata");
//DeleteCampaignVariable(CorpseDB, CorpseDBLocationArray + IntToString(nIndex));
DeletePersistentVariable(oCorpse, CorpseDBArray + IntToString(nIndex), "pwobjdata");
//DeleteCampaignVariable(CorpseDB, CorpseDBArray + IntToString(nIndex));
if ( oCorpse != OBJECT_INVALID )
{
nCount++;
SetLocalObject(oMod, CorpseDBArray + IntToString(nCount), oCorpse);
SetLocalLocation(oMod, CorpseDBLocationArray + IntToString(nCount), lCorpse);
}
nIndex--;
}
SetPersistentInt(oCorpse, CorpseDBCount,nCount, 0, "pwobjdata");
//SetCampaignInt(CorpseDB, CorpseDBCount, nCount);
while ( nCount > 0 )
{
oCorpse = GetLocalObject(oMod, CorpseDBArray + IntToString(nCount));
lCorpse = GetLocalLocation(oMod, CorpseDBLocationArray + IntToString(nCount));
StoreCampaignObject("pwobjdata", CorpseDBArray + IntToString(nCount), oCorpse);
SetPersistentLocation(oCorpse, CorpseDBLocationArray + IntToString(nCount), lCorpse, 0, "pwobjdata");
//SetCampaignLocation(CorpseDB, CorpseDBLocationArray + IntToString(nCount),lCorpse);
SetLocalInt(oCorpse, CorpseLocalIndex, nCount);
nCount--;
}
}
|
This is what I get after save has been initiated
o Logfile maximum size limit is: 524288 bytes
o Log level: Everything will be logged.
o Using SQLite connection.
o Hooking SCO....hooked at 5d3560
o Hooking RCO....hooked at 5d3440
o Connect successful.
o Got request: SELECT val FROM pwobjdata WHERE player='~' AND tag='' AND name='CorpseCount'
o Sent response (1 bytes): 0
o Got request: SELECT player FROM pwobjdata WHERE player='~' AND tag='' AND name='CorpseCount'
o Sent response (1 bytes): ~
o Got request: UPDATE pwobjdata SET val='0',expire=0 WHERE player='~' AND tag='' AND name='CorpseCount'
o Got request: SELECT val FROM pwdata WHERE player='AnyaTatsuya' AND tag='Anya Tatsuya' AND name='AnyaTatsuya'
o Sent response (140 bytes): #AREA#Athkatla#POSITION_X# 168.263092041#POSITION_Y# 109.144638062#POSITION_Z# 0.000000000#ORIENTATION# 141.183074951#END#
o Got request: SELECT val FROM pwobjdata WHERE player='~' AND tag='QV6A76CRAnyaTatsuyaAnyaTatsuya' AND name='CorpseCount'
o Sent response (1 bytes): 4
o Got request: SELECT player FROM pwobjdata WHERE player='~' AND tag='QV6A76CRAnyaTatsuyaAnyaTatsuya' AND name='CorpseLocation5'
o Sent response (0 bytes):
o Got request: INSERT INTO pwobjdata (player,tag,name,val,expire) VALUES('~','QV6A76CRAnyaTatsuyaAnyaTatsuya','CorpseLocation5','#AREA#Athkatla#POSITION_X# 164.770401001#POSITION_Y# 106.165122986#POSITION_Z# 0.000000000#ORIENTATION# 199.515625000#END#',0)
o Got request: SELECT player FROM pwobjdata WHERE player='~' AND tag='QV6A76CRAnyaTatsuyaAnyaTatsuya' AND name='CorpseCount'
o Sent response (1 bytes): ~
o Got request: UPDATE pwobjdata SET val='5',expire=0 WHERE player='~' AND tag='QV6A76CRAnyaTatsuyaAnyaTatsuya' AND name='CorpseCount'
This is what I get after reloading the mod.
o Logfile maximum size limit is: 524288 bytes
o Log level: Everything will be logged.
o Using SQLite connection.
o Hooking SCO....hooked at 5d3560
o Hooking RCO....hooked at 5d3440
o Connect successful.
o Got request: SELECT val FROM pwobjdata WHERE player='~' AND tag='' AND name='CorpseCount'
o Sent response (1 bytes): 0
o Got request: SELECT player FROM pwobjdata WHERE player='~' AND tag='' AND name='CorpseCount'
o Sent response (1 bytes): ~
o Got request: UPDATE pwobjdata SET val='0',expire=0 WHERE player='~' AND tag='' AND name='CorpseCount'
o Got request: SELECT val FROM pwdata WHERE player='AnyaTatsuya' AND tag='Anya Tatsuya' AND name='AnyaTatsuya'
o Sent response (140 bytes): #AREA#Athkatla#POSITION_X# 168.263092041#POSITION_Y# 109.144638062#POSITION_Z# 0.000000000#ORIENTATION# 141.183074951#END#
o Disconnecting from database. |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Thu May 24, 2007 23:03 Post subject: |
|
|
Code: |
object oCorpse = OBJECT_INVALID;
int nIndex = GetPersistentInt(oCorpse, CorpseDBCount, "pwobjdata");
|
1. You are storing data on an invalid object. I'd use GetModule() in the call to GetPersistentInt and all subsequent calls that accesses general (i.e. not object specific) data.
2. The pwobjdata table is just for storing binary object data. For normal variables, just omit the parameter and it will use the default table "pwdata".
Code: |
RetrieveCampaignObject()
|
This is not the NWNX function to retrieve object data. Use GetPersistentObject from aps_include instead. Same for StoreCampaignObject().
These are just some quick hints to get you started. In general, I would consider to rewrite to whole script to make it more 'SQLish'. You are using kludges by just converting it 1:1, that aren't really necessary with SQL... _________________ Papillon |
|
Back to top |
|
|
Anya
Joined: 22 May 2007 Posts: 6
|
Posted: Sat May 26, 2007 3:56 Post subject: |
|
|
Thank you, for the information. I think I'll get started on rewriting that script. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|