See this code, you might understand it better than from my description:
#include "x2_inc_switches"
#include "nw_i0_generic"
void Spell(int nSpell, object oTarget);
void main()
{
SetCreatureOverrideAIScriptFinished(OBJECT_SELF);
if (GetLocalInt(OBJECT_SELF, "AI_RUNNING") == 1)
return;
object oEnemy = GetNearestSeenEnemy();
if (GetIsObjectValid(oEnemy))
{
// this is where this line should be, not above where I've commented it out
SetLocalInt(OBJECT_SELF, "AI_RUNNING", 1);
talent t = GetCreatureTalentBest(TALENT_CATEGORY_BENEFICIAL_ENHANCEMENT_AREAEFFECT,60);
while(GetIsTalentValid(t))
{
ActionCastSpellAtObject(GetIdFromTalent(t),OBJECT_SELF,METAMAGIC_NONE,FALSE,60,PROJECTILE_PATH_TYPE_DEFAULT,TRUE);
t = GetCreatureTalentBest(TALENT_CATEGORY_BENEFICIAL_ENHANCEMENT_AREAEFFECT,60);
}
int nSpell = SPELL_EPIC_RUIN;
vector vObjectPosition = GetPosition(oEnemy);
vector vNewPosition = GetPosition(OBJECT_SELF);
float fNewFacing = VectorToAngle(vObjectPosition-vNewPosition);
SetFacing(fNewFacing);
ActionCastFakeSpellAtObject(nSpell,OBJECT_SELF);
ActionDoCommand(Spell(nSpell,OBJECT_SELF));
ActionDoCommand(SetLocalInt(OBJECT_SELF, "AI_RUNNING", 0));
}
}
#include "70_inc_spells"
#include "x0_i0_spells"
void Spell(int nSpell, object oTarget)
{
oTarget = GetLastAttacker();
if(!GetIsObjectValid(oTarget))oTarget = GetNearestSeenEnemy();
if(!GetIsObjectValid(oTarget))
return;
float fDist = GetDistanceBetween(OBJECT_SELF, oTarget);
float fDelay = fDist/(3.0 * log(fDist) + 2.0)-1.0;
if(spellsIsTarget(oTarget, SPELL_TARGET_SINGLETARGET, OBJECT_SELF))
{
//Fire cast spell at event for the specified target
SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_EPIC_RUIN));
//Roll damage
int nDam = d6(35);
//Set damage effect
if(MySavingThrow(SAVING_THROW_FORT, oTarget, 65, SAVING_THROW_TYPE_SPELL, OBJECT_SELF))
{
nDam /=3;
}
effect eDam = EffectDamage(nDam, DAMAGE_TYPE_POSITIVE, DAMAGE_POWER_PLUS_TWENTY);
ApplyEffectAtLocation (DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SCREEN_SHAKE), GetLocation(oTarget));
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(487), oTarget);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_COM_BLOOD_CRT_RED), oTarget);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_COM_CHUNK_BONE_MEDIUM), oTarget);
DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget));
}
}
This is my custom AI which cause creature to cast epic "epic ruin" on nearest seen enemy. The epic ruin is slightly improved here.
Also since its fake spell the casting cannot be interrupted (unless you script it in OnDamaged event) however it has some other issues:
- the code after cast spell triggers a bit late than for normal spell
- resistspell probably not work right (havent tested yet but its very possibly)
- spellcraft bonus into save vs spell might not work (also havent tested yet)
- some spell functions like casterlevel obviously wont work or return weird numbers
Maybe it would be possible to cast instant normal spell after finishing fake one but the first issue will remain (I havent tried this as I needed the spell to work differently anyway)
Modifié par ShaDoOoW, 24 octobre 2011 - 01:04 .