63 lines
2.5 KiB
Plaintext
63 lines
2.5 KiB
Plaintext
///////////////////////////////////////////////////////////////////////////
|
|
// Real Time Strategy - NWN - OnPerception modified event for units
|
|
//========================================================================
|
|
// By Deva Bryson Winblood. 03/10/2003
|
|
///////////////////////////////////////////////////////////////////////////
|
|
void fnDeconsolidate(object oMe);
|
|
|
|
|
|
void main()
|
|
{
|
|
object oMe=OBJECT_SELF;
|
|
int nS=GetLocalInt(oMe,"nMState");
|
|
int nParm=GetLocalInt(oMe,"nParm");
|
|
object oDeployed=GetLocalObject(oMe,"oDeployed");
|
|
int bDeployed=GetLocalInt(oMe,"bDeployed");
|
|
float fRange=40.0;
|
|
if (GetResRef(oMe)=="dwfupg2") fRange=80.0;
|
|
if (bDeployed==FALSE||oDeployed==OBJECT_INVALID)
|
|
{ // standard combat
|
|
if (GetIsEnemy(GetLastPerceived())==TRUE&&GetLocalInt(oMe,"bConsolidationLeader")==TRUE)
|
|
fnDeconsolidate(oMe);
|
|
if (nS!=12&&nS!=1&&nS!=13&&GetIsEnemy(GetLastPerceived())==TRUE)
|
|
{
|
|
if (nS!=17)
|
|
{ // not raid
|
|
ExecuteScript("nw_c2_default2",OBJECT_SELF);
|
|
} // not raid
|
|
else if (nParm==1&&GetLocalInt(oMe,"nSState")>1)
|
|
{ // attack raid and at base
|
|
ExecuteScript("nw_c2_default2",OBJECT_SELF);
|
|
} // attack raid and at base
|
|
}
|
|
} // standard combat
|
|
else
|
|
{ // target
|
|
oDeployed=GetLocalObject(oMe,"oTarget");
|
|
if (oDeployed==OBJECT_INVALID||GetArea(oDeployed)!=GetArea(oMe)||GetDistanceBetween(oMe,oDeployed)>fRange||(GetIsFriend(oDeployed)&&GetLocalInt(oMe,"nMState")!=1))
|
|
{ // check for enemies
|
|
oDeployed=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oMe,1,CREATURE_TYPE_PERCEPTION,PERCEPTION_SEEN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
|
|
if (oDeployed!=OBJECT_INVALID) SetLocalObject(oMe,"oTarget",oDeployed);
|
|
else { DeleteLocalObject(oMe,"oTarget"); }
|
|
} // check for enemies
|
|
} // target
|
|
}
|
|
|
|
void fnDeconsolidate(object oMe)
|
|
{ // deconsolidate
|
|
int nC=1;
|
|
object oF=GetLocalObject(oMe,"oConsolidated"+IntToString(nC));
|
|
while(oF!=OBJECT_INVALID)
|
|
{ // bring consolidated forces back out
|
|
SetCommandable(TRUE,oF);
|
|
SetAILevel(oF,AI_LEVEL_NORMAL);
|
|
DelayCommand(0.1,AssignCommand(oF,ClearAllActions()));
|
|
DelayCommand(0.2,AssignCommand(oF,JumpToObject(oMe)));
|
|
SetLocalInt(oF,"nSState",0);
|
|
DeleteLocalObject(oMe,"oConsolidated"+IntToString(nC));
|
|
nC++;
|
|
oF=GetLocalObject(oMe,"oConsolidated"+IntToString(nC));
|
|
} // bring consolidated forces back out
|
|
DeleteLocalInt(oMe,"bConsolidationLeader");
|
|
} // fnDeconsolidate()
|