Aller au contenu

Photo

Could use some help merging a few scripts.


  • Veuillez vous connecter pour répondre
20 réponses à ce sujet

#1
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
#include "core_debug"
// Name     : Avlis Persistence System include
// Purpose  : Various APS/NWNX2 related functions
// Authors  : Ingmar Stieger, Adam Colon, Josh Simon
// Modified : February 16, 2003
// This file is licensed under the terms of the
// GNU GENERAL PUBLIC LICENSE (GPL) Version 2
/************************************/
/* Return codes                     */
/************************************/
int SQL_ERROR = 0;
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();
// 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 LocationToString(location lLocation);
// Return a location value when given the string form of the location
location StringToLocation(string sLocation);
// Return a string value when given a vector
string VectorToString(vector vVector);
// Return a vector value when given the string form of the vector
vector StringToVector(string sVector);

// * Get and Set persistent string
void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration=0, string sTable="pwdata");
string GetPersistentString(object oObject, string sVarName, string sTable="pwdata");
// * Get and Set persistent int
void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration=0, string sTable="pwdata");
int GetPersistentInt(object oObject, string sVarName, string sTable="pwdata");
// * Get and Set persistent float
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration=0, string sTable="pwdata");
float GetPersistentFloat(object oObject, string sVarName, string sTable="pwdata");
// * Get and Set persistent object
void SetPersistentObject(object oObject, string sVarName, string sValue, int iExpiration=0, string sTable="pwdata");
string GetPersistentObject(object oObject, string sVarName, string sTable="pwdata");
// * Get and Set persistent location
// 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");
location GetPersistentLocation(object oObject, string sVarname, string sTable="pwdata");
// * Get and Set persistent vector
//   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");
vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwdata");

// 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");
void DeletePersistentInt(object oObject, string sVarName, string sTable="pwdata");
void DeletePersistentString(object oObject, string sVarName, string sTable="pwdata");
void DeletePersistentObject(object oObject, string sVarName, string sTable="pwdata");
void DeletePersistentLocation(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;
    }
}
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 VectorToString(vector vVector)
{
    return "#POSITION_X#" + FloatToString(vVector.x) + "#POSITION_Y#" + FloatToString(vVector.y) + "#POSITION_Z#" + FloatToString(vVector.z) + "#END#";
}
vector StringToVector(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 LocationToString(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 StringToLocation(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 = DbgGetObjectByTag(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")
{
  if(sValue == "")
  {
    DeletePersistentVariable( oObject, sVarName, sTable );
    return;
  }
  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 = "REPLACE INTO " + sTable + " SET player='" + sPlayer + "', tag='" + sTag
  + "', name='" + sVarName + "', val='" + sValue + "', expire='" + 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 + "'";
*/
    // Lorinton change
    // Only match those records which haven't expired or which do not have
    // an expiration (expire = 0). The expiration field is used as hours.
    string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
               "' AND tag='" + sTag + "' AND name='" + sVarName + "'" +
               " AND ( NOW() < last + INTERVAL expire SECOND OR expire = 0 )";

    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 SetPersistentObject(object oObject, string sVarName, string sValue, int iExpiration=0, string sTable="pwdata")
{
    SetPersistentString(oObject, sVarName, sValue, iExpiration, sTable);
}
string GetPersistentObject(object oObject, string sVarName, string sTable="pwdata")
{
    return GetPersistentString(oObject, sVarName, sTable);
}
void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration=0, string sTable="pwdata")
{
  if ( iValue == 0 )
  {
    DeletePersistentVariable( oObject, sVarName, sTable );
  }
  else
  {
    SetPersistentString(oObject, sVarName, IntToString(iValue), iExpiration, sTable);
  }
}
int GetPersistentInt(object oObject, string sVarName, string sTable="pwdata")
{
    return StringToInt(GetPersistentString(oObject, sVarName, sTable));
}
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration=0, string sTable="pwdata")
{
  if ( fValue == 0.0 )
  {
    DeletePersistentVariable( oObject, sVarName, sTable );
  }
  else
  {
    SetPersistentString(oObject, sVarName, FloatToString(fValue), iExpiration, sTable);
  }
}
float GetPersistentFloat(object oObject, string sVarName, string sTable="pwdata")
{
    return StringToFloat(GetPersistentString(oObject, sVarName, sTable));
}
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration=0, string sTable="pwdata")
{
    SetPersistentString(oObject, sVarName, LocationToString(lLocation), iExpiration, sTable);
}
location GetPersistentLocation(object oObject, string sVarName, string sTable="pwdata")
{
    return StringToLocation(GetPersistentString(oObject, sVarName, sTable));
}
void SetPersistentVector(object oObject, string sVarName, vector vVector, int iExpiration=0, string sTable ="pwdata")
{
    SetPersistentString(oObject, sVarName, VectorToString(vVector), iExpiration, sTable);
}
vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwdata")
{
    return StringToVector(GetPersistentString(oObject, sVarName, sTable));
}
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);
}
void DeletePersistentInt(object oObject, string sVarName, string sTable="pwdata")
{
    DeletePersistentVariable(oObject, sVarName, sTable);
}
void DeletePersistentString(object oObject, string sVarName, string sTable="pwdata")
{
    DeletePersistentVariable(oObject, sVarName, sTable);
}
void DeletePersistentObject(object oObject, string sVarName, string sTable="pwdata")
{
    DeletePersistentVariable(oObject, sVarName, sTable);
}
void DeletePersistentLocation(object oObject, string sVarName, string sTable="pwdata")
{
    DeletePersistentVariable(oObject, sVarName, sTable);
}

// 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;
}
//void main(){}

#2
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
With...

#3
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
// 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;
}

 

Modifié par Lazarus Magni, 26 décembre 2013 - 02:49 .


#4
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
These are aps_include scripts.

#5
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
Secondly this is a modified x0_i0_positions script. I somehow need to merge this with the default. Is that even possible?

//:://////////////////////////////////////////////////
//:: X0_I0_POSITION
/*
Include file for functions that can be used to determine
locations and positions.
 */
//:://////////////////////////////////////////////////
//:: Copyright © 2002 Floodgate Entertainment
//:: Created By: Naomi Novik
//:: Created On: 11/08/2002
//:://////////////////////////////////////////////////
/**********************************************************************
 * CONSTANTS
 **********************************************************************/
// Distances used for determining positions
float DISTANCE_TINY = 1.0;
float DISTANCE_SHORT = 3.0;
float DISTANCE_MEDIUM = 5.0;
float DISTANCE_LARGE = 10.0;
float DISTANCE_HUGE = 20.0;
 

/**********************************************************************
 * FUNCTION PROTOTYPES
 **********************************************************************/
// Turn a location into a string. Useful for debugging.
string LocationToString(location loc);
// Turn a vector into a string. Useful for debugging.
string VectorToString(vector vec);

// This actually moves the target to the given new location,
// and makes them face the correct way once they get there.
void MoveToNewLocation(location lNewLocation, object oTarget=OBJECT_SELF);
// This returns the change in X coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInX(float fDistance, float fAngle);
// This returns the change in Y coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInY(float fDistance, float fAngle);
// This returns a new vector representing a position that is fDistance
// meters away at fAngle from the original position.
// If a negative coordinate is generated, the absolute value will
// be used instead.
vector GetChangedPosition(vector vOriginal, float fDistance, float fAngle);
// This returns the angle between two locations
float GetAngleBetweenLocations(location lOne, location lTwo);
/********** DIRECTION *************/
// This returns the opposite direction (ie, this is the direction you
// would use to set something facing exactly opposite the way of
// something else that's facing in direction fDirection).
float GetOppositeDirection(float fDirection);
// This returns the direction directly to the right. (IE, what
// you would use to make an object turn to the right.)
float GetRightDirection(float fDirection);
// This returns a direction that's a half-turn to the right
float GetHalfRightDirection(float fDirection);
// This returns a direction one and a half turns to the right
float GetFarRightDirection(float fDirection);
// This returns a direction a specified angle to the right
float GetCustomRightDirection(float fDirection, float fAngle);
// This returns the direction directly to the left. (IE, what
// you would use to make an object turn to the left.)
float GetLeftDirection(float fDirection);
// This returns a direction that's a half-turn to the left
float GetHalfLeftDirection(float fDirection);
// This returns a direction one and a half turns to the left
float GetFarLeftDirection(float fDirection);
// This returns a direction a specified angle to the left
float GetCustomLeftDirection(float fDirection, float fAngle);
/******** LOCATION FUNCTIONS *********/
/*
 * These functions return new locations suitable for placing
 * created objects in relation to a target, for example.
 *
 */
// Turns the target object to face the specified object
void TurnToFaceObject(object oObjectToFace, object oTarget=OBJECT_SELF);
// Returns the location flanking the target to the right
// (slightly behind) and facing same direction as the target
// (useful for backup)
location GetFlankingRightLocation(object oTarget);
// Returns the location flanking the target to the left
// (slightly behind) and facing same direction as the target.
// (useful for backup)
location GetFlankingLeftLocation(object oTarget);
// Returns a location directly opposite the target and
// facing the target
location GetOppositeLocation(object oTarget);
// Returns location directly ahead of the target and facing
// same direction as the target
location GetAheadLocation(object oTarget);
// Returns location directly behind the target and facing same
// direction as the target (useful for backstabbing attacks)
location GetBehindLocation(object oTarget);
// Returns location to the forward right flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingRightLocation(object oTarget);
// Returns location to the forward left flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingLeftLocation(object oTarget);
// Returns location to the forward right and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadRightLocation(object oTarget);
// Returns location to the forward left and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadLeftLocation(object oTarget);
// Returns location just a step to the left
// (Let's do the time warp...)
location GetStepLeftLocation(object oTarget);
// Returns location just a step to the right
location GetStepRightLocation(object oTarget);
// Get a random location in a given area based on a given object,
// the specified distance away.
// If no object is given, will use a random object in the area.
// If that is not available, will use the roughly-center point
// of the area.
// If distance is set to 0.0, a random distance will be used.
location GetRandomLocation(object oArea, object oSource=OBJECT_INVALID, float fDist=0.0);
/**********************************************************************
 * FUNCTION DEFINITIONS
 **********************************************************************/
// Speak location -- private function for debugging
void SpeakLocation(location lLoc)
{
    SpeakString(LocationToString(lLoc));
}
// Print location --- private function for debugging
void PrintLocation(location lLoc)
{
    PrintString(LocationToString(lLoc));
}
// Turn a location into a string. Useful for debugging.
string LocationToString(location loc)
{
    return "(" + GetTag(GetAreaFromLocation(loc)) + ")"
        + " " + VectorToString(GetPositionFromLocation(loc))
        + " (" + FloatToString(GetFacingFromLocation(loc)) + ")";
}

// Turn a vector into a string. Useful for debugging.
string VectorToString(vector vec)
{
    return "(" + FloatToString(vec.x)
        + ", " + FloatToString(vec.y)
        + ", " + FloatToString(vec.z) + ")";
}
 
// This actually moves the target to the given new location,
// and makes them face the correct way once they get there.
void MoveToNewLocation(location lNewLocation, object oTarget=OBJECT_SELF)
{
    AssignCommand(oTarget, ActionMoveToLocation(lNewLocation));
    AssignCommand(oTarget,
                  ActionDoCommand(
                        SetFacing(GetFacingFromLocation(lNewLocation))));
}

// This returns the change in X coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInX(float fDistance, float fAngle)
{
    return fDistance * cos(fAngle);
}
// This returns the change in Y coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInY(float fDistance, float fAngle)
{
    return fDistance * sin(fAngle);
}
// This returns a new vector representing a position that is fDistance
// meters away in the direction fAngle from the original position.
// If a negative coordinate is generated, the absolute value will
// be used instead.
vector GetChangedPosition(vector vOriginal, float fDistance, float fAngle)
{
    vector vChanged;
    vChanged.z = vOriginal.z;
    vChanged.x = vOriginal.x + GetChangeInX(fDistance, fAngle);
    if (vChanged.x < 0.0)
        vChanged.x = - vChanged.x;
    vChanged.y = vOriginal.y + GetChangeInY(fDistance, fAngle);
    if (vChanged.y < 0.0)
        vChanged.y = - vChanged.y;
    return vChanged;
}
// This returns the angle between two locations
float GetAngleBetweenLocations(location lOne, location lTwo)
{
    vector vPos1 = GetPositionFromLocation(lOne);
    vector vPos2 = GetPositionFromLocation(lTwo);
    float fDist = GetDistanceBetweenLocations(lOne, lTwo);
    float fChangeX = IntToFloat(abs(FloatToInt(vPos1.x - vPos2.x)));
    float fAngle = acos(fChangeX / fDist);
    return fAngle;
}

// This returns a direction normalized to the range 0.0 - 360.0
float GetNormalizedDirection(float fDirection)
{
    float fNewDir = fDirection;
    while (fNewDir >= 360.0) {
        fNewDir -= 360.0;
    }
    return fNewDir;
}
// This returns the opposite direction (ie, this is the direction you
// would use to set something facing exactly opposite the way of
// something else that's facing in direction fDirection).
float GetOppositeDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 180.0);
}

