logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
NWNX+Olanders realistic....
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Wed Jan 23, 2008 2:38    Post subject: NWNX+Olanders realistic.... Reply with quote

Hello,

Need help to setting up the "Olanders realistic system v4" working with
APS and NWNX instead of the NBDE that is default configuration.

Followin the guide to use the "Bentons persistent facade"
its gave me this error:

pf_aps_persist.nss(76): ERROR: THE IMPLEMENTATION OF
THE FUNCTION DOES NOT COINCIDE WITH THE DEFINITION.

The script is this one:



Code:
* Persistence Facade v1.2, by benton
This is the front-end for aps/nwnx
It just adds a few functions for HCR compatibility
*/
#include "aps_include"

// This is the table name were all HCR data for this module
// will be stored. If you're not using HCR, it's not used.
string sHCRTableName = "pwdata";

int GetPFCampaignInt(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
{ return GetPersistentInt(oPlayer, sVarName, sCampaignName); }

float GetPFCampaignFloat(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
{ return GetPersistentFloat(oPlayer, sVarName, sCampaignName); }

location GetPFCampaignLocation(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
{ return GetPersistentLocation(oPlayer, sVarName, sCampaignName); }

string GetPFCampaignString(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
{ return GetPersistentString(oPlayer, sVarName, sCampaignName); }

vector GetPFCampaignVector(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
{ return GetPersistentVector(oPlayer, sVarName, sCampaignName); }


void SetPFCampaignInt(string sCampaignName, string sVarName, int nInt,
object oPlayer=OBJECT_INVALID, int expire = 0)
{ SetPersistentInt(oPlayer, sVarName, nInt, expire, sCampaignName);}

void SetPFCampaignFloat(string sCampaignName, string sVarName, float flFloat,
object oPlayer=OBJECT_INVALID, int expire = 0)
{ SetPersistentFloat(oPlayer, sVarName, flFloat, expire, sCampaignName);}

void SetPFCampaignLocation(string sCampaignName, string sVarName, location locLocation,
object oPlayer=OBJECT_INVALID, int expire = 0)
{ SetPersistentLocation(oPlayer, sVarName, locLocation, expire, sCampaignName);}

void SetPFCampaignString(string sCampaignName, string sVarName, string sString,
object oPlayer=OBJECT_INVALID, int expire = 0)
{ SetPersistentString(oPlayer, sVarName, sString, expire, sCampaignName);}

void SetPFCampaignVector(string sCampaignName, string sVarName, vector vVector,
object oPlayer=OBJECT_INVALID, int expire = 0)
{ SetPersistentVector(oPlayer, sVarName, vVector, expire, sCampaignName);}

void DeletePFCampaignVariable(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
{ DeletePersistentVariable(oPlayer, sVarName, sCampaignName); }

void DestroyPFCampaignDatabase(string sCampaignName)
{ SQLExecDirect("DELETE from " + sCampaignName); }

// This does nothing in APS, because it doesn't support object storage
int StorePFCampaignObject(string sCampaignName, string sVarName, object oObject, object oPlayer=OBJECT_INVALID)
{ return 0; }

object RetrievePFCampaignObject(string sCampaignName, string sVarName, location locLocation,
object oOwner = OBJECT_INVALID, object oPlayer=OBJECT_INVALID)
{ return OBJECT_INVALID; }

//================== HCR compatibilty functions ===================//

// These functions are put in so HCR will compile and use the facade
void DeletePersistentString(object oTarget, string sName)
{ DeletePersistentVariable(oTarget, sName, sHCRTableName);}
void DeletePersistentInt(object oTarget, string sName)
{ DeletePersistentVariable(oTarget, sName, sHCRTableName); }
void DeletePersistentFloat(object oTarget, string sName)
{ DeletePersistentVariable(oTarget, sName, sHCRTableName); }
void DeletePersistentLocation(object oTarget, string sName)
{ DeletePersistentVariable(oTarget, sName, sHCRTableName); }
void DeletePersistentObject(object oTarget, string sName)
{ DeletePersistentVariable(oTarget, sName, sHCRTableName); }

// These do nothing in APS, because it doesn't support object storage
void SetPersistentObject(object oTarget, string sName, int iExpiration=0, string sTable="") {}
object GetPersistentObject(object oTarget, string sName, string sTable="")
{ return OBJECT_INVALID; }

// These do nothing in APS since all saving is done on-the-fly to DB
// They are put in so HCR will compile if this file is included with HCR
void PWDBSaveAll() {}
void PWDBSaveChanged() {}




The line is what gives the error:
void SetPersistentObject(object oTarget, string sName, int iExpiration=0, string sTable="") {}



And the aps_include:

Code:
// Name     : Avlis Persistence System include
// Purpose  : Various APS/NWNX2 related functions
// Authors  : Ingmar Stieger, Adam Colon, Josh Simon
// Modified : January 1st, 2005

// This file is licensed under the terms of the
// GNU GENERAL PUBLIC LICENSE (GPL) Version 2

/************************************/
/* Return codes                     */
/************************************/

const int SQL_ERROR = 0;
const int SQL_SUCCESS = 1;

/************************************/
/* Function prototypes              */
/************************************/

// Setup placeholders for ODBC requests and responses
void SQLInit();

// Execute statement in sSQL
void SQLExecDirect(string sSQL);

// Position cursor on next row of the resultset
// Call this before using SQLGetData().
// returns: SQL_SUCCESS if there is a row
//          SQL_ERROR if there are no more rows
int SQLFetch();

// * deprecated. Use SQLFetch instead.
// Position cursor on first row of the resultset and name it sResultSetName
// Call this before using SQLNextRow() and SQLGetData().
// returns: SQL_SUCCESS if result set is not empty
//          SQL_ERROR is result set is empty
int SQLFirstRow();

// * deprecated. Use SQLFetch instead.
// Position cursor on next row of the result set sResultSetName
// returns: SQL_SUCCESS if cursor could be advanced to next row
//          SQL_ERROR if there was no next row
int SQLNextRow();

// Return value of column iCol in the current row of result set sResultSetName
string SQLGetData(int iCol);

// Return a string value when given a location
string APSLocationToString(location lLocation);

// Return a location value when given the string form of the location
location APSStringToLocation(string sLocation);

// Return a string value when given a vector
string APSVectorToString(vector vVector);

// Return a vector value when given the string form of the vector
vector APSStringToVector(string sVector);

// Set oObject's persistent string variable sVarName to sValue
// Optional parameters:
//   iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
//   sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration =
                         0, string sTable = "pwdata");

// Set oObject's persistent integer variable sVarName to iValue
// Optional parameters:
//   iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
//   sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration =
                      0, string sTable = "pwdata");

// Set oObject's persistent float variable sVarName to fValue
// Optional parameters:
//   iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
//   sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration =
                        0, string sTable = "pwdata");

// Set oObject's persistent location variable sVarName to lLocation
// Optional parameters:
//   iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
//   sTable: Name of the table where variable should be stored (default: pwdata)
//   This function converts location to a string for storage in the database.
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration =
                           0, string sTable = "pwdata");

// Set oObject's persistent vector variable sVarName to vVector
// Optional parameters:
//   iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
//   sTable: Name of the table where variable should be stored (default: pwdata)
//   This function converts vector to a string for storage in the database.
void SetPersistentVector(object oObject, string sVarName, vector vVector, int iExpiration =
                         0, string sTable = "pwdata");

// Set oObject's persistent object with sVarName to sValue
// Optional parameters:
//   iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
//   sTable: Name of the table where variable should be stored (default: pwobjdata)
void SetPersistentObject(object oObject, string sVarName, object oObject2, int iExpiration =
                         0, string sTable = "pwobjdata");

// Get oObject's persistent string variable sVarName
// Optional parameters:
//   sTable: Name of the table where variable is stored (default: pwdata)
// * Return value on error: ""
string GetPersistentString(object oObject, string sVarName, string sTable = "pwdata");

// Get oObject's persistent integer variable sVarName
// Optional parameters:
//   sTable: Name of the table where variable is stored (default: pwdata)
// * Return value on error: 0
int GetPersistentInt(object oObject, string sVarName, string sTable = "pwdata");

// Get oObject's persistent float variable sVarName
// Optional parameters:
//   sTable: Name of the table where variable is stored (default: pwdata)
// * Return value on error: 0
float GetPersistentFloat(object oObject, string sVarName, string sTable = "pwdata");

// Get oObject's persistent location variable sVarName
// Optional parameters:
//   sTable: Name of the table where variable is stored (default: pwdata)
// * Return value on error: 0
location GetPersistentLocation(object oObject, string sVarname, string sTable = "pwdata");

// Get oObject's persistent vector variable sVarName
// Optional parameters:
//   sTable: Name of the table where variable is stored (default: pwdata)
// * Return value on error: 0
vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwdata");

// Get oObject's persistent object sVarName
// Optional parameters:
//   sTable: Name of the table where object is stored (default: pwobjdata)
// * Return value on error: 0
object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata");

// Delete persistent variable sVarName stored on oObject
// Optional parameters:
//   sTable: Name of the table where variable is stored (default: pwdata)
void DeletePersistentVariable(object oObject, string sVarName, string sTable = "pwdata");

// (private function) Replace special character ' with ~
string SQLEncodeSpecialChars(string sString);

// (private function)Replace special character ' with ~
string SQLDecodeSpecialChars(string sString);

/************************************/
/* Implementation                   */
/************************************/

// Functions for initializing APS and working with result sets

void SQLInit()
{
    int i;

    // Placeholder for ODBC persistence
    string sMemory;

    for (i = 0; i < 8; i++)     // reserve 8*128 bytes
        sMemory +=
            "................................................................................................................................";

    SetLocalString(GetModule(), "NWNX!ODBC!SPACER", sMemory);
}

void SQLExecDirect(string sSQL)
{
    SetLocalString(GetModule(), "NWNX!ODBC!EXEC", sSQL);
}

int SQLFetch()
{
    string sRow;
    object oModule = GetModule();

    SetLocalString(oModule, "NWNX!ODBC!FETCH", GetLocalString(oModule, "NWNX!ODBC!SPACER"));
    sRow = GetLocalString(oModule, "NWNX!ODBC!FETCH");
    if (GetStringLength(sRow) > 0)
    {
        SetLocalString(oModule, "NWNX_ODBC_CurrentRow", sRow);
        return SQL_SUCCESS;
    }
    else
    {
        SetLocalString(oModule, "NWNX_ODBC_CurrentRow", "");
        return SQL_ERROR;
    }
}

// deprecated. use SQLFetch().
int SQLFirstRow()
{
    return SQLFetch();
}

// deprecated. use SQLFetch().
int SQLNextRow()
{
    return SQLFetch();
}

string SQLGetData(int iCol)
{
    int iPos;
    string sResultSet = GetLocalString(GetModule(), "NWNX_ODBC_CurrentRow");

    // find column in current row
    int iCount = 0;
    string sColValue = "";

    iPos = FindSubString(sResultSet, "¬");
    if ((iPos == -1) && (iCol == 1))
    {
        // only one column, return value immediately
        sColValue = sResultSet;
    }
    else if (iPos == -1)
    {
        // only one column but requested column > 1
        sColValue = "";
    }
    else
    {
        // loop through columns until found
        while (iCount != iCol)
        {
            iCount++;
            if (iCount == iCol)
                sColValue = GetStringLeft(sResultSet, iPos);
            else
            {
                sResultSet = GetStringRight(sResultSet, GetStringLength(sResultSet) - iPos - 1);
                iPos = FindSubString(sResultSet, "¬");
            }

            // special case: last column in row
            if (iPos == -1)
                iPos = GetStringLength(sResultSet);
        }
    }

    return sColValue;
}

// These functions deal with various data types. Ultimately, all information
// must be stored in the database as strings, and converted back to the proper
// form when retrieved.

string APSVectorToString(vector vVector)
{
    return "#POSITION_X#" + FloatToString(vVector.x) + "#POSITION_Y#" + FloatToString(vVector.y) +
        "#POSITION_Z#" + FloatToString(vVector.z) + "#END#";
}

vector APSStringToVector(string sVector)
{
    float fX, fY, fZ;
    int iPos, iCount;
    int iLen = GetStringLength(sVector);

    if (iLen > 0)
    {
        iPos = FindSubString(sVector, "#POSITION_X#") + 12;
        iCount = FindSubString(GetSubString(sVector, iPos, iLen - iPos), "#");
        fX = StringToFloat(GetSubString(sVector, iPos, iCount));

        iPos = FindSubString(sVector, "#POSITION_Y#") + 12;
        iCount = FindSubString(GetSubString(sVector, iPos, iLen - iPos), "#");
        fY = StringToFloat(GetSubString(sVector, iPos, iCount));

        iPos = FindSubString(sVector, "#POSITION_Z#") + 12;
        iCount = FindSubString(GetSubString(sVector, iPos, iLen - iPos), "#");
        fZ = StringToFloat(GetSubString(sVector, iPos, iCount));
    }

    return Vector(fX, fY, fZ);
}

string APSLocationToString(location lLocation)
{
    object oArea = GetAreaFromLocation(lLocation);
    vector vPosition = GetPositionFromLocation(lLocation);
    float fOrientation = GetFacingFromLocation(lLocation);
    string sReturnValue;

    if (GetIsObjectValid(oArea))
        sReturnValue =
            "#AREA#" + GetTag(oArea) + "#POSITION_X#" + FloatToString(vPosition.x) +
            "#POSITION_Y#" + FloatToString(vPosition.y) + "#POSITION_Z#" +
            FloatToString(vPosition.z) + "#ORIENTATION#" + FloatToString(fOrientation) + "#END#";

    return sReturnValue;
}

location APSStringToLocation(string sLocation)
{
    location lReturnValue;
    object oArea;
    vector vPosition;
    float fOrientation, fX, fY, fZ;

    int iPos, iCount;
    int iLen = GetStringLength(sLocation);

    if (iLen > 0)
    {
        iPos = FindSubString(sLocation, "#AREA#") + 6;
        iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
        oArea = GetObjectByTag(GetSubString(sLocation, iPos, iCount));

        iPos = FindSubString(sLocation, "#POSITION_X#") + 12;
        iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
        fX = StringToFloat(GetSubString(sLocation, iPos, iCount));

        iPos = FindSubString(sLocation, "#POSITION_Y#") + 12;
        iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
        fY = StringToFloat(GetSubString(sLocation, iPos, iCount));

        iPos = FindSubString(sLocation, "#POSITION_Z#") + 12;
        iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
        fZ = StringToFloat(GetSubString(sLocation, iPos, iCount));

        vPosition = Vector(fX, fY, fZ);

        iPos = FindSubString(sLocation, "#ORIENTATION#") + 13;
        iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
        fOrientation = StringToFloat(GetSubString(sLocation, iPos, iCount));

        lReturnValue = Location(oArea, vPosition, fOrientation);
    }

    return lReturnValue;
}

// These functions are responsible for transporting the various data types back
// and forth to the database.

void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration =
                         0, string sTable = "pwdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oObject))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
        sTag = SQLEncodeSpecialChars(GetName(oObject));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oObject);
    }

    sVarName = SQLEncodeSpecialChars(sVarName);
    sValue = SQLEncodeSpecialChars(sValue);

    string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    if (SQLFetch() == SQL_SUCCESS)
    {
        // row exists
        sSQL = "UPDATE " + sTable + " SET val='" + sValue +
            "',expire=" + IntToString(iExpiration) + " WHERE player='" + sPlayer +
            "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
        SQLExecDirect(sSQL);
    }
    else
    {
        // row doesn't exist
        sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
            "('" + sPlayer + "','" + sTag + "','" + sVarName + "','" +
            sValue + "'," + IntToString(iExpiration) + ")";
        SQLExecDirect(sSQL);
    }
}

