Aurascripts + Target Selection

Hi,

I have started to try fixing some karazhan bosses - moving from timers to events, correct visuals, remove hacks, and of course, move spelleffects from the Boss script to Spellscripts.

I’m almost done with Prince Malchezaar, but there are 2 Problems that I couldn’t fix : Shadow Word: Pain and Enfeeble targetting. Both spells hit a fixed number of players (Enfeeble:5, SW:P: 1). I know how to limit that (SpellEntryMaxAffectedTargets = 5), but the problem is that the spells also exclude creature Targets and the Maintank.

With a SpellScript I could just use a piece of code like


 void FilterTargets(std::list<Unit*>& unitList)

 {

     unitList.remove_if(EnfeebleCheck(GetCaster());

     Trinity::RandomResizeList(unitList, 5);

}

and everything would work perfectly but the problem is that both spells are Auras and AuraScripts seem to lack a filter function. So, does anyone know how I can filter the Target list for these spells? I would be very grateful for your help /emoticons/default_smile.png

First at all, i’m no dev and this is just the thoughs of a guy who’s still learning with this project /emoticons/default_biggrin.png

afaik, i think you will need to make a custom class on your boss script, to match the exact way you want the spell will choose its target. Ex: if you want that some spell will not hit someone facing the caster…

[CODE]class OrientationCheck

{

public:

    explicit OrientationCheck(Unit* _caster) : caster(_caster) { }


    bool operator() (Unit* unit)

    {

        return !unit->isInFront(caster, 40.0f, 2.5f);

    }


private:

    Unit* caster;

};[/CODE]

And them use it on the filter target function

[CODE]class spell_eadric_radiance : public SpellScriptLoader

{

public:

    spell_eadric_radiance() : SpellScriptLoader("spell_eadric_radiance") { }

    class spell_eadric_radiance_SpellScript : public SpellScript

    {

        PrepareSpellScript(spell_eadric_radiance_SpellScript);

        void FilterTargets(std::list<Unit*>& unitList)

        {

            unitList.remove_if(OrientationCheck(GetCaster()));

        }


        void Register()

        {

            OnUnitTargetSelect += SpellUnitTargetFn(spell_eadric_radiance_SpellScript::FilterTargets, EFFECT_0, TARGET_UNIT_AREA_ENEMY_SRC);

            OnUnitTargetSelect += SpellUnitTargetFn(spell_eadric_radiance_SpellScript::FilterTargets, EFFECT_1, TARGET_UNIT_AREA_ENEMY_SRC);

        }

    };


    SpellScript *GetSpellScript() const

    {

        return new spell_eadric_radiance_SpellScript();

    }

};[/CODE]

Ofc you will have to scroll down all the functions on the unit class to find the one matching your require /emoticons/default_tongue.png

Hope it helps.

PS: Srry for bad english.

Thanks for your answer, but my problem is not the remove_if part, but the fact that Aurascripts seem to have no hook like OnUnitTargetSelect . For Spellscripts your solution is correct.

Use spellscript then. You want to filter targets that the spell effect hits. It does not matter whether it applies aura or does something else :wink:

Oh thanks I didn’t know that /emoticons/default_wink.png

For Shadow Word Pain this works perfectly, because it has no scripteffect, and for enfeeble it should work as well, If I use a timed BasicEvent to restore the Player’s life. I’m going to try it out soon.

Thanks to both of you for answering, I think this thread can be closed now /emoticons/default_smile.png

The target selection only happens when the spell is cast, this means you don’t need a target selector for an AuraScript, a SpellScript will be sufficient. If you really need an AuraScript, there is no problem in having a class with an AuraScript and a SpellScript, just be sure to have

AuraScript* GetAuraScript() const { return new spell_ftw_AuraScript(); } SpellScript* GetSpellScript() const { return new spell_ftw_SpellScript(); }

I don’t know if i’m clear enough. If not, take a look at Putricide’s ScriptSpells.

[/CODE]