// This returns the direction directly to the right. (IE, what
// you would use to make an object turn to the right.)
float GetRightDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection - 90.0);
}
// This returns a direction that's a half-turn to the right
float GetHalfRightDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection - 45.0);
}
// This returns a direction one and a half turns to the right
float GetFarRightDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection - 135.0);
}
// This returns a direction a specified angle to the right
float GetCustomRightDirection(float fDirection, float fAngle)
{
    return GetNormalizedDirection(fDirection - fAngle);
}
// This returns the direction directly to the left. (IE, what
// you would use to make an object turn to the left.)
float GetLeftDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 90.0);
}
// This returns a direction that's a half-turn to the left
float GetHalfLeftDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 45.0);
}
// This returns a direction one and a half turns to the left
float GetFarLeftDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 135.0);
}
// This returns a direction a specified angle to the left
float GetCustomLeftDirection(float fDirection, float fAngle)
{
    return GetNormalizedDirection(fDirection + fAngle);
}
/**********************************************************************
 * LOCATION FUNCTIONS
 **********************************************************************/
// Turns the object to face the specified object
void TurnToFaceObject(object oObjectToFace, object oTarget=OBJECT_SELF)
{
    AssignCommand(oTarget,
                  SetFacingPoint(
                        GetPosition(oObjectToFace)));
}
// Private function -- we use this to get the new location
location GenerateNewLocation(object oTarget, float fDistance, float fAngle, float fOrientation)
{
    object oArea = GetArea(oTarget);
    vector vNewPos = GetChangedPosition(GetPosition(oTarget),
                                        fDistance,
                                        fAngle);
    return Location(oArea, vNewPos, fOrientation);
}
// Private function -- we use this to get the new location
// from a source location.
location GenerateNewLocationFromLocation(location lTarget, float fDistance, float fAngle, float fOrientation)
{
    object oArea = GetAreaFromLocation(lTarget);
    vector vNewPos = GetChangedPosition(GetPositionFromLocation(lTarget),
                                        fDistance,
                                        fAngle);
    return Location(oArea, vNewPos, fOrientation);
}
 
// This returns the location flanking the target to the right
location GetFlankingRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleToRightFlank = GetFarRightDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngleToRightFlank,
                               fDir);
}

// Returns the location flanking the target to the left
// (slightly behind) and facing same direction as the target.
// (useful for backup)
location GetFlankingLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleToLeftFlank = GetFarLeftDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngleToLeftFlank,
                               fDir);
}

// Returns a location directly ahead of the target and
// facing the target
location GetOppositeLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleOpposite = GetOppositeDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fDir,
                               fAngleOpposite);
}
// Returns location directly ahead of the target and facing
// same direction as the target
location GetAheadLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fDir,
                               fDir);
}
// Returns location directly behind the target and facing same
// direction as the target (useful for backstabbing attacks)
location GetBehindLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleOpposite = GetOppositeDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngleOpposite,
                               fDir);
}

// Returns location to the forward right flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfRightDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fDir);
}

// Returns location to the forward left flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfLeftDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fDir);
}
// Returns location to the forward right and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfRightDirection(fDir);
    float fFaceAngle = GetOppositeDirection(fAngle);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fFaceAngle);
}
// Returns location to the forward left and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfLeftDirection(fDir);
    float fFaceAngle = GetOppositeDirection(fAngle);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fFaceAngle);
}

// Returns location just a step to the left
// (Let's do the time warp...)
location GetStepLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetLeftDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_TINY,
                               fAngle,
                               fDir);
}
// Returns location just a step to the right
location GetStepRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetRightDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_TINY,
                               fAngle,
                               fDir);
}
// Get the (roughly) center point of an area.
// This works by going through all the objects in an area and
// getting their positions, so it is resource-intensive.
location GetCenterPointOfArea(object oArea)
{
    float fXMax = 0.0;
    float fXMin = 10000.0;
    float fYMax = 0.0;
    float fYMin = 10000.0;
    object oTmp = OBJECT_INVALID;
    vector vTmp;
    oTmp = GetFirstObjectInArea(oArea);
    while (GetIsObjectValid(oTmp)) {
        vTmp = GetPositionFromLocation(GetLocation(oTmp));
        if (vTmp.x > fXMax)
            fXMax = vTmp.x;
        if (vTmp.x < fXMin)
            fXMin = vTmp.x;
        if (vTmp.y > fYMax)
            fYMax = vTmp.y;
        if (vTmp.y < fYMin)
            fYMin = vTmp.y;
        oTmp = GetNextObjectInArea(oArea);
    }
    // We now have the max and min positions of all objects in an area.
    vTmp = Vector( (fXMax + fXMin)/2.0, (fYMax + fYMin)/2.0, 0.0);
    PrintString("Center vector: " + VectorToString(vTmp));
    return Location(oArea, vTmp, 0.0);
}
// Get a random location in a given area based on a given object,
// the specified distance away.
// If no object is given, will use a random object in the area.
// If that is not available, will use the roughly-center point
// of the area.
// If distance is set to 0.0, a random distance will be used.
location GetRandomLocation(object oArea, object oSource=OBJECT_INVALID, float fDist=0.0)
{
    location lStart;
    if (!GetIsObjectValid(oSource)) {
        lStart = GetCenterPointOfArea(oArea);
    } else {
        lStart = GetLocation(oSource);
    }
    float fAngle; float fOrient;
    if (fDist == 0.0) {
        int nRoll = Random(3);
        switch (nRoll) {
        case 0:
            fDist = DISTANCE_MEDIUM; break;
        case 1:
            fDist = DISTANCE_LARGE; break;
        case 2:
            fDist = DISTANCE_HUGE; break;
        }
    }
    fAngle = IntToFloat(Random(140) + 40);
    fOrient = IntToFloat(Random(360));
    return GenerateNewLocationFromLocation(lStart,
                                           fDist,
                                           fAngle,
                                           fOrient);
}
 
 
/*  void main() {} /* */
 
 

Modifié par Lazarus Magni, 26 décembre 2013 - 02:52 .


#6
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
The default position script is this I believe. If that helps at all.

//:://////////////////////////////////////////////////
//:: X0_I0_POSITION
/*
Include file for functions that can be used to determine
locations and positions.
 */
//:://////////////////////////////////////////////////
//:: Copyright © 2002 Floodgate Entertainment
//:: Created By: Naomi Novik
//:: Created On: 11/08/2002
//:://////////////////////////////////////////////////
/**********************************************************************
 * CONSTANTS
 **********************************************************************/
// Distances used for determining positions
const float DISTANCE_TINY = 1.0;
const float DISTANCE_SHORT = 3.0;
const float DISTANCE_MEDIUM = 5.0;
const float DISTANCE_LARGE = 10.0;
const float DISTANCE_HUGE = 20.0;
 

/**********************************************************************
 * FUNCTION PROTOTYPES
 **********************************************************************/
// Turn a location into a string. Useful for debugging.
string LocationToString(location loc);
// Turn a vector into a string. Useful for debugging.
string VectorToString(vector vec);

// This actually moves the target to the given new location,
// and makes them face the correct way once they get there.
void MoveToNewLocation(location lNewLocation, object oTarget=OBJECT_SELF);
// This returns the change in X coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInX(float fDistance, float fAngle);
// This returns the change in Y coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInY(float fDistance, float fAngle);
// This returns a new vector representing a position that is fDistance
// meters away at fAngle from the original position.
// If a negative coordinate is generated, the absolute value will
// be used instead.
vector GetChangedPosition(vector vOriginal, float fDistance, float fAngle);
// This returns the angle between two locations
float GetAngleBetweenLocations(location lOne, location lTwo);
/********** DIRECTION *************/
// This returns the opposite direction (ie, this is the direction you
// would use to set something facing exactly opposite the way of
// something else that's facing in direction fDirection).
float GetOppositeDirection(float fDirection);
// This returns the direction directly to the right. (IE, what
// you would use to make an object turn to the right.)
float GetRightDirection(float fDirection);
// This returns a direction that's a half-turn to the right
float GetHalfRightDirection(float fDirection);
// This returns a direction one and a half turns to the right
float GetFarRightDirection(float fDirection);
// This returns a direction a specified angle to the right
float GetCustomRightDirection(float fDirection, float fAngle);
// This returns the direction directly to the left. (IE, what
// you would use to make an object turn to the left.)
float GetLeftDirection(float fDirection);
// This returns a direction that's a half-turn to the left
float GetHalfLeftDirection(float fDirection);
// This returns a direction one and a half turns to the left
float GetFarLeftDirection(float fDirection);
// This returns a direction a specified angle to the left
float GetCustomLeftDirection(float fDirection, float fAngle);
/******** LOCATION FUNCTIONS *********/
/*
 * These functions return new locations suitable for placing
 * created objects in relation to a target, for example.
 *
 */
// Turns the target object to face the specified object
void TurnToFaceObject(object oObjectToFace, object oTarget=OBJECT_SELF);
// Returns the location flanking the target to the right
// (slightly behind) and facing same direction as the target
// (useful for backup)
location GetFlankingRightLocation(object oTarget);
// Returns the location flanking the target to the left
// (slightly behind) and facing same direction as the target.
// (useful for backup)
location GetFlankingLeftLocation(object oTarget);
// Returns a location directly opposite the target and
// facing the target
location GetOppositeLocation(object oTarget);
// Returns location directly ahead of the target and facing
// same direction as the target
location GetAheadLocation(object oTarget);
// Returns location directly behind the target and facing same
// direction as the target (useful for backstabbing attacks)
location GetBehindLocation(object oTarget);
// Returns location to the forward right flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingRightLocation(object oTarget);
// Returns location to the forward left flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingLeftLocation(object oTarget);
// Returns location to the forward right and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadRightLocation(object oTarget);
// Returns location to the forward left and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadLeftLocation(object oTarget);
// Returns location just a step to the left
// (Let's do the time warp...)
location GetStepLeftLocation(object oTarget);
// Returns location just a step to the right
location GetStepRightLocation(object oTarget);
// Get a random location in a given area based on a given object,
// the specified distance away.
// If no object is given, will use a random object in the area.
// If that is not available, will use the roughly-center point
// of the area.
// If distance is set to 0.0, a random distance will be used.
location GetRandomLocation(object oArea, object oSource=OBJECT_INVALID, float fDist=0.0);
/**********************************************************************
 * FUNCTION DEFINITIONS
 **********************************************************************/
// Speak location -- private function for debugging
void SpeakLocation(location lLoc)
{
    SpeakString(LocationToString(lLoc));
}
// Print location --- private function for debugging
void PrintLocation(location lLoc)
{
    PrintString(LocationToString(lLoc));
}
// Turn a location into a string. Useful for debugging.
string LocationToString(location loc)
{
    return "(" + GetTag(GetAreaFromLocation(loc)) + ")"
        + " " + VectorToString(GetPositionFromLocation(loc))
        + " (" + FloatToString(GetFacingFromLocation(loc)) + ")";
}

// Turn a vector into a string. Useful for debugging.
string VectorToString(vector vec)
{
    return "(" + FloatToString(vec.x)
        + ", " + FloatToString(vec.y)
        + ", " + FloatToString(vec.z) + ")";
}
 
// This actually moves the target to the given new location,
// and makes them face the correct way once they get there.
void MoveToNewLocation(location lNewLocation, object oTarget=OBJECT_SELF)
{
    AssignCommand(oTarget, ActionMoveToLocation(lNewLocation));
    AssignCommand(oTarget,
                  ActionDoCommand(
                        SetFacing(GetFacingFromLocation(lNewLocation))));
}

// This returns the change in X coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInX(float fDistance, float fAngle)
{
    return fDistance * cos(fAngle);
}
// This returns the change in Y coordinate that should be made to
// cause an object to be fDistance away at fAngle.
float GetChangeInY(float fDistance, float fAngle)
{
    return fDistance * sin(fAngle);
}
// This returns a new vector representing a position that is fDistance
// meters away in the direction fAngle from the original position.
// If a negative coordinate is generated, the absolute value will
// be used instead.
vector GetChangedPosition(vector vOriginal, float fDistance, float fAngle)
{
    vector vChanged;
    vChanged.z = vOriginal.z;
    vChanged.x = vOriginal.x + GetChangeInX(fDistance, fAngle);
    if (vChanged.x < 0.0)
        vChanged.x = - vChanged.x;
    vChanged.y = vOriginal.y + GetChangeInY(fDistance, fAngle);
    if (vChanged.y < 0.0)
        vChanged.y = - vChanged.y;
    return vChanged;
}
// This returns the angle between two locations
float GetAngleBetweenLocations(location lOne, location lTwo)
{
    vector vPos1 = GetPositionFromLocation(lOne);
    vector vPos2 = GetPositionFromLocation(lTwo);
    float fDist = GetDistanceBetweenLocations(lOne, lTwo);
    float fChangeX = IntToFloat(abs(FloatToInt(vPos1.x - vPos2.x)));
    float fAngle = acos(fChangeX / fDist);
    return fAngle;
}

// This returns a direction normalized to the range 0.0 - 360.0
float GetNormalizedDirection(float fDirection)
{
    float fNewDir = fDirection;
    while (fNewDir >= 360.0) {
        fNewDir -= 360.0;
    }
    return fNewDir;
}
// This returns the opposite direction (ie, this is the direction you
// would use to set something facing exactly opposite the way of
// something else that's facing in direction fDirection).
float GetOppositeDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 180.0);
}

