// hb - By Deva Bryson Winblood - heart beat script for wards object fnNearestEnemy(object oMaster,float fRange=5.0) { // PURPOSE: Return nearest enemy within fRange object oRet=OBJECT_INVALID; object oMe=OBJECT_SELF; object oCreature; int nN=1; oCreature=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oMe,nN); while(oRet==OBJECT_INVALID&&oCreature!=OBJECT_INVALID&&GetDistanceBetween(oMe,oCreature)<=fRange) { // check each creature if (GetIsEnemy(oCreature,oMaster)) oRet=oCreature; else { // next nN++; oCreature=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oMe,nN); } // next } // check each creature return oRet; } // fnNearestEnemy() void fnWard(object oMaster,float fRange) { object oMe=OBJECT_SELF; int nPower=GetLocalInt(oMe,"nPower"); object oTarget; effect eE; if (nPower>0) { // ward has power oTarget=fnNearestEnemy(oMaster,fRange); if (oTarget!=OBJECT_INVALID) { // target exists SetIsTemporaryEnemy(oTarget,oMe,TRUE); if (nPower<5) { // 1 point spells nPower=nPower-1; AssignCommand(oMe,ActionCastSpellAtObject(SPELL_ELECTRIC_JOLT,oTarget,METAMAGIC_ANY,TRUE,1,PROJECTILE_PATH_TYPE_DEFAULT,TRUE)); } // 1 point spells else if (nPower<21) { // 5 point spells nPower=nPower-5; AssignCommand(oMe,ActionCastSpellAtObject(SPELL_MAGIC_MISSILE,oTarget,METAMAGIC_ANY,TRUE,2,PROJECTILE_PATH_TYPE_DEFAULT,TRUE)); } // 5 point spells else if (nPower<31) { // 10 point spells nPower=nPower-10; AssignCommand(oMe,ActionCastSpellAtObject(SPELL_GEDLEES_ELECTRIC_LOOP,oTarget,METAMAGIC_ANY,TRUE,3,PROJECTILE_PATH_TYPE_DEFAULT,TRUE)); } // 10 point spells else if (nPower<41) { // 15 point spells nPower=nPower-15; AssignCommand(oMe,ActionCastSpellAtObject(SPELL_LIGHTNING_BOLT,oTarget,METAMAGIC_ANY,TRUE,5,PROJECTILE_PATH_TYPE_DEFAULT,TRUE)); } // 15 point spells else if (nPower<51) { // 20 point spells nPower=nPower-20; AssignCommand(oMe,ActionCastSpellAtObject(SPELL_FEAR,oTarget,METAMAGIC_ANY,TRUE,8,PROJECTILE_PATH_TYPE_DEFAULT,TRUE)); } // 20 point spells else if (nPower<61) { // 25 point spells nPower=nPower-25; AssignCommand(oMe,ActionCastSpellAtObject(SPELL_BALL_LIGHTNING,oTarget,METAMAGIC_ANY,TRUE,10,PROJECTILE_PATH_TYPE_DEFAULT,TRUE)); } // 25 point spells else { // 30 point spells nPower=nPower-30; AssignCommand(oMe,ActionCastSpellAtObject(SPELL_CHAIN_LIGHTNING,oTarget,METAMAGIC_ANY,TRUE,12,PROJECTILE_PATH_TYPE_DEFAULT,TRUE)); } // 30 point spells SetLocalInt(oMe,"nPower",nPower); } // target exists DelayCommand(4.0,fnWard(oMaster,fRange)); } // ward has power else { // despawn DestroyObject(oMe); } // despawn } // fnWardMinor() //////////////////////////////////////////////////////////////////////////////// void main() { object oMe=OBJECT_SELF; object oMaster=GetLocalObject(oMe,"oMaster"); string sTag; int nEffect; float fRange; effect eE; if (oMaster!=OBJECT_INVALID) { // master exists sTag=GetTag(oMe); sTag=GetStringRight(sTag,3); if (sTag=="d25") { // minor nEffect=VFX_DUR_PROTECTION_EVIL_MINOR; fRange=5.0; } // minor else if (sTag=="d50") { // medium nEffect=VFX_DUR_PROTECTION_EVIL_MAJOR; fRange=8.0; } // medium else if (sTag=="100") { // major nEffect=VFX_DUR_PROTECTION_ELEMENTS; fRange=11.0; } // major eE=EffectVisualEffect(nEffect); if (GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,oMe,1)!=OBJECT_INVALID) ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eE,oMe,6.1); // player's in area... if (GetLocalInt(oMe,"bActivated")==FALSE) { // activate fnWard(oMaster,fRange); } // activate } // master exists else { // despawn DestroyObject(oMe); } // despawn } ////////////////////////////////////////////////////////////////////////////////