string GetPersistentString(object oObject, string sVarName, string sTable = "pwdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oObject))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
        sTag = SQLEncodeSpecialChars(GetName(oObject));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oObject);
    }

    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    if (SQLFetch() == SQL_SUCCESS)
        return SQLDecodeSpecialChars(SQLGetData(1));
    else
    {
        return "";
        // If you want to convert your existing persistent data to APS, this
        // would be the place to do it. The requested variable was not found
        // in the database, you should
        // 1) query it's value using your existing persistence functions
        // 2) save the value to the database using SetPersistentString()
        // 3) return the string value here.
    }
}

void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration =
                      0, string sTable = "pwdata")
{
    SetPersistentString(oObject, sVarName, IntToString(iValue), iExpiration, sTable);
}

int GetPersistentInt(object oObject, string sVarName, string sTable = "pwdata")
{
    string sPlayer;
    string sTag;
    object oModule;

    if (GetIsPC(oObject))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
        sTag = SQLEncodeSpecialChars(GetName(oObject));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oObject);
    }

    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    oModule = GetModule();
    SetLocalString(oModule, "NWNX!ODBC!FETCH", "-2147483647");
    return StringToInt(GetLocalString(oModule, "NWNX!ODBC!FETCH"));
}

void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration =
                        0, string sTable = "pwdata")
{
    SetPersistentString(oObject, sVarName, FloatToString(fValue), iExpiration, sTable);
}