// This returns the direction directly to the right. (IE, what
// you would use to make an object turn to the right.)
float GetRightDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection - 90.0);
}
// This returns a direction that's a half-turn to the right
float GetHalfRightDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection - 45.0);
}
// This returns a direction one and a half turns to the right
float GetFarRightDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection - 135.0);
}
// This returns a direction a specified angle to the right
float GetCustomRightDirection(float fDirection, float fAngle)
{
    return GetNormalizedDirection(fDirection - fAngle);
}
// This returns the direction directly to the left. (IE, what
// you would use to make an object turn to the left.)
float GetLeftDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 90.0);
}
// This returns a direction that's a half-turn to the left
float GetHalfLeftDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 45.0);
}
// This returns a direction one and a half turns to the left
float GetFarLeftDirection(float fDirection)
{
    return GetNormalizedDirection(fDirection + 135.0);
}
// This returns a direction a specified angle to the left
float GetCustomLeftDirection(float fDirection, float fAngle)
{
    return GetNormalizedDirection(fDirection + fAngle);
}
/**********************************************************************
 * LOCATION FUNCTIONS
 **********************************************************************/
// Turns the object to face the specified object
void TurnToFaceObject(object oObjectToFace, object oTarget=OBJECT_SELF)
{
    AssignCommand(oTarget,
                  SetFacingPoint(
                        GetPosition(oObjectToFace)));
}
// Private function -- we use this to get the new location
location GenerateNewLocation(object oTarget, float fDistance, float fAngle, float fOrientation)
{
    object oArea = GetArea(oTarget);
    vector vNewPos = GetChangedPosition(GetPosition(oTarget),
                                        fDistance,
                                        fAngle);
    return Location(oArea, vNewPos, fOrientation);
}
// Private function -- we use this to get the new location
// from a source location.
location GenerateNewLocationFromLocation(location lTarget, float fDistance, float fAngle, float fOrientation)
{
    object oArea = GetAreaFromLocation(lTarget);
    vector vNewPos = GetChangedPosition(GetPositionFromLocation(lTarget),
                                        fDistance,
                                        fAngle);
    return Location(oArea, vNewPos, fOrientation);
}
 
// This returns the location flanking the target to the right
location GetFlankingRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleToRightFlank = GetFarRightDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngleToRightFlank,
                               fDir);
}

// Returns the location flanking the target to the left
// (slightly behind) and facing same direction as the target.
// (useful for backup)
location GetFlankingLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleToLeftFlank = GetFarLeftDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngleToLeftFlank,
                               fDir);
}

// Returns a location directly ahead of the target and
// facing the target
location GetOppositeLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleOpposite = GetOppositeDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fDir,
                               fAngleOpposite);
}
// Returns location directly ahead of the target and facing
// same direction as the target
location GetAheadLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fDir,
                               fDir);
}
// Returns location directly behind the target and facing same
// direction as the target (useful for backstabbing attacks)
location GetBehindLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleOpposite = GetOppositeDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngleOpposite,
                               fDir);
}

// Returns location to the forward right flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfRightDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fDir);
}

// Returns location to the forward left flank of the target
// and facing the same way as the target
// (useful for guarding)
location GetForwardFlankingLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfLeftDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fDir);
}
// Returns location to the forward right and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfRightDirection(fDir);
    float fFaceAngle = GetOppositeDirection(fAngle);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fFaceAngle);
}
// Returns location to the forward left and facing the target.
// (useful for one of two people facing off against the target)
location GetAheadLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetHalfLeftDirection(fDir);
    float fFaceAngle = GetOppositeDirection(fAngle);
    return GenerateNewLocation(oTarget,
                               DISTANCE_MEDIUM,
                               fAngle,
                               fFaceAngle);
}

// Returns location just a step to the left
// (Let's do the time warp...)
location GetStepLeftLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetLeftDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_TINY,
                               fAngle,
                               fDir);
}
// Returns location just a step to the right
location GetStepRightLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngle = GetRightDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_TINY,
                               fAngle,
                               fDir);
}
// Get the (roughly) center point of an area.
// This works by going through all the objects in an area and
// getting their positions, so it is resource-intensive.
location GetCenterPointOfArea(object oArea)
{
    float fXMax = 0.0;
    float fXMin = 10000.0;
    float fYMax = 0.0;
    float fYMin = 10000.0;
    object oTmp = OBJECT_INVALID;
    vector vTmp;
    oTmp = GetFirstObjectInArea(oArea);
    while (GetIsObjectValid(oTmp)) {
        vTmp = GetPositionFromLocation(GetLocation(oTmp));
        if (vTmp.x > fXMax)
            fXMax = vTmp.x;
        if (vTmp.x < fXMin)
            fXMin = vTmp.x;
        if (vTmp.y > fYMax)
            fYMax = vTmp.y;
        if (vTmp.y < fYMin)
            fYMin = vTmp.y;
        oTmp = GetNextObjectInArea(oArea);
    }
    // We now have the max and min positions of all objects in an area.
    vTmp = Vector( (fXMax + fXMin)/2.0, (fYMax + fYMin)/2.0, 0.0);
    //PrintString("Center vector: " + VectorToString(vTmp));
    return Location(oArea, vTmp, 0.0);
}
// Get a random location in a given area based on a given object,
// the specified distance away.
// If no object is given, will use a random object in the area.
// If that is not available, will use the roughly-center point
// of the area.
// If distance is set to 0.0, a random distance will be used.
location GetRandomLocation(object oArea, object oSource=OBJECT_INVALID, float fDist=0.0)
{
    location lStart;
    if (!GetIsObjectValid(oSource)) {
        lStart = GetCenterPointOfArea(oArea);
    } else {
        lStart = GetLocation(oSource);
    }
    float fAngle; float fOrient;
    if (fDist == 0.0) {
        int nRoll = Random(3);
        switch (nRoll) {
        case 0:
            fDist = DISTANCE_MEDIUM; break;
        case 1:
            fDist = DISTANCE_LARGE; break;
        case 2:
            fDist = DISTANCE_HUGE; break;
        }
    }
    fAngle = IntToFloat(Random(140) + 40);
    fOrient = IntToFloat(Random(360));
    return GenerateNewLocationFromLocation(lStart,
                                           fDist,
                                           fAngle,
                                           fOrient);
}
 
 
/*  void main() {} /* */
 
 

Modifié par Lazarus Magni, 26 décembre 2013 - 02:56 .


#7
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
Any help would certainly be appreciated.

#8
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
You do not have any scripts there, therefore there is nothing to merge.

Everything listed is an include file. as long as you have not named two functions the same or are not trying to include the same file twice you should have no trouble.

Just include the files you need. Or append one to the other.

#9
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
Hi Lightfoot8,
Thanks for the response. What do you mean "append one to the other"? Are you talking about re-naming one, and then executing script at the bottom of the original?
Laz

#10
Shadooow

Shadooow
  • Members
  • 4 470 messages
he meant that you can #include "script" inside include itself which will effectively "merge" them, but includes aren't supposed to merge you would soon hit the limit for number of constants and functions so its best to have include files divided by their focus, one for itemproperties, one for spells, one for persistency etc.

#11
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
Thanks Shadooow. When you talk about a limit for number of constants and functions, are you talking about for an individual include itself, or for a mod as a whole? And do you know what that limit is?

#12
Shadooow

Shadooow
  • Members
  • 4 470 messages

Lazarus Magni wrote...

Thanks Shadooow. When you talk about a limit for number of constants and functions, are you talking about for an individual include itself, or for a mod as a whole? And do you know what that limit is?

the limit is per script because each script can include different number of includes, so just avoid merging includes together and include only those includes that you use function from and you should be fine

#13
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
 Note that none of the files that you listed have a "void main"  in them,  At least not one that is not commented out.  
I guess it helps to understand what  "void main()"   is.    It is basically just a 'void' returning function,a function that does not return a value,  that is named 'main'.  what makes the 'main' function special is that it is used as the starting point for the execution of a script.   Without a starting point you do not have a script.    You only have source code for use in building a script.   So even though you have a lot of source code in the files above none of them are scripts, they are only source code.   Since they are not scripts they can not be executed,  there is no starting point.


So the question would arrise " If they can not be executed, what are they good for?". 

As stated above they are source code for other scripts, That would be scripts that have a 'void main()' , starting point, in them.   That is where the compiler directive(#) 'include' comes in.    

# is the symbole for a compiler directive.   'include'  is the name of the directive.

It basically tells the compiler to add the file named following it to the script.    




Since both look like the same include.   I guess the question I now have is.   What triggered the request.  

Modifié par Lightfoot8, 26 décembre 2013 - 07:36 .


#14
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
Thanks for the clarification guys.

The reason why I was asking was because I am looking at merging two highly customized worlds. I was getting a ton of uncompiled scripts (naturally), and the biggest sources of this was due to two different versions used by said worlds of the above 2 scripts (or more precisely includes as I now gather.)

I have cut down the number of uncompiled scripts now from 800 or so to 80 or so, by searching independently the two worlds for scripts that had these two files (aps_include and x0_i0_position) as includes, and rerouting them to re-named copies.

Now to look at the other 80 or so, and see if they are even necessary (vital), and if so if we can get them to play nice so to speak.

Modifié par Lazarus Magni, 26 décembre 2013 - 08:46 .


#15
Shadooow

Shadooow
  • Members
  • 4 470 messages
if you send me those files on email i can merge it for you, but this mess you send on forums is useless :)

#16
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
Thank you Shadooow, that is kind of you. As I mentioned I believe I have a working solution at this point regarding those two scripts. However I do have a few other scripts that are being stubborn, and definitely would welcome some help if you would be willing. I will send you an e-mail once I figure out what's needed, and you can see from there what you would be willing to work on if anything.

Just a disclaimer though, at this point it is all still very experimental. Just testing the waters to see what is even feasible.

#17
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
At this point we still have about 40 scripts that aren't compiling. After looking through them none of them seem critical. I could probable just delete them, and they would not be missed by most. However I would still like to see if a full merger is possible, and from what I can tell it comes down to a few errors in a few scripts.

I would love some help resolving this, but again it's just an experiment at this point, and not essential. But I would love to see if we can complete the merge of 2 epic worlds. I think it speaks to the unlimited potential of NWN in general.

The scripts we have that don't compile seem to fall under the same 5-6 types of errors.

_functions_misc.nss(148): ERROR: PARSING VARIABLE LIST


x2_inc_switches.nss(17): ERROR: FUNCTION DEFINITION MISSING NAME

inc_divineinterv.nss(183): ERROR: IDENTIFIER LIST FULL

zero_ggdi.nss(515): ERROR: UNDEFINED IDENTIFIER (DrawStar)

x0_i0_positionav.nss(18): ERROR: FUNCTION DEFINITION MISSING NAME

kt_arrowtrap- no starting conditional

makeavatar- no starting conditional

(Space backspace, does not fix those with out starting conditionals.)

Of course since the toolset only shows the first error with a script (and not subsequent ones) it is quite likely that there are others contained within these.

Looking at just the first script giving the errors this is the script:

_functions_misc.nss

//:://////////////////////////////////////////////////////////////////////////
//:: Created By:    Demented
//:: Name:          Badlands Guild System Include File
//:: Modified:
//:: Date           Description
//:: -------------------------------------------------------------------------
//::
//:://////////////////////////////////////////////////////////////////////////
#include "nw_i0_plot"
#include "_functions_text"
// * Removes all Tempory effects on an Item
void RemoveItemTemp(object oItem);
// * Removes all tempory effects on  a player
void RemovePlayerTemp(object oPC);
// * This removes all Permenent effects on a player
void RemovePlayerPerm(object oPC);
// * Takes one off a item Stack
void RemoveOne(object oItem);
// * The snores for count times
void Snore(object oPC, int iCount=1);
// * Copy properties of one object to another
void CopyItemProperties(object oItem1,object oItem2);
// * Destroy a single object by resref
void Destroy(object oPC,string itemres);
//* Ability Player Ability Test
int PlayerAbilityTest(object oPC,int Ability,int Difficulty);
//* Create Item On A Object Once
void CreateItemOnObjectOnce(string sItemTemplate, object oTarget);
//* DWD TOKEN MESSAGE AND TOKEN DELETION
void TokenMsg(object oPC, string sItemTag, string sType);
//* MaxHP Functions - by OldManWhistler
string GetClassName (int nClass);
string LogMaxHP (object oPC);
void ShowMaxHP(object oPC);
//* Check access restriction.
void RestrictedAreaCheck(string sAreaName);
//*  Delayed Entire Fraction(Party) Jump to object.
void DelayedFractionJump(object oTarget, object oPlayer, float iDelay);
//  Cast A Spell
void Cast_A_Spell(int iSpell, object oCaster, object oTarget);
//  Apply a specail territory guild bonus.
void ApplyGuildBonus(object oPC, string sMessage, effect eVisualEffect, effect eBonusEffect);
//  Return to Waypoint.
void ReturnToWaypoint(object oPC);
//  Create A Portal On Death.
void DeathPortalCreate(object oBoss, object oWaypoint);

