Author Topic: Could use some help merging a few scripts.  (Read 834 times)

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« on: December 26, 2013, 02:47:14 am »


               #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(){}
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #1 on: December 26, 2013, 02:47:59 am »


               With...
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #2 on: December 26, 2013, 02:48:30 am »


               // 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 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #3 on: December 26, 2013, 02:50:15 am »


               These are aps_include scripts.
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #4 on: December 26, 2013, 02:51:51 am »


               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 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #5 on: December 26, 2013, 02:55:22 am »


               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 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #6 on: December 26, 2013, 02:57:19 am »


               Any help would certainly be appreciated.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #7 on: December 26, 2013, 03:24:47 am »


               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.
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #8 on: December 26, 2013, 05:37:28 pm »


               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
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #9 on: December 26, 2013, 06:22:39 pm »


               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.
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #10 on: December 26, 2013, 07:18:20 pm »


               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?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #11 on: December 26, 2013, 07:25:30 pm »


               

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
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #12 on: December 26, 2013, 07:36:07 pm »


                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 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #13 on: December 26, 2013, 08:45:45 pm »


               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 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Could use some help merging a few scripts.
« Reply #14 on: December 26, 2013, 10:00:21 pm »


               if you send me those files on email i can merge it for you, but this mess you send on forums is useless '<img'>