float GetPersistentFloat(object oObject, string sVarName, string sTable = "pwdata")
{
    string sPlayer;
    string sTag;
    object oModule;

    if (GetIsPC(oObject))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
        sTag = SQLEncodeSpecialChars(GetName(oObject));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oObject);
    }

    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    oModule = GetModule();
    SetLocalString(oModule, "NWNX!ODBC!FETCH", "-340282306073709650000000000000000000000.000000000");
    return StringToFloat(GetLocalString(oModule, "NWNX!ODBC!FETCH"));
}

void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration =
                           0, string sTable = "pwdata")
{
    SetPersistentString(oObject, sVarName, APSLocationToString(lLocation), iExpiration, sTable);
}

location GetPersistentLocation(object oObject, string sVarName, string sTable = "pwdata")
{
    return APSStringToLocation(GetPersistentString(oObject, sVarName, sTable));
}

void SetPersistentVector(object oObject, string sVarName, vector vVector, int iExpiration =
                         0, string sTable = "pwdata")
{
    SetPersistentString(oObject, sVarName, APSVectorToString(vVector), iExpiration, sTable);
}

vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwdata")
{
    return APSStringToVector(GetPersistentString(oObject, sVarName, sTable));
}

void SetPersistentObject(object oOwner, string sVarName, object oObject, int iExpiration =
                         0, string sTable = "pwobjdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oOwner))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oOwner));
        sTag = SQLEncodeSpecialChars(GetName(oOwner));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oOwner);
    }
    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);

    if (SQLFetch() == SQL_SUCCESS)
    {
        // row exists
        sSQL = "UPDATE " + sTable + " SET val=%s,expire=" + IntToString(iExpiration) +
            " WHERE player='" + sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
        SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
        StoreCampaignObject ("NWNX", "-", oObject);
    }
    else
    {
        // row doesn't exist
        sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
            "('" + sPlayer + "','" + sTag + "','" + sVarName + "',%s," + IntToString(iExpiration) + ")";
        SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
        StoreCampaignObject ("NWNX", "-", oObject);
    }
}