//  Return to Waypoint.
//void ReturnToWaypoint(object oPC);
//------------------------------------------------------------------------------
//-     Removes all Tempory effects on an Item
//------------------------------------------------------------------------------
void RemoveItemTemp(object oItem)
{
    itemproperty ip = GetFirstItemProperty(oItem);
    while (GetIsItemPropertyValid(ip))
    {
        if (GetItemPropertyDurationType(ip) == DURATION_TYPE_TEMPORARY) RemoveItemProperty(oItem, ip);
        ip = GetNextItemProperty(oItem);
    }
}
//------------------------------------------------------------------------------
//-     This removes all tempory effects on a player
//------------------------------------------------------------------------------
void RemovePlayerTemp(object oPC)
{
    effect eCheck = GetFirstEffect(oPC);
    while(GetIsEffectValid(eCheck))
    {
        if(GetEffectDurationType(eCheck)==DURATION_TYPE_TEMPORARY) RemoveEffect(oPC,eCheck);
        eCheck = GetNextEffect(oPC);
    }
}
//------------------------------------------------------------------------------
//-     This removes all Permenent effects on a player
//------------------------------------------------------------------------------
void RemovePlayerPerm(object oPC)
{
    effect eCheck=GetFirstEffect(oPC);
    while(GetIsEffectValid(eCheck))
    {
        if (GetEffectSubType(eCheck)==SUBTYPE_SUPERNATURAL)
        {
            RemoveEffect(oPC,eCheck);
        }
        eCheck=GetNextEffect(oPC);
    }
}
//------------------------------------------------------------------------------
//-     Remove a single item from a stack
//------------------------------------------------------------------------------
void RemoveOne(object oItem)
{
    int iStack=GetItemStackSize(oItem);
    SetItemStackSize(oItem, iStack-1);
}
//------------------------------------------------------------------------------
//-     Destroy a single object by resref
//------------------------------------------------------------------------------
void Destroy (object oPC,string itemres)
{
    object oDes=GetItemPossessedBy(oPC,itemres);
    DestroyObject(oDes);
}
//------------------------------------------------------------------------------
//-     Applys Cute Sleeping Animation.
//------------------------------------------------------------------------------
void Snore(object oPC, int iCount=1)
{
    FloatingTextStringOnCreature("ZZzzzz",oPC);
    if (iCount <3)
    {
        iCount++;
        DelayCommand(6.0,AssignCommand (oPC, Snore(oPC,iCount)));
    }
}
//------------------------------------------------------------------------------
//-     Applys Ability Test
//------------------------------------------------------------------------------
int PlayerAbilityTest(object oPC,int Ability,int Difficulty)
{
    int Abb=LoCGetAbilityModifier(Ability,oPC)+d20();
    SendMessageToPC(oPC,"You Rolled Strength Roll of "+IntToString(Abb)+" Difficulty "+IntToString(Difficulty));
    if (Abb>=Difficulty) return TRUE;
    return FALSE;
}
//------------------------------------------------------------------------------
//-     Copy Item Properties
//------------------------------------------------------------------------------
void CopyItemProperties(object oItem1,object oItem2)
{
    itemproperty ip1 =  GetFirstItemProperty(oItem1);
    while (GetIsItemPropertyValid(ip1))
    {
        AddItemProperty(DURATION_TYPE_PERMANENT,ip1,oItem2,0.0f);
        ip1=GetNextItemProperty(oItem1);
    }
}
//------------------------------------------------------------------------------
//-     Create Item On A Object Once
//------------------------------------------------------------------------------
void CreateItemOnObjectOnce(string sItemTemplate, object oTarget)
{
    if(GetItemPossessedBy(oTarget, sItemTemplate) == OBJECT_INVALID)
    {
        CreateItemOnObject(sItemTemplate, oTarget);
    }
    return;
}
//------------------------------------------------------------------------------
//-     DWD TOKEN MESSAGE AND TOKEN DELETION
//------------------------------------------------------------------------------
void TokenMsg(object oPC, string sItemTag, string sType)
{
    int i;
    int iXtra = GetNumItems(oPC, sItemTag) - 1;
    for (i = 1; i <= iXtra; i++)
    {
        Destroy(oPC, sItemTag);
    }
    SendMessageToPC(oPC, "Sorry, you have too many " + sType +
        " You are only allowed 1.  " + IntToString(iXtra) +
        " extra item(s) removed.");
}
//------------------------------------------------------------------------------
// MaxHP Functions - a really small stupid function by OldManWhistler
//------------------------------------------------------------------------------
//
// This is a little function that you can stick into your module (suggested
// spots: OnLevelUp, OnClientEnter, OnClientLeave) to write the player HP to the
// log file.
//
// It logs the maximum HP, the maximum HP possible, the HP from CON+Toughness,
// the maximum HP from classes and the percentage of maximum possible HP the
// character has.
//
// The information can be used to see if certain players are abusing the ability
// to "re-roll" bad HP rolls by hitting cancel in the level up process.
//
// But keep in mind that low Hit Die classes like wizard/sorcerer/rogue/bard
// will most likely always be close to the maximum possible HP because of NWN
// never rolls less than 50% when rolling HD. Also remember that characters get
// 100% of their Hit Die for their first three levels.
//
// Zip includes a tiny sample module and the script in an ERF file.
//------------------------------------------------------------------------------
string GetClassName (int nClass)
{
    // nClass - CLASS_* constant
    switch (nClass)
    {
        case CLASS_TYPE_BARBARIAN: return "Barbarian";
        case CLASS_TYPE_BARD: return "Bard";
        case CLASS_TYPE_CLERIC: return "Cleric";
        case CLASS_TYPE_DRUID: return "Druid";
        case CLASS_TYPE_FIGHTER: return "Fighter";
        case CLASS_TYPE_MONK: return "Monk";
        case CLASS_TYPE_PALADIN: return "Paladin";
        case CLASS_TYPE_RANGER: return "Ranger";
        case CLASS_TYPE_ROGUE: return "Rogue";
        case CLASS_TYPE_SORCERER: return "Sorcerer";
        case CLASS_TYPE_WIZARD: return "Wizard";
    }
    return "";
}
string LogMaxHP (object oPC)
{
    // by OldManWhistler
    // This function writes out the maximum HP the character has and the
    // maximum HP the character can possible have.
    // It is useful for seeing if your players are re-rolling their HP.
    // Note: level 1-3 characters will always have 100% of their maximum
    // possible HP.
    int iLevel = GetLevelByPosition(1, oPC) + GetLevelByPosition(2, oPC) + GetLevelByPosition(3, oPC);
    int iMaxHP = GetMaxHitPoints(oPC);
    int id4 = GetLevelByClass(CLASS_TYPE_SORCERER, oPC) + GetLevelByClass(CLASS_TYPE_WIZARD, oPC);
    int id6 = GetLevelByClass(CLASS_TYPE_BARD, oPC) + GetLevelByClass(CLASS_TYPE_ROGUE, oPC);
    int id8 = GetLevelByClass(CLASS_TYPE_CLERIC, oPC) + GetLevelByClass(CLASS_TYPE_DRUID, oPC) + GetLevelByClass(CLASS_TYPE_MONK, oPC);
    int id10 = GetLevelByClass(CLASS_TYPE_FIGHTER, oPC) + GetLevelByClass(CLASS_TYPE_PALADIN, oPC) + GetLevelByClass(CLASS_TYPE_RANGER, oPC);
    int id12 = GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC);
    int iCon = LoCGetAbilityModifier(ABILITY_CONSTITUTION, oPC);
    int iTough = GetHasFeat(FEAT_TOUGHNESS, oPC);
    int iHPBonus = (iCon + iTough) * iLevel;
    int iHPClass = 4*id4 + 6*id6 + 8*id8 + 10*id10 + 12*id12;
    float fPerc = IntToFloat(iMaxHP - iHPBonus)*100 / IntToFloat(iHPClass);
    string sMsg1 = "LogMaxHP:"+GetPCPlayerName(oPC)+"/"+GetName(oPC);
    string sMsg2 = "LogMaxHP:"+GetClassName(GetClassByPosition(1, oPC))+"/"+GetClassName(GetClassByPosition(2, oPC))+"/"+GetClassName(GetClassByPosition(3, oPC))+" Level:"+IntToString(iLevel)+" MaxHP:"+IntToString(iMaxHP)+" HPPotential:"+IntToString(iHPBonus+iHPClass)+" HPConTough:"+IntToString(iHPBonus)+" HPClasses:"+IntToString(iHPClass)+ " PercentageOfMax:"+FloatToString(fPerc, 4, 2);
    SendMessageToPC(oPC, sMsg1);
    SendMessageToPC(oPC, sMsg2);
    SendMessageToAllDMs(sMsg1);
    SendMessageToAllDMs(sMsg2);
    return sMsg2;
}
void ShowMaxHP(object oPC)
{
    object oPC = GetItemActivatedTarget();
    int iMaxHP = GetMaxHitPoints(oPC);
    string sMaxHP = IntToString(iMaxHP);
    SendMessageToPC(oPC, "Your maximum HP is " + sMaxHP);
    SendMessageToAllDMs("The player's maximum HP is " + sMaxHP);
}
//------------------------------------------------------------------------------
//  Port Access Check.
//------------------------------------------------------------------------------
void RestrictedAreaCheck(string sAreaName)
{
    int iFlag = TRUE;
    //  House of 1000 Burning Kitten Areas
    if (sAreaName == "Advocates Stronghold") iFlag = FALSE;
    //  House of 1000 Burning Kitten Areas
    if (sAreaName == "Order of the Blue Rose Stronghold") iFlag = FALSE;
    //  House of 1000 Burning Kitten Areas
    if (sAreaName == "") iFlag = FALSE;
    //  The Outlawz Areas
    if (sAreaName == "Outlawz Stronghold") iFlag = FALSE;
    //  Brotherhood of Shadows Areas
    if (sAreaName == "Brotherhood of Shadows Stronghold") iFlag = FALSE;
    //  Legion of Vigilantes Areas
    if (sAreaName == "Legion of Vigilantes Stronghold") iFlag = FALSE;
}
//------------------------------------------------------------------------------
//  Delayed Entire Fraction(Party) Jump to object.
//------------------------------------------------------------------------------
/*
*/
void DelayedFractionJump(object oTarget, object oPlayer, float iDelay)
{
    // Get the first PC party member
    object  oObject     = GetFirstFactionMember(oPlayer, TRUE);
    // We stop when there are no more valid PC's in the party.
    while(GetIsObjectValid(oObject) == TRUE)
    {
        //  Do not count yourself, DM's, or members of other guilds.
        if (GetIsPC(oObject))
        {
            //  Port the player.
            DelayCommand(iDelay, AssignCommand(oObject, JumpToObject(oTarget)));
        }
        // Get the next PC member of oPC's faction.
        oObject = GetNextFactionMember(oPlayer, TRUE);
    }
}

//------------------------------------------------------------------------------
//  Cast a Spell.
//------------------------------------------------------------------------------
/*
*/
void Cast_A_Spell(int iSpell, object oCaster, object oTarget)
{
    int nMetaMagic = METAMAGIC_MAXIMIZE;
    int bCheat = TRUE;
    int nDomainLevel = 40;
    int nProjectilePathType = PROJECTILE_PATH_TYPE_DEFAULT;
    int bInstantSpell = TRUE;
    //  Now lets cast GMW on it.
    AssignCommand(oCaster, ActionCastSpellAtObject(iSpell, oTarget, nMetaMagic,
        bCheat, nDomainLevel, nProjectilePathType, bInstantSpell));
}

//------------------------------------------------------------------------------
//  Apply a specail territory guild bonus.
//------------------------------------------------------------------------------
/*
*/
void ApplyGuildBonus(object oPC, string sMessage, effect eVisualEffect, effect eBonusEffect)
{
    AssignCommand(oPC,ClearAllActions());
    //  1st Setup the starndard duration variable.
    float fDur = IntToFloat(20 + GetHitDice(oPC) * d6(4));
    //int iDur = StringToInt(FloatToString(fDur/60.0));
    //  Apply the visual effect.
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisualEffect, oPC);
    //  Apply the Bonus effect.
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBonusEffect, oPC, fDur);
    //  Apply the onuse pause to the character
    SetLocalInt(oPC, "effect_pause", TRUE);
    //  Apply the delayed removal of the pause.
    AssignCommand(oPC, DelayCommand(fDur/6, SetLocalInt(oPC, "effect_pause", FALSE)));
    //  Send the cooresponding floating text message.
    ColoredFloatingString(sMessage, oPC, 10);
    return;
}

//------------------------------------------------------------------------------
//  Return to Waypoint.
//------------------------------------------------------------------------------
void ReturnToWaypoint(object oObject)
{
    //  Grab the needed shop keeper Tag his waypoint Tag when the store closes.
    string   sShopKeeperTag = GetTag(oObject);
    string   sWaypointTag   = "WP_" + sShopKeeperTag + "_01";
    //  Convert the string to its needed objects.
    object   oWaypoint      = GetWaypointByTag(sWaypointTag);
    //  Move the object to the destination.
    AssignCommand(oObject, ActionForceMoveToObject(oWaypoint, TRUE, 1.0f));
}

