Canattack Check For Spells. (Antifactionhack)

Hello, I’m quite new to TrinityCore and im trying to make some kind of check which should block players from casting harmful spell onto thier own faction, or friendly players in general.

I’m familair with OregonCore, which is an old 2.4.3 Fork of Trinity and i’ve used this for a long long time without any problems in “CanCast()”.

[CODE] if(!IsPositiveSpell(m_spellInfo->Id) && !m_IsTriggeredSpell

		&& m_caster->GetTypeId() == TYPEID_PLAYER && m_caster != target && !m_caster->canAttack(target))

	{

		// anti faction hack

		return SPELL_FAILED_BAD_TARGETS;

	}[/CODE]

I tried this on trinity with an error message instead of a return to start with, and I got spammed by loads of them(all random spells), so i’m missing something. Any idea’s?

ps. This IS blizzlike, you cant “factionhack” on official realms

There is already a check for this in the core and its handled by the SpellSystem

Then it obviously doesn’t work…Herp derp.

It does work, you cant just cast a harmful spell on friendly targets unless you are in a duel

Is there any way to make a spell casted by a friendly npc to have harmful effects on player /so to be taken on player as, if enemy unit casted it/?

Could you point me where I can find it?

There’s a IsVAlidAttackTarget check in InitSpellExplicitTargets function as far as i remember