There's a few ways you can do this, depending if you're working with persistency functions and an external database.
For short-term timers, the easiest method is to set a local int, and then delete it after a set time using a DelayCommand(). Then you add a check to the start of your script that aborts it if the int is set to TRUE. For example...
Code: Select all
int iTest = GetLocalInt(OBJECT_SELF, "Stored_Value");
if (iTest)
return;
// Your Code Here
SetLocalInt(OBJECT_SELF, "Stored_Value", TRUE);
DelayCommand(10.0, DeleteLocalInt(OBJECT_SELF, "Stored_Value"));
That only works within the time-frame of a server reset, however. If you want a Persistent timer, a-la inn rooms, you've got two options.
1. SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration = 0, string sTable = "pwdata")
If you pass a value for iExpiration into SetPersistentInt(), the variable will be deleted from the database in that many days. This is accomplished by an external program that runs once per day, and decrements the value in this field, deleting any that would drop to zero. I believe that it only works on the pwdata table, and has to be set up specially.
2. Datetimes. Yay.
Code: Select all
SQLExecDirect("select (unix_timestamp(now())");
SQLFetch();
iReturn = StringToInt(SQLGetData(1));
That snippet of code will return the current time, presented as the number of seconds since some reference value. Not sure what the reference value is, but it doesn't really matter. What you can do, though, is record this value either as a normal or persistent int, and then compare it to the current time later on to determine how much time has passed. For example...
Code: Select all
SQLExecDirect("select (unix_timestamp(now())");
SQLFetch();
int iTime = StringToInt(SQLGetData(1));
int iStoredTime = GetLocalInt(OBJECT_SELF, "Stored_Time");
if (iTime < (iStoredTime + 10))
return;
//Your Code Here
SetLocalInt(OBJECT_SELF, "Stored_Time", iTime);
Note that in both examples, the delay is set for 10 seconds. Note also, that the last two options require some for of persistent data storage and NWNX.