object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata")
{
    string sPlayer;
    string sTag;
    object oModule;

    if (GetIsPC(oObject))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
        sTag = SQLEncodeSpecialChars(GetName(oObject));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oObject);
    }
    sVarName = SQLEncodeSpecialChars(sVarName);

    string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);

    if (!GetIsObjectValid(oOwner))
        oOwner = oObject;
    return RetrieveCampaignObject ("NWNX", "-", GetLocation(oOwner), oOwner);
}

void DeletePersistentVariable(object oObject, string sVarName, string sTable = "pwdata")
{
    string sPlayer;
    string sTag;

    if (GetIsPC(oObject))
    {
        sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
        sTag = SQLEncodeSpecialChars(GetName(oObject));
    }
    else
    {
        sPlayer = "~";
        sTag = GetTag(oObject);
    }

    sVarName = SQLEncodeSpecialChars(sVarName);
    string sSQL = "DELETE FROM " + sTable + " WHERE player='" + sPlayer +
        "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
    SQLExecDirect(sSQL);
}

// Problems can arise with SQL commands if variables or values have single quotes
// in their names. These functions are a replace these quote with the tilde character

string SQLEncodeSpecialChars(string sString)
{
    if (FindSubString(sString, "'") == -1)      // not found
        return sString;

    int i;
    string sReturn = "";
    string sChar;

    // Loop over every character and replace special characters
    for (i = 0; i < GetStringLength(sString); i++)
    {
        sChar = GetSubString(sString, i, 1);
        if (sChar == "'")
            sReturn += "~";
        else
            sReturn += sChar;
    }
    return sReturn;
}

