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