186 lines
4.5 KiB
Plaintext
186 lines
4.5 KiB
Plaintext
//Script Name: time_tutorial
|
|
//////////////////////////////////////////
|
|
//Created By: Genisys (Guile)
|
|
//Created On: 8/16/08
|
|
/////////////////////////////////////////
|
|
/*
|
|
|
|
The purpose of this Tutorial is to show you how to use the
|
|
Time System I set up within scripting to get Current Real
|
|
Time that has passed since the module has been started.
|
|
|
|
//////////////////////USING REAL TIME/////////////////////////////
|
|
|
|
These variables below will get you the exact time, which is
|
|
exactly how much time has passed since the module started in
|
|
hours, minutes, & seconds, or the total amount of time in
|
|
minutes or seconds that has passed since the module started.
|
|
|
|
|
|
//////////////Example of Time Use In Scripting////////////////////
|
|
|
|
If 2hrs 30 minutes and 24 seconds have passed since the module
|
|
started, The the variables below would return this information..
|
|
|
|
nHr = 2 // nMin = 30 // nSec = 24
|
|
|
|
nTotalMin = 150 // nTotalSec = 9024
|
|
|
|
(NOTE: nTotalMin = The total Time that has passed in Minutes ONLY!
|
|
(NOTE: nTotalSec = The total Time that has passed in Seconds ONLY!
|
|
|
|
Everything below should be used in your scripts after void main
|
|
exactly how you see it below!
|
|
|
|
///////////////////////EXAMPLE SCRIPT//////////////////////////////
|
|
|
|
//Main Script Starts Here..
|
|
void main()
|
|
{
|
|
|
|
//////////////CURRENT REAL TIME VARIABLE DEFINITIONS/////////////////
|
|
|
|
int nMT = GetLocalInt(GetObjectByTag("timekeeper"), "moduletime");
|
|
|
|
int nHr = GetLocalInt(GetObjectByTag("timekeeper"), "MODHR");
|
|
int nMin = GetLocalInt(GetObjectByTag("timekeeper"), "MODMIN");
|
|
int nSec = GetLocalInt(GetObjectByTag("timekeeper"), "MODSEC");
|
|
|
|
int nTotalSec = nMT*6; //(Total Time in Seconds)
|
|
int nTotalMin = nTotalSec/60; //(Total Time in Minutes)
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//Your main script code would go here..
|
|
|
|
|
|
|
|
//Main Script Ends Here...
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
/////////////////////MORE NOTES/////////////////////////////////////
|
|
|
|
You can do a variety of things with the Current Real Time
|
|
Variable Definitions in a script, depending upon what kind of
|
|
script it is, and what you want to do.
|
|
|
|
Look at the example functions below to see
|
|
just how easy this Time System makes it for you!
|
|
|
|
///////////////////////////////////////////////////////
|
|
Example Functions:
|
|
//////////////////////////////////////////////////////
|
|
|
|
(In the OnEnter Event Script for an Encounter Trigger)
|
|
|
|
|
|
if(nHr<3)
|
|
{
|
|
//For the first 3 Hours do this...
|
|
//(you could increase or lower the # of creatures)
|
|
}
|
|
|
|
else if(nHr>=3 && nHr<6)
|
|
{
|
|
//For the following 3 hours do this instead
|
|
}
|
|
|
|
else
|
|
{
|
|
//Otherwise continue to do this after 6 hours have passed
|
|
}
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
(In an OnEnter Event for an area or tracks trigger)
|
|
|
|
|
|
if(nMin<30)
|
|
{
|
|
//For the first 30 minutes do this..
|
|
}
|
|
|
|
else
|
|
{
|
|
//For the next 30 minutes do this instead..
|
|
}
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
(In a OnHeartbeat Event Script)
|
|
NOTE: Heartbeat script run every 6 seconds continuously
|
|
It's a little harder to code time for these scripts, but
|
|
I assure you it's A LOT Easier with this system in place!
|
|
|
|
if(nSec==6)
|
|
{
|
|
Do This every Minute ONLY..
|
|
}
|
|
|
|
if(nMin==30 && nSec==6)
|
|
{
|
|
//Do something every 30 minutes
|
|
//nSec==6 make sure it fires only one time at the 30 minute mark
|
|
}
|
|
|
|
|
|
if((nMin==9 || nMin ==19 || nMin ==29 || nMin==39 ||
|
|
nMin==49 || nMin ==59) && (nSec==6))
|
|
{
|
|
//Do This Once Every 10 Minutes
|
|
}
|
|
|
|
|
|
if((nHr ==2 || nHr ==4 || nHr ==6 || nHr ==8 ||
|
|
nHr ==10 || nHr ==12) && (nMin ==1) && (nSec==6))
|
|
{
|
|
Do this Once Every 2 Hours...
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//Set this to how often (in minutes) you want this function to run
|
|
int nInterval = 10; //10 = default (ever 10 minutes)
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
//For Timed Intervaled Functions.. (On Heartbeat ONLY)
|
|
//////////////////////////////////////////////////////////////////
|
|
int
|
|
int nMC2 = GetLocalInt(oMe, "INTVCOUNT");
|
|
int nMT2 = (nMC2*nInterval);
|
|
int nTimesN;
|
|
|
|
if(nMC2==0)//can't multiply by 0 to get the interval!
|
|
{ nTimesN = nMsgTime; }//The Interval Variable
|
|
else
|
|
{ nTimesN = nMT2; }//The # of Counts * The Interval Variable.
|
|
|
|
//If the Total # of Minutes = (The Interval * The Interval Count)
|
|
if(nTotalMin==nTimesN && nSec==6) //Check only Once / minute!
|
|
{
|
|
|
|
if(nMC1>0)
|
|
{nInc1 = nMC1 + 1;}
|
|
else
|
|
{nInc1 = 2;}
|
|
|
|
SetLocalInt(oMe, "INTVCOUNT", nInc1);
|
|
|
|
|
|
//Enter your code here.....
|
|
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
////NOTE: This is here only for compiling purposes, don't touch..
|
|
*/
|
|
void main()
|
|
{
|
|
|
|
}
|