string SQLDecodeSpecialChars(string sString)
{
    if (FindSubString(sString, "~") == -1)      // not found
        return sString;

    int i;
    string sReturn = "";
    string sChar;

    // Loop over every character and replace special characters
    for (i = 0; i < GetStringLength(sString); i++)
    {
        sChar = GetSubString(sString, i, 1);
        if (sChar == "~")
            sReturn += "'";
        else
            sReturn += sChar;
    }
    return sReturn;
}





Any idea? All help apreciatted.

Cheers and thanks for the advice for posting here Funky..
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Jan 23, 2008 4:22    Post subject: Reply with quote

// These do nothing in APS, because it doesn't support object storage
void SetPersistentObject(object oTarget, string sName, int iExpiration=0, string sTable="") {}
object GetPersistentObject(object oTarget, string sName, string sTable="")
{ return OBJECT_INVALID; }

The above do not describe the APS functions.

Looking at it, these lines should be comments only, as they would duplicate the entries from "aps_include"

Cheers
Gryphyn
Back to top
View user's profile Send private message
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Wed Jan 23, 2008 14:35    Post subject: Reply with quote

Hi Gryphyn an thanks for the fast response.

I have commented out this lines , and the lines that have slightly similarly and then build the module with no errors, but though the NWNX creates the sqlite database , but when im triying to take a look if there are some data in it with sqlite cc, nothing appears...theres no data!.

