219 lines
8.2 KiB
Plaintext
219 lines
8.2 KiB
Plaintext
////////////////////////////////////////////////////////////////////////////
|
|
// Deva's Encounter System - des_oe_trigger
|
|
// By Deva Bryson Winblood. 12/24/2003
|
|
////////////////////////////////////////////////////////////////////////////
|
|
/* the trigger requires a nearby waypoint with the tag des_waypoint. The
|
|
name field of this waypoint is used to define the encounter type.
|
|
<triggered by>.<duration in hours>.<day/night>.<spawn locations>.<spawn tag>.
|
|
<script>
|
|
TRIGGERED BY is P for PC only, N for NPC only, or A for all.
|
|
DURATION IN HOURS is 0 if the creatures spawn and remain until killed. Any
|
|
other number signifies how many hours the creature will remain spawned.
|
|
DAYNIGHT tells whether there are two different encounter tables one for DAY
|
|
and one for NIGHT. T = TRUE there are two encounter tables, F = FALSE there
|
|
is only one encounter table.
|
|
SPAWN LOCATIONS indicates how many different waypoints are placed for this
|
|
trigger to spawn creatures at.
|
|
SPAWN TAG is the tag of the spawn waypoints. A # will be appended to the end.
|
|
SCRIPT is the script you wish the spawned creature to execute or NA.
|
|
|
|
ENCOUNTER TABLES:
|
|
A waypoint with the tag: ET_<spawntag> will exist unless day/night is in
|
|
act. If day/night is in act then ET_<spawntag>_D/N will exist.
|
|
The waypoints name field will be setup as follows:
|
|
<# to spawn>.<encounter%>/<encounter resref>.<next encounter>
|
|
NOTE: if the encounter % does not add up to 100 then the last encounter in
|
|
the list will take up the slack. If the encounter % exceeds 100 then the
|
|
creatures above 100% will never appear.
|
|
|
|
SPAWN LOCATIONS:
|
|
These are simply waypoints with the tag <spawntag># where # is 1+ based on
|
|
the number of spawn locations that were specified. */
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PROTOTYPES
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
string fnParse(string sIn,string sD="."); // Parse string
|
|
string fnRemoveParsed(string sOrig,string sParsed,string sD=".");
|
|
int fnCountSpawns(object oDef); // how many active spawns from this encounter
|
|
string fnSpawnType(string sET); // pass encounter table and provide a spawn
|
|
void fnDespawn(); // function to despawn a creature
|
|
|
|
////////////////////////////////////////////////////////// MAIN ////////////////
|
|
void main()
|
|
{
|
|
object oMe=OBJECT_SELF;
|
|
object oEntered=GetEnteringObject();
|
|
object oDef=GetNearestObjectByTag("des_waypoint",oEntered,1);
|
|
object oWP;
|
|
object oCr;
|
|
string sName;
|
|
string sParsed;
|
|
int nV;
|
|
int nL;
|
|
int nDur;
|
|
int nDN=FALSE;
|
|
int nSL;
|
|
string sSpawnTag;
|
|
string sSpawnScript;
|
|
object oET;
|
|
string sRes;
|
|
int nNumToSpawn;
|
|
if (oDef!=OBJECT_INVALID)
|
|
{ // definition waypoint is present
|
|
if (fnCountSpawns(oDef)==0)
|
|
{ // no current spawns from this encounter
|
|
sName=GetName(oDef);
|
|
sParsed=fnParse(sName);
|
|
sName=fnRemoveParsed(sName,sParsed);
|
|
nV=FALSE;
|
|
if (sParsed=="A") nV=TRUE;
|
|
else if (sParsed=="N"&&GetIsPC(oEntered)==FALSE) nV=TRUE;
|
|
else if (sParsed=="P"&&GetIsPC(oEntered)==TRUE) nV=TRUE;
|
|
if (nV==TRUE)
|
|
{ // do encounter
|
|
sParsed=fnParse(sName);
|
|
sName=fnRemoveParsed(sName,sParsed);
|
|
nDur=StringToInt(sParsed);
|
|
sParsed=fnParse(sName);
|
|
sName=fnRemoveParsed(sName,sParsed);
|
|
if (sParsed=="T") nDN=TRUE;
|
|
sParsed=fnParse(sName);
|
|
sName=fnRemoveParsed(sName,sParsed);
|
|
nSL=StringToInt(sParsed);
|
|
sParsed=fnParse(sName);
|
|
sName=fnRemoveParsed(sName,sParsed);
|
|
sSpawnTag=sParsed;
|
|
sSpawnScript=sName;
|
|
if (nSL>0)
|
|
{ // spawn locations set
|
|
if (nDN==FALSE)
|
|
oET=GetWaypointByTag("ET_"+sSpawnTag);
|
|
else
|
|
{ // day/night
|
|
if (GetIsDay()==TRUE||GetIsDawn()==TRUE)
|
|
oET=GetWaypointByTag("ET_"+sSpawnTag+"_D");
|
|
else { oET=GetWaypointByTag("ET_"+sSpawnTag+"_N"); }
|
|
} // day/night
|
|
if (oET!=OBJECT_INVALID)
|
|
{ // encounter table exists
|
|
sName=GetName(oET);
|
|
sParsed=fnParse(sName);
|
|
nNumToSpawn=StringToInt(sParsed);
|
|
if (nNumToSpawn>0)
|
|
{ // spawn is set for more than 0
|
|
nL=1;
|
|
sName=fnRemoveParsed(sName,sParsed);
|
|
nV=Random(nSL)+1;
|
|
oWP=GetWaypointByTag(sSpawnTag+IntToString(nV));
|
|
while(nL<=nNumToSpawn)
|
|
{ // spawn creatures
|
|
sRes=fnSpawnType(sName);
|
|
oCr=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oWP));
|
|
SetLocalObject(oDef,"oSpawned"+IntToString(nL),oCr);
|
|
if (nDur!=0)
|
|
{ // duration
|
|
DelayCommand(HoursToSeconds(nDur),AssignCommand(oCr,fnDespawn()));
|
|
} // duration
|
|
if (sSpawnScript!="NA") AssignCommand(oCr,ExecuteScript(sSpawnScript,oCr));
|
|
nL++;
|
|
} // spawn creatures
|
|
SetLocalInt(oDef,"nSpawnTop",nNumToSpawn);
|
|
} // spawn is set for more than 0
|
|
else
|
|
{ // error
|
|
SendMessageToPC(oEntered,"DES ENCOUNTER ERROR: The number to spawn for the encounter table you just tripped is 0!!");
|
|
} // error
|
|
} // encounter table exists
|
|
else
|
|
{ // error
|
|
SendMessageToPC(oEntered,"DES ENCOUNTER ERROR: An encounter table waypoint does not exist for the encounter trigger you just passed through.");
|
|
} // error
|
|
} // spawn locations set
|
|
else
|
|
{ // error
|
|
SendMessageToPC(oEntered,"DES ENCOUNTER ERROR: Number of spawn locations not properly defined on encounter in current area. See script des_oe_trigger for details.");
|
|
} // error
|
|
} // do encounter
|
|
} // no current spawns from this encounter
|
|
} // definition waypoint is present
|
|
else
|
|
{
|
|
SendMessageToPC(oEntered,"DES ENCOUNTER ERROR: waypoint des_waypoint missing in area '"+GetName(GetArea(oEntered))+"'!");
|
|
}
|
|
}
|
|
///////////////////////////////////////////////////////// MAIN /////////////////
|
|
|
|
void fnDespawn()
|
|
{ // despawn this creature
|
|
object oMe=OBJECT_SELF;
|
|
if (IsInConversation(oMe)==TRUE||GetIsInCombat(oMe)==TRUE)
|
|
DelayCommand(18.0,fnDespawn());
|
|
else { DestroyObject(oMe); }
|
|
} // fnDespawn()
|
|
|
|
string fnSpawnType(string sET)
|
|
{ // provide a resref from this encounter table
|
|
string sRet="";
|
|
string sTable=sET;
|
|
string sParse;
|
|
string sSub;
|
|
int nPT=0;
|
|
int nP=d100();
|
|
int nNum;
|
|
while (nPT<nP&&GetStringLength(sTable)>0&&nPT<101)
|
|
{ // find creature
|
|
sParse=fnParse(sTable);
|
|
sSub=fnParse(sParse,"/");
|
|
sTable=fnRemoveParsed(sTable,sParse);
|
|
sParse=fnRemoveParsed(sParse,sSub,"/");
|
|
nNum=StringToInt(sSub);
|
|
if (nNum<1) nNum=1;
|
|
nPT=nPT+nNum;
|
|
if (nPT>nP) sRet=sParse;
|
|
} // find creature
|
|
if (sRet=="") sRet=sParse;
|
|
return sRet;
|
|
} // fnSpawnType()
|
|
|
|
|
|
string fnParse(string sIn,string sD=".")
|
|
{ // parse based on the delimiter sD
|
|
string sRet="";
|
|
string sName=sIn;
|
|
while(GetStringLeft(sName,1)!=sD&&GetStringLength(sName)>0)
|
|
{ // build return string
|
|
sRet=sRet+GetStringLeft(sName,1);
|
|
sName=GetStringRight(sName,GetStringLength(sName)-1);
|
|
} // build return string
|
|
return sRet;
|
|
} // fnParse()
|
|
|
|
string fnRemoveParsed(string sOrig,string sParsed,string sD=".")
|
|
{ // removes sParsed from sOrig based on delimiter sD
|
|
string sRet="";
|
|
if (GetStringLength(sOrig)>GetStringLength(sParsed))
|
|
sRet=GetStringRight(sOrig,GetStringLength(sOrig)-GetStringLength(sParsed));
|
|
if (GetStringLeft(sRet,1)==sD)
|
|
sRet=GetStringRight(sRet,GetStringLength(sRet)-1);
|
|
return sRet;
|
|
} // fnRemoveParsed()
|
|
|
|
int fnCountSpawns(object oDef)
|
|
{ // how many active creatures spawned by this creature are still present
|
|
int nRet=0;
|
|
object oCr;
|
|
int nC=GetLocalInt(oDef,"nSpawnTop");
|
|
int nL=1;
|
|
if (nC>0)
|
|
{ // see if spawned creatures still exist
|
|
while(nL<=nC)
|
|
{ // test
|
|
oCr=GetLocalObject(oDef,"oSpawned"+IntToString(nL));
|
|
if (oCr!=OBJECT_INVALID&&GetIsDead(oCr)!=TRUE) nRet++;
|
|
nL++;
|
|
} // test
|
|
} // see if spawned creatures still exist
|
|
return nRet;
|
|
} // fnCountSpawns()
|