HoS_PRC8/_mod/_module/nss/wazoo_ex_conmon.nss
Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

133 lines
5.9 KiB
Plaintext

// contingency monitor
void main()
{
object oPC=OBJECT_SELF;
int nSpell=GetLocalInt(oPC,"nContingencySpell");
int nN;
object oOb;
object oTarget;
int bDone=FALSE;
int nType=GetLocalInt(oPC,"nContingencyType");
if (nType==1)
{ // when I am wounded
if (GetCurrentHitPoints(oPC)<GetMaxHitPoints(oPC))
{ // wounded
bDone=TRUE;
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,ActionCastSpellAtObject(nSpell,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
} // wounded
} // when I am wounded
else if (nType==2)
{ // when a nearby friend is wounded
nN=1;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_FRIEND);
while(GetIsObjectValid(oOb)&&!GetIsObjectValid(oTarget)&&GetDistanceBetween(oOb,oPC)<30.0)
{ // find target
if (GetObjectSeen(oOb,oPC)||GetObjectSeen(oPC,oOb))
{ // target can be seen
if (GetCurrentHitPoints(oOb)<GetMaxHitPoints(oOb)) oTarget=oOb;
} // target can be seen
nN++;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_FRIEND);
} // find target
if (GetIsObjectValid(oTarget))
{ // target found
bDone=TRUE;
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,ActionCastSpellAtObject(nSpell,oTarget,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
} // target found
} // when a nearby friend is wounded
else if (nType==3)
{ // when an enemy is nearby
nN=1;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
while(GetIsObjectValid(oOb)&&!GetIsObjectValid(oTarget)&&GetDistanceBetween(oOb,oPC)<30.0)
{ // find target
if (GetObjectSeen(oOb,oPC)||GetObjectSeen(oPC,oOb))
{ // target can be seen
oTarget=oOb;
} // target can be seen
nN++;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
} // find target
if (GetIsObjectValid(oTarget))
{ // target found
bDone=TRUE;
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,ActionCastSpellAtObject(nSpell,oTarget,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
} // target found
} // when an enemy is nearby
else if (nType==4)
{ // when an invisible enemy is nearby
nN=1;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
while(GetIsObjectValid(oOb)&&!GetIsObjectValid(oTarget)&&GetDistanceBetween(oOb,oPC)<30.0)
{ // find target
if (GetHasSpellEffect(SPELL_INVISIBILITY,oOb)||GetHasSpellEffect(SPELL_IMPROVED_INVISIBILITY,oOb)||GetHasSpellEffect(SPELL_INVISIBILITY_SPHERE,oOb)) oTarget=oOb;
nN++;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
} // find target
if (GetIsObjectValid(oTarget))
{ // target found
bDone=TRUE;
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,ActionCastSpellAtObject(nSpell,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
} // target found
} // when an invisible enemy is nearby
else if (nType==5)
{ // when I am in combat
if (GetIsInCombat(oPC))
{ // combat
bDone=TRUE;
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,ActionCastSpellAtObject(nSpell,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
} // combat
} // when I am in combat
else if (nType==6)
{ // when a trap is nearby
nN=1;
oOb=GetNearestObject(OBJECT_TYPE_TRIGGER,oPC,nN);
while(GetIsObjectValid(oOb)&&!GetIsObjectValid(oTarget)&&GetDistanceBetween(oOb,oPC)<15.0)
{ // check for nearby traps
if (GetTrapBaseType(oOb)>0) oTarget=oOb;
nN++;
oOb=GetNearestObject(OBJECT_TYPE_TRIGGER,oPC,nN);
} // check for nearby traps
if (GetIsObjectValid(oTarget))
{ // target found
bDone=TRUE;
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,ActionCastSpellAtObject(nSpell,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
} // target found
} // when a trap is nearby
else if (nType==7)
{ // when a dangerous enemy is nearby
nN=1;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
while(GetIsObjectValid(oOb)&&!GetIsObjectValid(oTarget)&&GetDistanceBetween(oOb,oPC)<30.0)
{ // find target
if (GetObjectSeen(oOb,oPC)||GetObjectSeen(oPC,oOb))
{ // target can be seen
if ((GetLevelByPosition(1,oOb)+GetLevelByPosition(2,oOb)+GetLevelByPosition(3,oOb))>=(GetLevelByPosition(1,oPC)+GetLevelByPosition(2,oPC)+GetLevelByPosition(3,oPC)))
oTarget=oOb;
} // target can be seen
nN++;
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
} // find target
if (GetIsObjectValid(oTarget))
{ // target found
bDone=TRUE;
AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC,ActionCastSpellAtObject(nSpell,oTarget,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
} // target found
} // when a dangerous enemy is nearby
if (!bDone) DelayCommand(2.0,ExecuteScript("wazoo_ex_conmon",oPC));
else
{ // done
SendMessageToPC(oPC,"Your contingency stored spell has been used.");
DeleteLocalInt(oPC,"nContingencySpell");
DeleteLocalInt(oPC,"nContingencyType");
} // done
}