I spend one week with this issue, doing all kinds of changes in this scripts but I have not obtained any satisfactory results.

My excuses for my ugly English, I will try to explain better if the language is not understood.

Cheers and thanks in advance.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Jan 23, 2008 14:41    Post subject: Reply with quote

Post your NWNX log, and your SQLite log
--there might be a hint in them

G
Back to top
View user's profile Send private message
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Wed Jan 23, 2008 14:47    Post subject: Reply with quote

Ok, this are the logs:

The nwnx ones:

Code:
NWN Extender V.2.6.1
(c) 2005 by Ingmar Stieger (Papillon) and Jeroen Broekhuizen
visit us at http://www.nwnx.org

* Loading plugins...
* Plugin odbc is loaded.
* NWNX2 activated.
* NWNX2 shutting down...
* NWNX2 shutdown successfull.


and the sqlite ones:


Code:
NWNX ODBC2 plugin V.0.9.2.4
(c) 2005 by Ingmar Stieger (Papillon) and Jeroen Broekhuizen
visit us at http://www.nwnx.org

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.


Cheers!.
Back to top
View user's profile Send private message
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Wed Jan 23, 2008 15:15    Post subject: Reply with quote

Might post the changes i made in the scripts if that helps in anyway.

The Olanders system only has for default aps_include and the persistent facade without pf_aps_persist script, i add this one later and add the aps_onload too.
Then i follow the instructions on the bentons persistent facade for use APS persistence, uncommented #include "pf_aps_persist" in the pf_facade script, and then the system gives me the error i related above.

