REO-EE/_module/nss/rwt_include.nss
Jaysyn904 f82740bbbd Initial commit
Initial commit
2024-02-22 13:22:03 -05:00

102 lines
3.0 KiB
Plaintext

#include "inc_system_const"
#include "inc_mysql_tables"
// Number of seconds in one day
const int RWT_NUMBER_OF_SECONDS_IN_DAY = 86400;
// Number of seconds in one week
const int RWT_NUMBER_OF_SECONDS_IN_WEEK = 604800;
// Number of seconds in one month
const int RWT_NUMBER_OF_SECONDS_IN_MONTH = 2629744;
// Number of hours a player has sanctuary from PVP and the death system
// Default: 72
const int RWT_PLAYER_SANCTUARY_HOURS = 72;
// Returns real world time in the format as follows:
// '2010-05-14 01:31:07'
string RWT_GetCurrentTimestamp();
// Returns the amount of time between two timestamps
// Both parameters must be in the format as follows:
// '2010-05-14 01:31:07'
// Note: The order DOES matter. If Timestamp1 is earlier than Timestamp2,
// the return value will be negative. If reversed, it will be positive.
// Make sure you're aware of this if you use this function.
// Return value is in format as follows:
// '-72:12:34'
string RWT_GetTimeDiff(string sTimestamp1, string sTimestamp2);
// Checks a player to see if they have sanctuary.
// If they do, returns TRUE
// If not, returns FALSE
int RWT_GetDoesPlayerHaveSanctuary(object oPC);
// Returns the UNIX timestamp (Number of seconds since January 1st 1970)
int RWT_GetUnixTimestamp();
// Convenience function.
// Simply adds iSeconds to the current unix timestamp and returns the new value
// Useful for storing cooldown information
int RWT_CreateCooldown(int iSeconds);
// Returns a readable timestamp (date, time) from a unix timestamp
string RWT_GetTimestampFromUnix(int iUnixTimestamp);
string RWT_GetCurrentTimestamp()
{
string sSQL = "SELECT CURRENT_TIMESTAMP";
SQLExecDirect(sSQL);
SQLFetch();
return SQLGetData(1);
}
string RWT_GetTimeDiff(string sTimestamp1, string sTimestamp2)
{
string sSQL = "SELECT TIMEDIFF('" + sTimestamp1 + "', '" + sTimestamp2 + "')";
SQLExecDirect(sSQL);
SQLFetch();
return SQLGetData(1);
}
int RWT_GetDoesPlayerHaveSanctuary(object oPC)
{
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iCreationInt = GetLocalInt(oDatabase, CHARACTER_CREATION_DATE);
int iTimestamp = RWT_GetUnixTimestamp();
// Check to see if PC has disabled sanctuary. If he has, we can return FALSE right now.
if(GetLocalInt(oDatabase, "CHARACTER_SANCTUARY_DISABLED") == TRUE)
return FALSE;
iTimestamp = abs(iTimestamp - iCreationInt);
if(iTimestamp < ((RWT_PLAYER_SANCTUARY_HOURS * 60) * 60))
return TRUE;
// Otherwise, the PC does not have sanctuary
else return FALSE;
}
int RWT_GetUnixTimestamp()
{
string sSQL = "SELECT UNIX_TIMESTAMP()";
SQLExecDirect(sSQL);
SQLFetch();
return StringToInt(SQLGetData(1));
}
int RWT_CreateCooldown(int iSeconds)
{
return RWT_GetUnixTimestamp() + iSeconds;
}
string RWT_GetTimestampFromUnix(int iUnixTimestamp)
{
string sSQL = "SELECT FROM_UNIXTIME(" + IntToString(iUnixTimestamp) + ")";
SQLExecDirect(sSQL);
SQLFetch();
return SQLGetData(1);
}
// Error checking
//void main(){}