//------------------------------------------------------------------------------
//  Return to Waypoint.
//------------------------------------------------------------------------------
//  Create A Portal On Death.
void DeathPortalCreate(object oBoss, object oWaypoint)
{
    string WP_4_Portal = GetLocalString(oBoss, "WP_Portal");
    string WP_TerryNum = GetLocalString(oBoss, "Terry_Num");
    string WP_Terry    = "WP_Territory_" + WP_TerryNum;
    effect eBoom = EffectVisualEffect(VFX_FNF_DISPEL_DISJUNCTION,FALSE);
    effect eFire = EffectVisualEffect(VFX_IMP_PULSE_COLD);
    effect eDebris = EffectVisualEffect(354);
    location lTerryPortal = GetLocation(oWaypoint);
    object   oTerryPortal = CreateObject(OBJECT_TYPE_PLACEABLE, "boss_Portal", lTerryPortal);
    SetLocalString(oTerryPortal, "WaypointName", WP_Terry);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eBoom, lTerryPortal);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eFire, lTerryPortal);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eDebris, lTerryPortal);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eDebris, lTerryPortal);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eDebris, lTerryPortal);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eDebris, lTerryPortal);
    PlaySound("sim_explsun");
    DestroyObject(oTerryPortal, 100.0);
}
 

Modifié par Lazarus Magni, 29 décembre 2013 - 03:48 .


#18
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
And the includes are:

nw_i0_plot:

//::///////////////////////////////////////////////
//::
//:: Designer Include File
//::
//:: NW_I0_PLOT.nss
//::
//:: Copyright © 2001 Bioware Corp.
//::
//::
//:://////////////////////////////////////////////
//::
//::
//:: This is a sample of design wrote
//:: functions that may need inclusion in multiple
//:: modules.
//::
//:://////////////////////////////////////////////
//::
//:: Created By: Brent Knowles
//:: Created On: February 12, 2001
//:: Updated On: August, 14, 2003 (Georg) - Fixed AutoDC, Added const statement to constants
//:://////////////////////////////////////////////
const int DC_EASY = 0;
const int DC_MEDIUM = 1;
const int DC_HARD = 2;
const int DC_SUPERIOR = 3;
const int DC_MASTER = 4;
const int DC_LEGENDARY = 5;
const int DC_EPIC = 6;
// * this is used by some of the template scripts
// * 100 - this number is the chance of that dialog
// * appearing
const int G_CLASSCHANCE = 70;
//Experience Point Rewards constants used in the 'des_xp_rewards' 2da
const int XP_VERY_LOW = 1;    //50 xp
const int XP_LOW = 2;         //100 xp
const int XP_MEDIUM_LOW = 3;  //150 xp
const int XP_MEDIUM = 4;      //250 xp
const int XP_MEDIUM_HIGH = 5; //500 xp
const int XP_HIGH = 6;        //1000 xp
const int XP_VERY_HIGH = 7;   //2000 xp
const int XP_EPIC = 8;        //5000 xp

// * FUNCTION DECLARATIONS
// * returns true if the player can afford to lose the indicated amount of XP without losing  a level
int plotCanRemoveXP(object oPC, int nPenalty);
int GetCanCastHealingSpells(object oPC) ;
int DoOnce();
void DebugSpeak(string s);
object GetMyMaster();
int IsRecall();
void DimensionHop(object oTarget);
int CanSeePlayer();
void EscapeArea(int bRun = TRUE, string sTag="NW_EXIT");
int HasItem(object oCreature, string s);
void TakeGold(int nAmount, object oGoldHolder, int bDestroy=TRUE);
object GetNearestPC();
void SetIsEnemy(object oTarget);
// Provide a scaled skill check DC based on the DC_* constant passed in
// DC      -  DC_EASY  DC_MEDIUM  DC_HARD  DC_SUPERIOR  DC_MASTER  DC_LEGENDARY  DC_EPIC
// nSkill  - SKILL_* constant
// oTarget - creature that is going to perform the check;
int AutoDC(int DC, int nSkill, object oTarget);
void AutoAlignG(int DC, object oTarget);
void AutoAlignE(int DC, object oTarget);
void DoGiveXP(string sJournalTag, int nPercentage, object oTarget, int QuestAlignment=ALIGNMENT_NEUTRAL);
void RewardXP(string sJournalTag, int nPercentage, object oTarget, int QuestAlignment=ALIGNMENT_NEUTRAL, int bAllParty=TRUE);
void RewardGP(int GP, object oTarget,int bAllParty=TRUE);
int CheckCharismaMiddle();
int CheckCharismaNormal();
int CheckCharismaLow();
int CheckCharismaHigh();
int CheckIntelligenceLow();
int CheckIntelligenceNormal();
int CheckIntelligenceNormal();
int CheckIntelligenceHigh();
int CheckWisdomHigh();
// Return the wisdom of oTarget
int GetWisdom(object oTarget);
// Return the Intelligence of the Target
int GetIntelligence(object oTarget);
// Return the Charisma of the Target
int GetCharisma(object oTarget);
// Return the numer of items oTarget possesses from type sItem (Tag)
int GetNumItems(object oTarget,string sItem);
// Gives the item with the ResRef sItem to creature oTarget nNumItems times
void GiveNumItems(object oTarget,string sItem,int nNumItems);
// Remove nNumItems Items of Type sItem (Tag) from oTarget
void TakeNumItems(object oTarget,string sItem,int nNumItems);
// * plays the correct character theme
// * assumes OBJECT_SELF is in the area
void PlayCharacterTheme(int nTheme);
// * plays the old theme for the area
// * assumes OBJECT_SELF is in the area
void PlayOldTheme();
int GetPLocalInt(object oPC,string sLocalName);
void SetPLocalInt(object oPC,string sLocalName, int nValue);
// * removes all negative effects
void RemoveEffects(object oDead);
// * starts store using appraise skill
void gplotAppraiseOpenStore(object oStore, object oPC, int nBonusMarkUp = 0, int nBonusMarkDown = 0);
// * starts store with favorable appraise check
void gplotAppraiseFavOpenStore(object oStore, object oPC, int nBonusMarkUp = 0, int nBonusMarkDown = 0);
//Do a DC check and modify the skill by the Target's Strength modifier
int CheckDCStr(int DC, int nSkill, object oTarget);
//Check to see if target is PC and not DM
int GetIsPlayerCharacter(object oTarget);
//Reward Experience based on an entry in the des_xp_rewards 2da file
void Reward_2daXP(object oPC, int nRow, int bAllParty = TRUE, int nPercentage = 100);
//Both speak a string ref as well as play the associate sound file
void PlaySpeakSoundByStrRef(int nStrRef);

// * returns a value that will be subtracted from the
// * oTarget's DC to resist APpraise or Persuasion
int GetNPCEasyMark(object oTarget)
{
    int nCharmMod = 0;
    if (GetHasSpellEffect(SPELL_CHARM_PERSON, oTarget))
    {
        nCharmMod = 10;
    }
    else
    if (GetHasSpellEffect(SPELL_CHARM_MONSTER, oTarget))
    {
        nCharmMod = 10;
    }
    else
    if (GetHasSpellEffect(SPELL_CHARM_PERSON_OR_ANIMAL, oTarget))
    {
        nCharmMod = 10;
    }
    else if (GetHasSpellEffect(SPELL_MASS_CHARM, oTarget))
    {
            nCharmMod = 15;
    }
    else if (GetHasSpellEffect(SPELL_DOMINATE_MONSTER, oTarget))
    {
            nCharmMod = 20;
    }
    else if (GetHasSpellEffect(SPELL_DOMINATE_ANIMAL, oTarget))
    {
            nCharmMod = 20;
    }
    else if (GetHasSpellEffect(SPELL_DOMINATE_PERSON, oTarget))
    {
        nCharmMod = 20;
    }
    return nCharmMod;
}
//::///////////////////////////////////////////////
//:: gplotAppraiseOpenStore
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Opens a store, modifying the store prices
    by the Appraise skill of the PCspeaker
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:: 2003-05-26: Updated from XP1 sources - Georg
//:://////////////////////////////////////////////
void gplotAppraiseOpenStore(object oStore, object oPC, int nBonusMarkUp = 0, int nBonusMarkDown = 0)
{
    int STATE_FAILED = 1;
    int STATE_TIE = 2;
    int STATE_WON = 3;
    string sTag = ObjectToString(OBJECT_SELF);
    int nPlayerSkillRank = GetSkillRank(SKILL_APPRAISE, oPC);
    int nNPCSkillRank = GetSkillRank(SKILL_APPRAISE, OBJECT_SELF) - GetNPCEasyMark(OBJECT_SELF);

    if (nNPCSkillRank < 1 )
        nNPCSkillRank = 1;
    int nAdjust = 0;

    /*
      New System:
        An opposed skill check (a d10 roll instead). Your appraise skill versus the shopkeepers appraise skill.
        Possible Results:
        Percentage Rebate/Penalty: The 'difference'
        Feedback: [Appraise Skill]: Merchant's reaction is unfavorable.
                  [Appraise Skill]: Merchant's reaction is neutral.
                  [Appraise Skill]: Merchant's reaction is favorable.
        Additional: Remember last reaction for this particular skill.
        When the player gets a new skill rank in this skill they'll get a
        reroll against this merchant.
    */
    int nState = 0;
    int nPreviousRank = GetLocalInt(oPC, "X0_APPRAISERANK"+ sTag);
    // * if the player's rank has improved, let them have another appraise check
    // * against this merchant
 
    if ( (nPlayerSkillRank > nPreviousRank) || !GetLocalInt(oPC, "X0_APPRAISEVISITED"+sTag) )
    {
       SetLocalInt(oPC, "X0_APPRAISERANK"+ sTag, nPlayerSkillRank);
       SetLocalInt(oPC, "X0_APPRAISEVISITED"+sTag, 1);
        nPlayerSkillRank = nPlayerSkillRank + d10();
        nNPCSkillRank = nNPCSkillRank + d10();
        nAdjust = nNPCSkillRank - nPlayerSkillRank; // * determines the level of price modification
        if (nNPCSkillRank > nPlayerSkillRank)
        {
            nState = STATE_FAILED;
        }
        else
        if (nNPCSkillRank < nPlayerSkillRank)
        {
            nState = STATE_WON;
        }
        else
        if (nNPCSkillRank == nPlayerSkillRank)
        {
            nState = STATE_TIE;
        }
    }
    else
    {
        // * recover last reaction
        nAdjust  = GetLocalInt(oPC, "X0_APPRAISEADJUST" + sTag);
        if (nAdjust > 0)
        {
            nState = STATE_FAILED;
        }
        else
        if (nAdjust < 0)
        {
            nState = STATE_WON;
        }
        else
        if (nAdjust == 0)
        {
            nState = STATE_TIE;
        }
    }
    if (nState == STATE_FAILED  )
    {
        FloatingTextStrRefOnCreature(8963, oPC, FALSE);
    }
    else
    if (nState == STATE_WON)
    {
        FloatingTextStrRefOnCreature(8965, oPC, FALSE);
    }
    else
    if (nState == STATE_TIE)
    {
        FloatingTextStrRefOnCreature(8964, oPC, FALSE);
    }
    SetLocalInt(oPC, "X0_APPRAISEADJUST"+ sTag, nAdjust);
  //  SpawnScriptDebugger();

    // * Hard cap of 30% max up or down
    if (nAdjust > 30)
        nAdjust = 30;
    if (nAdjust < -30)
        nAdjust = -30;
    nBonusMarkUp = nBonusMarkUp + nAdjust;
    nBonusMarkDown = nBonusMarkDown - nAdjust;
    OpenStore(oStore, oPC, nBonusMarkUp, nBonusMarkDown);
}
//::///////////////////////////////////////////////
//:: gplotAppraiseFavOpenStore
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Opens a store, modifying the store prices
    by the Appraise skill of the PCspeaker
    THIS SCRIPT ALWAYS RESULTS IN A GOOD APPRAISE
    RESULT
*/
//:://////////////////////////////////////////////
//:: Created By: Keith Warner
//:: Created On: Mar 7/03
//:: 2003-05-26: Updated from XP1 sources - Georg
//:://////////////////////////////////////////////
void gplotAppraiseFavOpenStore(object oStore, object oPC, int nBonusMarkUp = 0, int nBonusMarkDown = 0)
{
    int STATE_WON = 3;
    string sTag = ObjectToString(OBJECT_SELF);
    int nPlayerSkillRank = GetSkillRank(SKILL_APPRAISE, oPC);
    int nNPCSkillRank = 0;

    int nAdjust = 0;
    int nState = STATE_WON;
    int nPreviousRank = GetLocalInt(oPC, "X0_APPRAISERANK"+ sTag);
    // * if the player's rank has improved, let them have another appraise check
    // * against this merchant
 
    if ( (nPlayerSkillRank > nPreviousRank) || !GetLocalInt(oPC, "X0_APPRAISEVISITED"+sTag) )
    {
       SetLocalInt(oPC, "X0_APPRAISERANK"+ sTag, nPlayerSkillRank);
       SetLocalInt(oPC, "X0_APPRAISEVISITED"+sTag, 1);
        nPlayerSkillRank = nPlayerSkillRank + d10();
        nAdjust = nNPCSkillRank - nPlayerSkillRank; // * determines the level of price modification
    }
    else
    {
        // * recover last reaction
        nAdjust  = GetLocalInt(oPC, "X0_APPRAISEADJUST" + sTag);
    }
    FloatingTextStrRefOnCreature(8965, oPC, FALSE);

    SetLocalInt(oPC, "X0_APPRAISEADJUST"+ sTag, nAdjust);
    // * Hard cap of 30% max up or down
    if (nAdjust > 30)
        nAdjust = 30;
    if (nAdjust < -30)
        nAdjust = -30;
    nBonusMarkUp = nBonusMarkUp + nAdjust;
    nBonusMarkDown = nBonusMarkDown - nAdjust;
    OpenStore(oStore, oPC, nBonusMarkUp, nBonusMarkDown);
}