If i comment out the lines with the error module builds ok but no data stored in the db table

I make a try with the aps_demo module and everything goes well, i saw the data on the sqlite table with sqlite cc.
Already I do not have any more ideas of what to do, And this issue starts being frustrating for me.

Help needed seriously Wink


Cheers
Back to top
View user's profile Send private message
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Wed Jan 23, 2008 16:01    Post subject: Reply with quote

You have to modify the requiered functions to work with the sco/rco plugin. To do this you can look into the aps_include scripts or you have to wait a little to give me time to look into one of my modified scripts, it's a very old script i used in one of an outdated module i converted to nwnx2.
_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Wed Jan 23, 2008 17:09    Post subject: Reply with quote

Hi, Mikel of Avalon (nice Nick !!)

Sincerely it is not important for me to wait a little, my knowledge on scripts is limited, and alone I am afraid not to be able to repair this, thanks for your offer, ill wait for ur instructions.


Funkyswerve said to me in bioware forums this scriptset i use ( i suppose he reffers to Bentons persisten facade) "is clearly fairly old" and I do not have doubts on his opinion, but Its strange a system like this Olander´s one which have been updated 08-19-2007 still have so older scripts inside.

Im sure theres another way to make Olanders realistic system work with APS but i dont know which one.

Any suggestion is welcome, thanks all of you for patient and for helping with this my personal headache.

Cheers
Back to top
View user's profile Send private message
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Wed Jan 23, 2008 23:30    Post subject: Reply with quote

Ok - the persistent facade is one of the easiest ways to work with many persistent systems without break other systems.

I will look at the aps_include and pf_facade scripts at the weekend and tell you what to do.
Also i will have a look in oleanders system - afaik the system must be resident on harddisc for testing...
_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Thu Jan 24, 2008 0:23    Post subject: Reply with quote

Great! thanks a lot.
Back to top
View user's profile Send private message
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Sun Jan 27, 2008 20:42    Post subject: Reply with quote

Hi,

Any news with this issue? Could u test the scripset finally?

Regards.
Back to top
View user's profile Send private message
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Mon Jan 28, 2008 14:54    Post subject: Reply with quote

Currently i inspected only the PF scripts...

My pf_aps_persist looks like this:
Code:

/*  Persistence Facade v1.2, by benton
    This is the front-end for aps/nwnx
    It just adds a few functions for HCR compatibility
*/
#include "aps_include"

// This is the table name were all HCR data for this module
// will be stored. If you're not using HCR, it's not used.
string sHCRTableName = "pwdata";

