void CastSpellOnRandomTarget(uint32 i, float mindist2cast, float maxdist2cast, int minhp2cast, int maxhp2cast) { if (!maxdist2cast) maxdist2cast = 100.0f; if (!maxhp2cast) maxhp2cast = 100; if(_unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget()) { std::vector<UnitPointer> TargetTable; /* From M4ksiu - Big THX to Capt who helped me with std stuff to make it simple and fully working <3 */ /* If anyone wants to use this function, then leave this note! */ for(unordered_set<ObjectPointer>::iterator itr = _unit->GetInRangeSetBegin(); itr != _unit->GetInRangeSetEnd(); ++itr) { if (((spells[i].targettype == TARGET_RANDOM_FRIEND && isFriendly(_unit, (*itr))) || (spells[i].targettype != TARGET_RANDOM_FRIEND && isHostile(_unit, (*itr)) && (*itr) != _unit)) && ((*itr)->GetTypeId()== TYPEID_UNIT || (*itr)->GetTypeId() == TYPEID_PLAYER) && (*itr)->GetInstanceID() == _unit->GetInstanceID()) // isAttackable(_unit, (*itr)) && { UnitPointer RandomTarget = NULLUNIT; RandomTarget = TO_UNIT(*itr); if (RandomTarget->isAlive() && _unit->GetDistance2dSq(RandomTarget) >= mindist2cast*mindist2cast && _unit->GetDistance2dSq(RandomTarget) <= maxdist2cast*maxdist2cast && ((RandomTarget->GetHealthPct() >= minhp2cast && RandomTarget->GetHealthPct() <= maxhp2cast && spells[i].targettype == TARGET_RANDOM_FRIEND) || (_unit->GetAIInterface()->getThreatByPtr(RandomTarget) > 0 && isHostile(_unit, RandomTarget)))) { TargetTable.push_back(RandomTarget); } } } if (_unit->GetHealthPct() >= minhp2cast && _unit->GetHealthPct() <= maxhp2cast && spells[i].targettype == TARGET_RANDOM_FRIEND) TargetTable.push_back(_unit); if (!TargetTable.size()) return; size_t RandTarget = rand()%TargetTable.size(); UnitPointer RTarget = TargetTable[RandTarget]; if (!RTarget) return; switch (spells[i].targettype) { case TARGET_RANDOM_FRIEND: case TARGET_RANDOM_SINGLE: _unit->CastSpell(RTarget, spells[i].info, spells[i].instant); break; case TARGET_RANDOM_DESTINATION: _unit->CastSpellAoF(RTarget->GetPositionX(), RTarget->GetPositionY(), RTarget->GetPositionZ(), spells[i].info, spells[i].instant); break; } TargetTable.clear(); } }
void OnCombatStart(UnitPointer mTarget) { _unit->GetAIInterface()->m_canMove = false; _unit->GetAIInterface()->disable_melee = true; _unit->SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); UnitPointer antusul = NULLUNIT; antusul = _unit->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(1815.030029f, 686.817017f, 14.519000f, 8127); if(antusul) { if(antusul->isAlive()) { antusul->GetAIInterface()->AttackReaction(mTarget, 0, 0); antusul->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Lunch has arrived, my beutiful childern. Tear them to pieces!"); } } }
void OnEmote(PlayerPointer pPlayer, uint32 Emote, UnitPointer pUnit) { pUnit = pPlayer->GetMapMgr()->GetUnit(pPlayer->GetSelection()); if (!pUnit || !pUnit->isAlive() || pUnit->GetAIInterface()->GetNextTarget()) return; // Switch For Emote Name (You do EmoteName to Script Name link). switch(Emote) { case EMOTE_ONESHOT_SALUTE: // <- Its EMOTE name. GuardsOnSalute(pPlayer, pUnit); // <- Its Link. break; case EMOTE_ONESHOT_KISS: GaurdsOnKiss(pPlayer, pUnit); break; case EMOTE_ONESHOT_WAVE: GuardsOnWave(pPlayer, pUnit); break; } }