Author Topic: ERROR TMI Help needed  (Read 905 times)

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« on: July 28, 2011, 09:13:59 pm »


               At the moment i have 4 scripts that give me a Error: Too Many Instructions, how can i solve that problem? here is the first one that gives the error (also the one in Comments at the beggining it says something about hc_on_cli_enter" that one gives me TMI error too:

/*----------------------------------------------------------------------------
  File        : nd_pc_idcheck
  Updated     : 11.10.2005 (Dray)
  Description : Makes sure the player has his unique id item
                Used to separate characters with the same user and name
  Comments    : Called from hc_on_cli_enter
----------------------------------------------------------------------------*/
#include "aps_include"

// Creates the ID card on the player
void nd_CreateIdOnPlayer (object oPlayer);

void main()
{

    object oPlayer = OBJECT_SELF;

    if (!GetIsObjectValid(oPlayer))
        return;

    // Make sure the player gets his id papers
    if (GetItemPossessedBy(oPlayer,"IdentificationPaper") == OBJECT_INVALID)
        nd_CreateIdOnPlayer(oPlayer);

}

void nd_CreateIdOnPlayer (object oPlayer)
{

    if (!GetIsObjectValid(oPlayer))
        return;

    string sUser = GetPCPlayerName(oPlayer);

    string sName = GetName(oPlayer);

    string sRnd = IntToString(Random(10))+
                  IntToString(Random(10))+
                  IntToString(Random(10))+
                  IntToString(Random(10));

    string sTemp = sUser + sName + sRnd;

    string sId = GetMD5Hash(sTemp);

    if (sId == "")
    {
        SendMessageToAllDMs("Warning: Failed to create id papers for player :"+sName);
        return;
    }

    object oItem = CreateItemOnObject("identificationpa",oPlayer);

    // Store the characters unique id on the item object
    SetLocalString(oItem,"ND_PC_ID",sId);

    // Make sure the character is saved
    ExportSingleCharacter(oPlayer);
}
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #1 on: July 28, 2011, 09:47:59 pm »


               check your include resources for a infinite loop.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #2 on: July 28, 2011, 09:56:21 pm »


               string sId = GetMD5Hash(sTemp);

this is causing that, so can you send full definition of this function?
               
               

               
            

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #3 on: July 29, 2011, 03:32:11 pm »


               // Returns a MD5 hash of sString
string GetMD5Hash(string sString)

thats all...not sure what its for..
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #4 on: July 29, 2011, 04:36:33 pm »


               that's not all. you must find the function and see what it does. it's either in "aps_include" or in a file that file includes
               
               

               
            

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #5 on: July 29, 2011, 04:49:09 pm »


               Im in aps_include now, found this:
string GetMD5Hash(string sString)
{

   string sResult;

   // Get rid of possible single quotes
   sString = SQLEncodeSpecialChars(sString);

   string sQ = "SELECT MD5('"+sString+"')";
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #6 on: July 29, 2011, 09:55:41 pm »


               continue down into this function: SQLEncodeSpecialChars(sString);
               
               

               
            

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #7 on: July 30, 2011, 01:03:44 pm »


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

Further down it says:
// 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)
   {
               
               

               
            

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #8 on: July 30, 2011, 01:05:35 pm »


               and conutes with this

       // 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 "";
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #9 on: July 30, 2011, 03:29:19 pm »


               those are not the right functions. you only list the prototype not the function body.
               
               

               
            

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #10 on: July 30, 2011, 04:52:12 pm »


               How about this

}

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")
{
   return StringToInt(GetPersistentString(oObject, sVarName, sTable));
}

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")
{
   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);
}

// 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;
}
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #11 on: July 30, 2011, 07:50:28 pm »


               the loop is inefficent but you shouldn't hit TMI with it. there is faster ways of replace a ~ with a ' in string repeated use of FindSubString.and you will cut up the string faster. unless the string has a majority of special chars in that case this will be faster. Which is a unlikley scenerio.
               
               

               
            

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #12 on: August 01, 2011, 08:48:32 am »


               ok so i should try to replace all these in the strings: ~ inte these '?

for example it should be like this: sChar = GetSubString(sString, i, 1);
if (sChar == "'")

instead of sChar = GetSubString(sString, i, 1);
if (sChar == "~")
?
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #13 on: August 01, 2011, 04:31:31 pm »


               No there is nothing wrong with the script it's a bit inefficent in design. It should work and unless you knwo what your doing it's better to leave it as it is.
               
               

               
            

Legacy_G0000fy

  • Newbie
  • *
  • Posts: 44
  • Karma: +0/-0
ERROR TMI Help needed
« Reply #14 on: August 03, 2011, 01:25:35 pm »


               If the script looks ok, how then do i get the TMI Error...dont get that one..