int GetPFCampaignInt(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
    { return GetPersistentInt(oPlayer, sVarName, sCampaignName); }

float GetPFCampaignFloat(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
    { return GetPersistentFloat(oPlayer, sVarName, sCampaignName); }

location GetPFCampaignLocation(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
    { return GetPersistentLocation(oPlayer, sVarName, sCampaignName); }

string GetPFCampaignString(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
    { return GetPersistentString(oPlayer, sVarName, sCampaignName); }

vector GetPFCampaignVector(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
    { return GetPersistentVector(oPlayer, sVarName, sCampaignName); }


void SetPFCampaignInt(string sCampaignName, string sVarName, int nInt,
    object oPlayer=OBJECT_INVALID, int expire = 0)
    { SetPersistentInt(oPlayer, sVarName, nInt, expire, sCampaignName);}

void SetPFCampaignFloat(string sCampaignName, string sVarName, float flFloat,
    object oPlayer=OBJECT_INVALID, int expire = 0)
    { SetPersistentFloat(oPlayer, sVarName, flFloat, expire, sCampaignName);}

void SetPFCampaignLocation(string sCampaignName, string sVarName, location locLocation,
    object oPlayer=OBJECT_INVALID, int expire = 0)
    { SetPersistentLocation(oPlayer, sVarName, locLocation, expire, sCampaignName);}

void SetPFCampaignString(string sCampaignName, string sVarName, string sString,
    object oPlayer=OBJECT_INVALID, int expire = 0)
    { SetPersistentString(oPlayer, sVarName, sString, expire, sCampaignName);}

void SetPFCampaignVector(string sCampaignName, string sVarName, vector vVector,
    object oPlayer=OBJECT_INVALID, int expire = 0)
    { SetPersistentVector(oPlayer, sVarName, vVector, expire, sCampaignName);}

void DeletePFCampaignVariable(string sCampaignName, string sVarName, object oPlayer=OBJECT_INVALID)
    { DeletePersistentVariable(oPlayer, sVarName, sCampaignName); }

void DestroyPFCampaignDatabase(string sCampaignName)
    { SQLExecDirect("DELETE from " + sCampaignName); }

// This does nothing in APS, because it doesn't support object storage
int StorePFCampaignObject(string sCampaignName, string sVarName, object oObject, object oPlayer=OBJECT_INVALID)
    { SetPersistentObject(oObject, sVarName, oPlayer, 0, sCampaignName); return 1; }

object RetrievePFCampaignObject(string sCampaignName, string sVarName, location locLocation,
    object oOwner = OBJECT_INVALID, object oPlayer=OBJECT_INVALID)
    { object oObject=OBJECT_INVALID; return GetPersistentObject(object oObject, sVarName, oOwner, sCampaignName); }

//==================   HCR compatibilty functions ===================//

// These functions are put in so HCR will compile and use the facade
void DeletePersistentString(object oTarget, string sName)
    { DeletePersistentVariable(oTarget, sName, sHCRTableName);}
void DeletePersistentInt(object oTarget, string sName)
    { DeletePersistentVariable(oTarget, sName, sHCRTableName); }
void DeletePersistentFloat(object oTarget, string sName)
    { DeletePersistentVariable(oTarget, sName, sHCRTableName); }
void DeletePersistentLocation(object oTarget, string sName)
    { DeletePersistentVariable(oTarget, sName, sHCRTableName); }
void DeletePersistentObject(object oTarget, string sName)
    { DeletePersistentVariable(oTarget, sName, sHCRTableName); }

/*
// These do nothing in APS, because it doesn't support object storage
void SetPersistentObject(object oTarget, string sName, int iExpiration=0, string sTable="") {}
object GetPersistentObject(object oTarget, string sName, string sTable="")
    { return OBJECT_INVALID; }
*/

// These do nothing in APS since all saving is done on-the-fly to DB
// They are put in so HCR will compile if this file is included with HCR
void PWDBSaveAll() {}
void PWDBSaveChanged() {}

_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Mon Jan 28, 2008 19:29    Post subject: Reply with quote

The same lines commented here, the two scripts seem to be identical.
Back to top
View user's profile Send private message
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Tue Jan 29, 2008 13:15    Post subject: Reply with quote

Feel the difference...

Make sure that the placeholder functions for HCR that different to aps_include are commented out.
Code:

/*
// These do nothing in APS, because it doesn't support object storage
void SetPersistentObject(object oTarget, string sName, int iExpiration=0, string sTable="") {}
object GetPersistentObject(object oTarget, string sName, string sTable="")
    { return OBJECT_INVALID; }
*/


Also see the difference in StorePFCampaignObject and RetrievePFCampaignObject which are completed to store objects (it can be possible to set the CampaignName to pwobjdata if you use this.
_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
Mikel



Joined: 23 Jan 2008
Posts: 13

PostPosted: Mon Aug 18, 2008 16:04    Post subject: Reply with quote

Sorry for no reply before, but busy with work and some other "real" things. I recently restart working the module.

Ill try ur suggestions about the pf_aps_persist, and it gives me an error on line 59 something like ERROR: UNKNOW STATE IN COMPILER (0sorry but my game is spanish and it differs)

This is the line that gives me the error:

Code:
 { object oObject=OBJECT_INVALID; return GetPersistentObject(object oObject, sVarName, oOwner, sCampaignName); }

i think its a sintax error or something similar, any idea of whats wrong? I copy this lines of ur pf_aps_persist script, without any changes.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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