// * plays the correct character theme
// * assumes OBJECT_SELF is in the area
void PlayCharacterTheme(int nTheme)
{
    object oArea =GetArea(OBJECT_SELF);
    int nMusicNight = MusicBackgroundGetNightTrack(oArea);
    int nMusicDay = MusicBackgroundGetDayTrack(oArea);
   // AssignCommand(GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC), SpeakString(IntToString(nMusic)));
    //* stores the last music track
    SetLocalInt(oArea, "NW_L_MYLASTTRACKNight", nMusicNight);
    SetLocalInt(oArea, "NW_L_MYLASTTRACKDay", nMusicDay);
    MusicBackgroundStop(oArea);
    MusicBackgroundChangeNight(oArea, nTheme);
    MusicBackgroundChangeDay(oArea, nTheme);
    MusicBackgroundPlay(oArea);
}
// * plays the old theme for the area
// * assumes OBJECT_SELF is in the area
void PlayOldTheme()
{
    object oArea =GetArea(OBJECT_SELF);
    //* stores the last music track
    int nMusicNight = GetLocalInt(oArea, "NW_L_MYLASTTRACKNight");
    int nMusicDay = GetLocalInt(oArea, "NW_L_MYLASTTRACKDay");
    MusicBackgroundStop(oArea);
    MusicBackgroundChangeNight(oArea, nMusicNight);
    MusicBackgroundChangeDay(oArea, nMusicDay);
    MusicBackgroundPlay(oArea);
}

//  Returns the adjusted Reaction for the purposes of store pricing.
float GetReactionAdjustment(object oTarget);
/*
    Adjusts all faction member's reputation visa via
    another faction.  Pass in a member from each
    faction.
*/
void AdjustFactionReputation(object oTargetCreature, object oMemberOfSourceFaction, int nAdjustment);
/*
    Makes the person teleport away and look like
    they are casting a spell.
*/
void EscapeViaTeleport(object oFleeing);
// * FUNCTION DEFINITIONS

int GetCanCastHealingSpells(object oPC)
{
    talent tTalent = GetCreatureTalentBest(TALENT_CATEGORY_BENEFICIAL_HEALING_TOUCH, 20, oPC);
    if (GetIsTalentValid(tTalent) == TRUE)
    {
      return TRUE;
    }
      return FALSE;
}

int DoOnce()
{
    int bResult = FALSE;
    if (GetLocalInt(OBJECT_SELF,"NW_L_DOONCE999") == 0)
    {
        SetLocalInt(OBJECT_SELF,"NW_L_DOONCE999",1);
        bResult = TRUE;
    }
    return bResult;
}
void DebugSpeak(string s)
{
    SpeakString(s);
}
object GetMyMaster()
{
    return GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
}
 
//::///////////////////////////////////////////////
//:: IsRecall
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Attempts  to transport the player
    back to closest Temple of Tyr using
    a Recall Stone.
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////
int IsRecall()
{
    if (GetTag(GetItemActivated()) == "NW_IT_RECALL")
    {
       string sAreaTag = GetTag(GetArea(GetItemActivator()));
       if (/*Chapter 1 Areas*/
           sAreaTag == "MAP_M1S3B" ||
           sAreaTag == "Map_M1S4C" ||
           sAreaTag == "MAP_M1Q6F4" || // Fenthick area in Chapter1e
           sAreaTag == "Map_M1S4D" ||
           sAreaTag == "Map_M1S4E" ||
           sAreaTag == "Map_M1S4F" ||
           /* Chapter 3 and 4 Areas*/
           sAreaTag == "MAP_M1Q6A" || /*Castle Never*/
           sAreaTag == "M4Q1D2" /*Final Source Stone level*/ ||
           sAreaTag == "M4FinalArea" || /*Haedralines area*/
           sAreaTag == "M3Q1A10" || /*Aarin Gend's Lodge*/
           sAreaTag == "M3Q3C" || sAreaTag == "M3Q3Ca" ||  sAreaTag == "M3Q2G" ||  sAreaTag == "M3Q2I" ||
           sAreaTag == "Map_M2Q2E2" || sAreaTag == "Map_M2Q2G" || sAreaTag == "Map_M2Q3GA" || sAreaTag == "Map_M2Q3GB")
       {
        AssignCommand(GetItemActivator(), ActionSpeakStringByStrRef(10611));
        return TRUE;
       }
       else
/*       if (CanAffordIt() == FALSE)
       {
        AssignCommand(GetItemActivator(), ActionSpeakStringByStrRef(66200));
        return TRUE;
       }
       else */
       // * May 2002: Checking a global to see if Haedraline is around as well
       if (        GetLocalInt(GetModule(),"NW_G_RECALL_HAED") == 10
       || GetIsObjectValid(GetNearestObjectByTag("Haedraline3Q11", GetItemActivator())) == TRUE)
       {
        AssignCommand(GetItemActivator(), ActionSpeakStringByStrRef(10612));
        return TRUE;
       }
       else
       {
           object oPortal = GetObjectByTag("NW_RECALL_PORTAL");
           if (GetIsObjectValid(oPortal) == TRUE)
           {
             SetLocalInt(GetItemActivator(), "NW_L_USED_RECALL", 1);
             SetLocalLocation(GetItemActivator(), "NW_L_LOC_RECALL", GetLocation(GetItemActivator()));
             string sTag =  "NW_RECALL_PORTAL";
              object oClicker = GetItemActivator();
              object oTarget = GetObjectByTag(sTag);
             // AssignCommand(GetItemActivator(), SpeakString(sTag));
                // * if I don't do this, gets stuck in a loop
                // * of casting.
              AssignCommand(oClicker, ClearAllActions());
              AssignCommand(oClicker, PlaySound("as_mg_telepout1"));

              //SetAreaTransitionBMP(AREA_TRANSITION_RANDOM);
//              AssignCommand(oClicker, PlaySound("as_mg_telepout1"));
              AssignCommand(oClicker,JumpToObject(oTarget));
//              AssignCommand(oClicker, DelayCommand(1.0,PlaySound("as_mg_telepout1")));
              AssignCommand(oClicker, ActionDoCommand(ClearAllActions()));
              return TRUE;
           }
           // * this module does not have a temple of tyr
           else
           {
                AssignCommand(GetItemActivator(), ActionSpeakStringByStrRef(10614));
                return TRUE;
           }
       }
    }
    return FALSE;
}
//::///////////////////////////////////////////////
//:: DimensionHop
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
     Will move the character from one point to oTarget
     with a flashy graphic.
     Original Use: Dryads in M3Q3, SnowGlobe
*/
//:://////////////////////////////////////////////
//:: Created By: Brent
//:: Created On: January 10, 2002
//:://////////////////////////////////////////////
void DimensionHop(object oTarget)
{
    if (GetDistanceToObject(oTarget) > 2.5)
    {
        effect eVis = EffectVisualEffect(VFX_IMP_UNSUMMON);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, OBJECT_SELF);
        ActionJumpToObject(oTarget);
    }
}
 
//::///////////////////////////////////////////////
//:: CanSeePlayer
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
   Returns true if OBJECT_SELF can see the player
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////
int CanSeePlayer()
{
    return GetIsObjectValid(GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN));
}
//::///////////////////////////////////////////////
//:: EscapeArea()
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
  Runs object to nearest waypoint with tag
  "NW_EXIT".  This tag can be overridden.
  You can also specify whether to run or not.
*/
//:://////////////////////////////////////////////
//:: Created By: Brent
//:: Created On: December 2001
//:://////////////////////////////////////////////
void EscapeArea(int bRun = TRUE, string sTag="NW_EXIT")
{
    object oWay = GetNearestObjectByTag(sTag);
    if (GetIsObjectValid(oWay))
    {
        ActionMoveToObject(oWay, bRun);
        ActionDoCommand(DestroyObject(OBJECT_SELF));
        SetCommandable(FALSE); // * this prevents them from being interrupted
    }
    //else
    //SpeakString("invalid exit waypoint");
}
//::///////////////////////////////////////////////
//:: HasItem
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
      A wrapper to simplify checking for an item.
*/
//:://////////////////////////////////////////////
//:: Created By:        Brent
//:: Created On:        November 2001
//:://////////////////////////////////////////////
int HasItem(object oCreature, string s)
{
    return  GetIsObjectValid(GetItemPossessedBy(oCreature, s));
}
//::///////////////////////////////////////////////
//:: Take Gold
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Takes nAmount of gold from the object speaking.
    By default, the gold is destroyed.
*/
//:://////////////////////////////////////////////
//:: Created By: Brent
//:: Created On: November 2001
//:://////////////////////////////////////////////
void TakeGold(int nAmount, object oGoldHolder, int bDestroy=TRUE)
{
    TakeGoldFromCreature(nAmount, oGoldHolder, bDestroy);
}

//::///////////////////////////////////////////////
//:: HasGold
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Checks to see if the player has nAmount of gold
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////
int HasGold(int nAmount, object oGoldHolder)
{
    return GetGold(oGoldHolder) >= nAmount;
}
//:: GetNearestPC
//////////////////////////////////////////////////
//
//  GetNearestPC
//
//////////////////////////////////////////////////
//
//
// Returns the PC closes to the object calling
// the function.
//
//////////////////////////////////////////////////
//
//  Created By: Brent
//  Created On: May 16, 2001
//
//////////////////////////////////////////////////
object GetNearestPC()
{
   return GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC);
}

//:: SetIsEnemy
//////////////////////////////////////////////////
//
//  [Function Name]
//
//////////////////////////////////////////////////
//
//
// [A description of the function.  This should contain any
// special ranges on input values]
//
//////////////////////////////////////////////////
//
//  Created By:
//  Created On:
//
//////////////////////////////////////////////////
void SetIsEnemy(object oTarget)
{
    AdjustReputation(oTarget, OBJECT_SELF,-100);
    ActionAttack(oTarget);
}
 

