// 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)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 }