///////////////////////////////////////////////////////////////////////////////
//
//  AutoDC
//
///////////////////////////////////////////////////////////////////////////////
//  Returns a pass value based on the object's level and the suggested DC
// December 20 2001: Changed so that the difficulty is determined by the
// NPC's Hit Dice
// November 2002 (Brent): Adding a higher upper range for level 15+ campaigns.
// August 2003 (Georg): Fixed bug not adding up DCs in the correct order
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13 2001
///////////////////////////////////////////////////////////////////////////////
int AutoDC(int DC, int nSkill, object oTarget)
{
    /*
    Easy = Lvl/4 ...rounded up
    Moderate = 3/Lvl + Lvl ...rounded up
    Difficult = Lvl * 1.5 + 6 ...rounded up
    */
    int nLevel = GetHitDice(OBJECT_SELF);
    int nTest = 0;
    // * July 2
    // * If nLevel is less than 0 or 0 then set it to 1
    if (nLevel <= 0)
    {
        nLevel = 1;
    }
    switch (DC)
    {
        case DC_EASY: nTest = nLevel / 4 + 1; break;
            // * minor tweak to lower the values a little
        case DC_MEDIUM: nTest = (3 / nLevel + nLevel) - abs( (nLevel/2) -2); break;
        case DC_HARD: nTest = FloatToInt(nLevel * 1.5 + 6) - abs( ( FloatToInt(nLevel/1.5) -2)); break;
        case DC_SUPERIOR: nTest = 7+ FloatToInt(nLevel * 1.5 + 6) - abs( ( FloatToInt(nLevel/1.5) -2)); break;
        case DC_MASTER: nTest = 14 + FloatToInt(nLevel * 1.5 + 6) - abs( ( FloatToInt(nLevel/1.5) -2)); break;
        case DC_LEGENDARY: nTest = 21 + FloatToInt(nLevel * 1.5 + 6) - abs( ( FloatToInt(nLevel/1.5) -2)); break;
        case DC_EPIC: nTest = 28 + FloatToInt(nLevel * 1.5 + 6) - abs( ( FloatToInt(nLevel/1.5) -2)); break;
    }
 
    // *********************************
    // * CHARM/DOMINATION
    // * If charmed or dominated the NPC
    // * will be at a disadvantage
    // *********************************
    int nCharmMod = 0;
    if (nSkill == SKILL_PERSUADE || nSkill == SKILL_BLUFF || nSkill == SKILL_INTIMIDATE)
        nCharmMod = GetNPCEasyMark(oTarget);
    int nDC = nTest + 10 - nCharmMod ;
    if (nDC < 1 )
        nDC = 1;
    // * Roll d20 + skill rank vs. DC + 10
    if (GetSkillRank(nSkill, oTarget) + d20() >= (nDC) )
    {
       return TRUE;
    }
       return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
//  AutoAlignG(int DC, object oTarget)
//
///////////////////////////////////////////////////////////////////////////////
//  Adjusts the alignment of the object towards good, relative to the
//  degree indicated.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
void AutoAlignG(int DC, object oTarget)
{
    int nShift = 0;
    switch (DC)
    {
        case 0: nShift = 3;  break;
        case 1: nShift = 7; break;
        case 2: nShift = 10; break;
    }
    AdjustAlignment(oTarget, ALIGNMENT_GOOD, nShift);
}
///////////////////////////////////////////////////////////////////////////////
//
//  AutoAlignE
//
///////////////////////////////////////////////////////////////////////////////
//  Adjusts the alignment of the object towards evil, relative to the
//  degree indicated.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
void AutoAlignE(int DC, object oTarget)
{
    int nShift = 0;
    switch (DC)
    {
        case 0: nShift = 3;   break;
        case 1: nShift = 7;  break;
        case 2: nShift = 10;  break;
    }
    AdjustAlignment(oTarget, ALIGNMENT_EVIL, nShift);
}

//::///////////////////////////////////////////////
//:: DoGiveXP
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
      Gives the designated XP to the object
      using the design rules for XP
      distribution.
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////
void DoGiveXP(string sJournalTag, int nPercentage, object oTarget, int QuestAlignment=ALIGNMENT_NEUTRAL)
{
    float nRewardMod = 1.0;
    // * error handling
    if ((nPercentage < 0) || (nPercentage > 100))
    {
        nPercentage = 100;
    }
    float nXP = GetJournalQuestExperience(sJournalTag) * (nPercentage * 0.01);
    // * for each party member
    // * cycle through them and
    // * and give them the appropriate reward
    // * HACK FOR NOW
    if ((GetAlignmentGoodEvil(oTarget) == ALIGNMENT_NEUTRAL) || (QuestAlignment ==ALIGNMENT_NEUTRAL) )
    {
        nRewardMod = 1.0;
    }
    else
    if (GetAlignmentGoodEvil(oTarget) == QuestAlignment)
    {
        nRewardMod = 1.25;
    }
    else
    if (GetAlignmentGoodEvil(oTarget) != QuestAlignment)
    {
        nRewardMod = 0.75;
    }
//    AssignCommand(oTarget,SpeakString("My XP reward is: " + FloatToString(nRewardMod * nXP)));
    GiveXPToCreature(oTarget, FloatToInt(nRewardMod * nXP));
}
///////////////////////////////////////////////////////////////////////////////
//
//  RewardXP
//
///////////////////////////////////////////////////////////////////////////////
//  Gives each player the reward, scaled 1.25 times if of the correct alignment
//  and 0.75 times if of the wrong alignment.  Neutral always get the
//  1.0 times reward.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
void RewardXP(string sJournalTag, int nPercentage, object oTarget, int QuestAlignment=ALIGNMENT_NEUTRAL, int bAllParty=TRUE)
{
//   AssignCommand(oTarget, SpeakString("in rewardxp funtion"));
    if (bAllParty == TRUE)
    {
        object oPartyMember = GetFirstFactionMember(oTarget, TRUE);
        while (GetIsObjectValid(oPartyMember) == TRUE)
        {
            DoGiveXP(sJournalTag, nPercentage, oPartyMember, QuestAlignment);
            oPartyMember = GetNextFactionMember(oTarget, TRUE);
//            AssignCommand(oTarget,SpeakString("here your xp sir"));
        }
    }
    else
    {
     DoGiveXP(sJournalTag, nPercentage, oTarget, QuestAlignment);
    }

}

///////////////////////////////////////////////////////////////////////////////
//
//  RewardGP
//
///////////////////////////////////////////////////////////////////////////////
//  Gives the GP to (if bAllParty = TRUE) all party members.
//  Each players gets the GP value amount.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
void RewardGP(int GP, object oTarget,int bAllParty=TRUE)
{
    // * for each party member
    // * cycle through them and
    // * and give them the appropriate reward
    // * HACK FOR NOW
    if (bAllParty == TRUE)
    {
        object oPartyMember = GetFirstFactionMember(oTarget, TRUE);
        while (GetIsObjectValid(oPartyMember) == TRUE)
        {
            //AssignCommand(oPartyMember, SpeakString("MY GP reward is: " + IntToString(GP)));
            GiveGoldToCreature(oPartyMember, GP);
            oPartyMember = GetNextFactionMember(oTarget, TRUE);
        }
    }
    else
    {
     GiveGoldToCreature(oTarget, GP);
    }
}

// *
// * Conversation Functions
// *
///////////////////////////////////////////////////////////////////////////////
//
//  CheckCharismaMiddle
//
///////////////////////////////////////////////////////////////////////////////
//  Returns TRUE if charisma is in the normal range.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
int CheckCharismaMiddle()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_CHARISMA) >= 10 && GetAbilityScore(GetPCSpeaker(),ABILITY_CHARISMA) < 15)
 {
   return TRUE;
 }
 return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
//  CheckCharismaNormal
//
///////////////////////////////////////////////////////////////////////////////
//  Returns TRUE if charisma is in the normal range.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
int CheckCharismaNormal()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_CHARISMA) >= 10)
 {
   return TRUE;
 }
 return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
//  CheckCharismaLow
//
///////////////////////////////////////////////////////////////////////////////
//  Returns TRUE if charisma is in the low range.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
int CheckCharismaLow()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_CHARISMA) < 10)
 {
  return TRUE;
 }
 return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
//  CheckCharismaHigh
//
///////////////////////////////////////////////////////////////////////////////
//  Returns TRUE if charisma is in the high range.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
int CheckCharismaHigh()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_CHARISMA) >= 15)
 {
  return TRUE;
 }
 return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
//  CheckIntelligenceLow
//
///////////////////////////////////////////////////////////////////////////////
//  Returns TRUE if intelligence is in the low range
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
int CheckIntelligenceLow()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_INTELLIGENCE) < 9)
   return TRUE;
 return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
//  CheckIntelligenceNormal
//
///////////////////////////////////////////////////////////////////////////////
//  Returns TRUE if intelligence is in the normal range
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
int CheckIntelligenceNormal()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_INTELLIGENCE) >= 9)
   return TRUE;
 return FALSE;
}
//::///////////////////////////////////////////////
//:: CheckIntelligenceHigh
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////
int CheckIntelligenceHigh()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_INTELLIGENCE) >= 15)
   return TRUE;
 return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
//  CheckWisdomHigh
//
///////////////////////////////////////////////////////////////////////////////
//  Returns TRUE if wisdom is in the High range
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 13, 2001
///////////////////////////////////////////////////////////////////////////////
int CheckWisdomHigh()
{
 if (GetAbilityScore(GetPCSpeaker(),ABILITY_WISDOM) > 13)
   return TRUE;
 return FALSE;
}
int GetWisdom(object oTarget)
{
    return GetAbilityScore(oTarget, ABILITY_WISDOM);
}
int GetIntelligence(object oTarget)
{
    return GetAbilityScore(oTarget, ABILITY_INTELLIGENCE);
}
int GetCharisma(object oTarget)
{
    return GetAbilityScore(oTarget, ABILITY_CHARISMA);
}
//:: GetNumItems
//////////////////////////////////////////////////
//
//  GetNumItems
//
//////////////////////////////////////////////////
//
//
// Returns the number of specified item in the
// target's inventory.
//
//////////////////////////////////////////////////
//
//  Created By: John
//  Created On: September 19, 2001
//
//////////////////////////////////////////////////
int GetNumItems(object oTarget,string sItem)
{
    int nNumItems = 0;
    object oItem = GetFirstItemInInventory(oTarget);
    while (GetIsObjectValid(oItem) == TRUE)
    {
        if (GetTag(oItem) == sItem)
        {
            nNumItems = nNumItems + GetNumStackedItems(oItem);
        }
        oItem = GetNextItemInInventory(oTarget);
    }
   return nNumItems;
}
//:: GiveNumItems
//////////////////////////////////////////////////
//
//  GiveNumItems
//
//////////////////////////////////////////////////
//
//
// Gives the target the number of items specified.
//
//////////////////////////////////////////////////
//
//  Created By: John
//  Created On: September 19, 2001
//
//////////////////////////////////////////////////
void GiveNumItems(object oTarget,string sItem,int nNumItems)
{
    int nCount = 0;
    object oItem = GetFirstItemInInventory(OBJECT_SELF);
    while (GetIsObjectValid(oItem) == TRUE && nCount < nNumItems)
    {
        if (GetTag(oItem) == sItem)
        {
            ActionGiveItem(oItem,oTarget);
            nCount++;
        }
        oItem = GetNextItemInInventory(OBJECT_SELF);
    }
   return;
}
//:: TakeNumItems
//////////////////////////////////////////////////
//
//  TakeNumItems
//
//////////////////////////////////////////////////
//
//
// Takes the number of items specified from the target.
//
//////////////////////////////////////////////////
//
//  Created By: John
//  Created On: September 19, 2001
//
//////////////////////////////////////////////////
void TakeNumItems(object oTarget,string sItem,int nNumItems)
{
    int nCount = 0;
    object oItem = GetFirstItemInInventory(oTarget);
    while (GetIsObjectValid(oItem) == TRUE && nCount < nNumItems)
    {
        if (GetTag(oItem) == sItem)
        {
            ActionTakeItem(oItem,oTarget);
            nCount++;
        }
        oItem = GetNextItemInInventory(oTarget);
    }
   return;
}

///////////////////////////////////////////////////////////////////////////////
//
//  GetReactionAdjustment
//
///////////////////////////////////////////////////////////////////////////////
//  Returns the adjusted Reaction for the purposes of store pricing.
///////////////////////////////////////////////////////////////////////////////
//  Created By: Brent, September 25, 2001
///////////////////////////////////////////////////////////////////////////////
 float GetReactionAdjustment(object oTarget)
{
    float nFactionAdjustment = 2.0;
    // (i)
    if (GetIsFriend(oTarget) == TRUE)
    {
        nFactionAdjustment = 1.0;
    }
    // (ii)
    int oTargetLawChaos = GetLawChaosValue(oTarget);
    int oTargetGoodEvil = GetGoodEvilValue(oTarget);
    int oSourceLawChaos = GetLawChaosValue(OBJECT_SELF);
    int oSourceGoodEvil = GetGoodEvilValue(OBJECT_SELF);
    int APB = abs(oSourceLawChaos - oTargetLawChaos)  + abs(oSourceGoodEvil - oTargetGoodEvil);
    int nTargetCharismaMod = GetAbilityModifier(ABILITY_CHARISMA, oTarget);
    return abs(10 + APB - (nTargetCharismaMod * 10)) * nFactionAdjustment;
}
//::///////////////////////////////////////////////
//:: AdjustFactionReputation
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Adjusts all faction member's reputation visa via
    another faction.  Pass in a member from each
    faction.
*/
//:://////////////////////////////////////////////
//:: Created By: Presotn Watamaniuk
//:: Created On: Nov 15, 2001
//:://////////////////////////////////////////////
void AdjustFactionReputation(object oTargetCreature, object oMemberOfSourceFaction, int nAdjustment)
{
    object oFaction = GetFirstFactionMember(oTargetCreature);
    while(GetIsObjectValid(oFaction))
    {
        AdjustReputation(oTargetCreature, oMemberOfSourceFaction, nAdjustment);
        oFaction = GetNextFactionMember(oTargetCreature);
    }
    AdjustReputation(oTargetCreature, oMemberOfSourceFaction, nAdjustment);
}
//::///////////////////////////////////////////////
//:: Escape Via Teleport
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Makes the person teleport away and look like
    they are casting a spell.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: March 12, 2002
//:://////////////////////////////////////////////
void EscapeViaTeleport(object oFleeing)
{
    effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3);
    ActionCastFakeSpellAtObject(SPELL_MINOR_GLOBE_OF_INVULNERABILITY, oFleeing);
    DelayCommand(1.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetLocation(oFleeing)));
    DestroyObject(oFleeing, 2.5);
}

//::///////////////////////////////////////////////
//:: GetP(arty)LocalInt
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Scans through all players in the party, to
    treat them all as 'one person' for the purposes
    of most plots. Makes our plots more multiplayer friendly.
*/
//:://////////////////////////////////////////////
//:: Created By: John
//:: Created On:
//:://////////////////////////////////////////////
int GetPLocalInt(object oPC,string sLocalName)
{
    int nValue = 0;
    object oMember;
    oMember = GetFir

Modifié par Lazarus Magni, 29 décembre 2013 - 03:51 .


#19
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
And...

_functions_text:


//:://////////////////////////////////////////////////////////////////////////
//:: Created By:    Demented
//:: Name:          Various Text Functions
//:: Modified:
//:: Date           Description
//:: -------------------------------------------------------------------------
//::
//::////////////////////////////////////////////////////////////////////////////
/*
    This function returns a RGB colored sting, be very careful with the
    COLORTOKEN if u alter it all this will not work.
*/
#include "blg_inc"
#include "loc_colour"
/*
//  Returns a properly color-coded sText string based on specified RGB values
string ColourString(string sText, int nRed=255, int nGreen=255, int nBlue=255);
*/
//  Shouts a color-coded Text string based on specified RGB values
void ShoutColoredGuildString(string sShout, object oShouter);
//  Shouts a color-coded Text string based on specified RGB values
void ArenaColoredShoutString(string sShout);
//  Displays a color-coded Text string in only a designated area.
void AreaColoredSpeakString(string sShout, string sAreaname);
//  Float a color-coded Text string to specific area.
void AreaColoredFloatingString(string sMessage, string sAreaname, object oPlayer);
//  This assigns custom tokens for conversation menu's.
void AssignColorTokens();
//  Float a Color-coded Floating Text string based on specified RGB values
void ColoredFloatingString(string sMessage, object oPlayer, int iColor);
//  Float a Complete colored Message based on specified RGB values
void ColoredMessage(object oMessageHolder, object oPlayer, int iColor);
//  Float a Alernate colored Message based on specified RGB values
void ColoredAltMessage(object oMessageHolder, object oPlayer, int iColor);
//  Float a Complete colored Message based on specified RGB values Once
void ColoredMessageOnce(object oMessageHolder, object oPlayer, int iColor);

////////////////////////////////////////////////////////////////////////////////
/*
//------------------------------------------------------------------------------
//-     Returns a properly color-coded sText string based on specified RGB values
//------------------------------------------------------------------------------
string ColourString(string sText, int nRed=255, int nGreen=255, int nBlue=255)
{
    return "<c" + GetSubString(COLOURTOKEN, nRed, 1) + GetSubString(COLOURTOKEN, nGreen, 1) + GetSubString(COLOURTOKEN, nBlue, 1) + ">" + sText + "</c>";
}
*/
//------------------------------------------------------------------------------
//  Shouts a color-coded Text string based on specified RGB values
//------------------------------------------------------------------------------
void ShoutColoredGuildString(string sShout, object oShouter)
{
    int     iC1 = 255;
    int     iC2 = 255;
    int     iC3 = 255;
    int     iGuildID    = GetGuildID(oShouter);
    string  sGuildName  = GetGuildName(iGuildID);
    string  sRankName   = GetRankName(0, iGuildID);
    //  Set the Guild Colors for Shouts
    if(iGuildID == 0) {iC1 = 147;  iC2 = 112;  iC3 = 216;}  //Advos
    if(iGuildID == 1) {iC1 = 178;  iC2 = 34;  iC3 = 34;}  //Advos
    if(iGuildID == 2) {iC1 = 255;  iC2 = 255;  iC3 = 255;} //OBR
    if(iGuildID == 3) {iC1 = 0;  iC2 = 128;  iC3 = 0;} //Kittens
    if(iGuildID == 4) {iC1 = 65; iC2 = 105; iC3 = 205;}  //Outlawz
    if(iGuildID == 5) {iC1 = 128;  iC2 = 128;  iC3 = 128;} //BoS
    if(iGuildID == 6) {iC1 = 34;  iC2 = 205;  iC3 = 178;} //LoV
    SpeakString(ColourString(sShout, iC1, iC2, iC3), TALKVOLUME_SHOUT);
    return;
}

//------------------------------------------------------------------------------
//  Shouts a color-coded Text string based on specified RGB values
//------------------------------------------------------------------------------
void ArenaColoredShoutString(string sShout)
{
    //  Set the Color for the Shout.
    int iC1 = iC1 = 0, iC2 = 128, iC3 = 128;
    SpeakString(ColourString(sShout, iC1, iC2, iC3), TALKVOLUME_SHOUT);
    return;
}
//------------------------------------------------------------------------------
//  Displays a color-coded Text string only in a designated area.
//------------------------------------------------------------------------------
void AreaColoredSpeakString(string sMessage, string sAreaname)
{
    object  oObject = GetFirstPC();
    int iLoop_Cnt   = 0;
    int iMax_Objects = 40;
    //  Set the Color for the Shout.{112, 128, 144}
    int iC1 = iC1 = 0, iC2 = 128, iC3 = 128;
    //  Start a loop throught the player base in game.
    while (GetIsObjectValid(oObject) && iLoop_Cnt <= iMax_Objects)
    {
        //  If the player is located in the designated area.
        if(GetName(GetArea(oObject)) == sAreaname)
        {
            //  Send them the included message.
            SpeakString(ColourString(sMessage, iC1, iC2, iC3), TALKVOLUME_TALK);
         }
         // Increment the Count and get the next player.
         iLoop_Cnt++;
         oObject = GetNextPC();
    }
}
//------------------------------------------------------------------------------
//  Speak a Floating color-coded Text string to all in a specific area.
//------------------------------------------------------------------------------
void AreaColoredFloatingString(string sMessage, string sAreaname, object oPlayer)
{
    object  oObject = GetFirstPC();
    int iLoop_Cnt   = 0;
    int iMax_Objects = 40;
    //  Set the Color for the Shout.
    int iC1 = 0, iC2 = 128, iC3 = 128;
    //  Start a loop throught the player base in game.
    while (GetIsObjectValid(oObject) && iLoop_Cnt <= iMax_Objects)
    {
        //  If the player is located in the designated area.
        if(GetName(GetArea(oObject)) == sAreaname)
        {
            //  Send them the included message.
            FloatingTextStringOnCreature(ColourString(sMessage, iC1, iC2, iC3), oPlayer, FALSE);
         }
         // Increment the Count and get the next player.
         iLoop_Cnt++;
         oObject = GetNextPC();
    }
}
//------------------------------------------------------------------------------
//  This assigns custom tokens for conversation menu's.
//------------------------------------------------------------------------------
void AssignColorTokens()
{
    SetCustomToken(100, "</c>");   // CLOSE tag
    SetCustomToken(101, "<cþ  >"); // red
    SetCustomToken(102, "<c þ >"); // green
    SetCustomToken(103, "<c  þ>"); // blue
    SetCustomToken(104, "<c þþ>"); // cyan
    SetCustomToken(105, "<cþ þ>"); // magenta
    SetCustomToken(106, "<cþþ >"); // yellow
    SetCustomToken(107, "<c   >"); // black
    SetCustomToken(108, "<c¥  >"); // dark red
    SetCustomToken(109, "<c ¥ >"); // dark green
    SetCustomToken(110, "<c  ¥>"); // dark blue
    SetCustomToken(111, "<c ¥¥>"); // dark cyan
    SetCustomToken(112, "<c¥ ¥>"); // dark magenta
    SetCustomToken(113, "<c¥¥ >"); // dark yellow
    SetCustomToken(114, "<c¥¥¥>"); // grey
    SetCustomToken(117, "<cŒŒŒ>"); // dark grey
    SetCustomToken(115, "<cþ¥ >"); // orange
    SetCustomToken(116, "<cþŒ >"); // dark orange
    SetCustomToken(117, "<cÚ¥#>"); // brown
    SetCustomToken(118, "<c† >"); // dark brown
    return;
}

//------------------------------------------------------------------------------
//  Float a Color-coded Floating Text string based on specified RGB values
//------------------------------------------------------------------------------
void ColoredFloatingString(string sMessage, object oPlayer, int iColor)
{
    int     iC1 = 255;
    int     iC2 = 255;
    int     iC3 = 255;
    //  Set the Guild Colors for Shouts,
    if(iColor ==  0) {iC1 = 255; iC2 = 255; iC3 = 255;}   //
    if(iColor ==  1) {iC1 = 178; iC2 = 34;  iC3 = 34;}    //Advos
    if(iColor ==  2) {iC1 = 255; iC2 = 255; iC3 = 255;}   //OBR
    if(iColor ==  3) {iC1 = 0;   iC2 = 128; iC3 = 0;}     //Kittens
    if(iColor ==  4) {iC1 = 65;  iC2 = 105; iC3 = 205;}   //Outlawz
    if(iColor ==  5) {iC1 = 128; iC2 = 128; iC3 = 128;}   //BoS
    if(iColor ==  6) {iC1 = 34;  iC2 = 205; iC3 = 178;}   //LoV
    // Used for other colored shouts.
    if(iColor ==  7) {iC1 = 240; iC2 = 1;   iC3 = 1;}     //Red
    if(iColor ==  8) {iC1 = 1;   iC2 = 240; iC3 = 1;}     //Green
    if(iColor ==  9) {iC1 = 1;   iC2 = 1;   iC3 = 240;}   //Blue
    if(iColor == 10) {iC1 = 185; iC2 = 185; iC3 = 185;}   //Grey
    if(iColor == 11) {iC1 = 30;  iC2 = 210; iC3 = 210;}   //Yellow
    //  Send them the included message.
    FloatingTextStringOnCreature(ColourString(sMessage, iC1, iC2, iC3), oPlayer, FALSE);
    return;
}

//------------------------------------------------------------------------------
//  Float a Complete colored Message based on specified RGB values
//------------------------------------------------------------------------------
void ColoredMessage(object oMessageHolder, object oPlayer, int iColor)
{
    int     iNum_Messages, iMax_Messages = 9;
    string  sVariable, sMessage;
    float   fDelay;
    //  Loop and Display The Message if it exists.
    for (iNum_Messages = 1; iNum_Messages <= iMax_Messages; iNum_Messages++)
    {
        //  Grab the next territory marker.
        sVariable = "Message" + IntToString(iNum_Messages);
        sMessage  = GetLocalString(oMessageHolder, sVariable);
        if (sMessage != "")
        {
            //  Float the Message.
            fDelay = IntToFloat(iNum_Messages);
            DelayCommand(fDelay, ColoredFloatingString(sMessage, oPlayer, iColor));
        }
    }
}
//------------------------------------------------------------------------------
//  Float a Alernate colored Message based on specified RGB values
//------------------------------------------------------------------------------
void ColoredAltMessage(object oMessageHolder, object oPlayer, int iColor)
{
    int     iNum_Messages, iMax_Messages = 9;
    string  sVariable, sMessage;
    float   fDelay;
    //  Loop and Display The Message if it exists.
    for (iNum_Messages = 1; iNum_Messages <= iMax_Messages; iNum_Messages++)
    {
        //  Grab the next territory marker.
        sVariable = "MessageAlt" + IntToString(iNum_Messages);
        sMessage  = GetLocalString(oMessageHolder, sVariable);
        if (sMessage != "")
        {
            //  Float the Message.
            fDelay = IntToFloat(iNum_Messages);
            DelayCommand(fDelay, ColoredFloatingString(sMessage, oPlayer, iColor));
        }
    }
}
//------------------------------------------------------------------------------
//  Float a Complete colored Message based on specified RGB values Once
//------------------------------------------------------------------------------
void ColoredMessageOnce(object oMessageHolder, object oPlayer, int iColor)
{
    int     iNum_Messages, iMax_Messages = 9;
    string  sVariable, sMessage;
    float   fDelay;
    string  sVarname    = GetTag(oMessageHolder);
    int     iViewOnce   = GetLocalInt(oPlayer, sVarname);
    //  Test to see if already viewed.
    if(!iViewOnce)
    {
        //  Loop and Display The Message if it exists.
        for (iNum_Messages = 1; iNum_Messages <= iMax_Messages; iNum_Messages++)
        {
            //  Grab the next territory marker.
            sVariable = "Message" + IntToString(iNum_Messages);
            sMessage  = GetLocalString(oMessageHolder, sVariable);
            if (sMessage != "")
            {
                //  Float the Message.
                fDelay = IntToFloat(iNum_Messages);
                DelayCommand(fDelay, ColoredFloatingString(sMessage, oPlayer, iColor));
            }
        }
    }
}

Modifié par Lazarus Magni, 29 décembre 2013 - 03:53 .


#20
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
kt_arrowtrap- no starting conditional
makeavatar- no starting conditional

On thees two,  you are either trying to compile a regular script as a Starting Condition or they are not scripts at all.  If the are include files.  This error is normal and nothing to worry about.    


x2_inc_switches.nss(17): ERROR: FUNCTION DEFINITION MISSING NAME
x0_i0_positionav.nss(18): ERROR: FUNCTION DEFINITION MISSING NAME
 
Never seen this one before,  Either a function has no name,   something like  

void ();

or 
 int ()
{ }

or it may be related to the problem you are having below. 

zero_ggdi.nss(515): ERROR: UNDEFINED IDENTIFIER (DrawStar)

here an identerfier has not been defined,  It could be that an include is miss-named or not included. 


 _functions_misc.nss(148): ERROR: PARSING VARIABLE LIST

this one could be that you have the same lable defined twice in the same namespace.  or related to the one below. 

inc_divineinterv.nss(183): ERROR: IDENTIFIER LIST FULL

this one is your biggest problem and may be causing all the other ones.   
it is bascally saying that your lable list in you scripts has gotten so bit that is is exceeding the limits of the nwn compiler.   Your option here is to either shorten or limit the number of includes that you place in a script or start using one of the external compilers.    like the PRC compiler.   I have never used any of them so can not help much.    

#21
Lazarus Magni

Lazarus Magni
  • Members
  • 1 134 messages
Thanks Light. I appreciate the input.