diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index cc85cdd589..3ad842ed30 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -595,7 +595,7 @@ bool SmartAI::AssistPlayerInCombatAgainst(Unit* who) return false; } -void SmartAI::JustAppeared() +void SmartAI::InitializeAI() { mDespawnTime = 0; mDespawnState = 0; @@ -930,9 +930,7 @@ void SmartAI::StopFollow(bool complete) void SmartAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker) { - if (invoker) - GetScript()->mLastInvoker = invoker->GetGUID(); - GetScript()->SetScript9(e, entry); + GetScript()->SetScript9(e, entry, invoker); } void SmartAI::OnGameEvent(bool start, uint16 eventId) @@ -994,9 +992,6 @@ void SmartGameObjectAI::InitializeAI() void SmartGameObjectAI::Reset() { - // call respawn event on reset - GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN); - GetScript()->OnReset(); } @@ -1054,9 +1049,7 @@ void SmartGameObjectAI::SetData(uint32 id, uint32 value, Unit* invoker) void SmartGameObjectAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker) { - if (invoker) - GetScript()->mLastInvoker = invoker->GetGUID(); - GetScript()->SetScript9(e, entry); + GetScript()->SetScript9(e, entry, invoker); } void SmartGameObjectAI::OnGameEvent(bool start, uint16 eventId) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index f8d5600bdd..6d318425c4 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -235,7 +235,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (!roll_chance_i(e.event.event_chance)) return; } - e.runOnce = true;//used for repeat check + e.runOnce = true; //used for repeat check if (unit) mLastInvoker = unit->GetGUID(); @@ -3533,9 +3533,12 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff) case SMART_EVENT_DISTANCE_CREATURE: case SMART_EVENT_DISTANCE_GAMEOBJECT: { - ProcessEvent(e); if (e.GetScriptType() == SMART_SCRIPT_TYPE_TIMED_ACTIONLIST) { + Unit* invoker9 = nullptr; + if (me && mTimedActionListInvoker) + invoker9 = ObjectAccessor::GetUnit(*me, mTimedActionListInvoker); + ProcessEvent(e, invoker9); e.enableTimed = false;//disable event if it is in an ActionList and was processed once for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i) { @@ -3547,6 +3550,8 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff) } } } + else + ProcessEvent(e); break; } } @@ -3840,7 +3845,7 @@ Unit* SmartScript::DoFindClosestFriendlyInRange(float range, bool playerOnly) return unit; } -void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry) +void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker) { //do NOT clear mTimedActionList if it's being iterated because it will invalidate the iterator and delete // any SmartScriptHolder contained like the "e" parameter passed to this function @@ -3854,6 +3859,7 @@ void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry) mTimedActionList = sSmartScriptMgr->GetScript(entry, SMART_SCRIPT_TYPE_TIMED_ACTIONLIST); if (mTimedActionList.empty()) return; + mTimedActionListInvoker = invoker ? invoker->GetGUID() : ObjectGuid::Empty; for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i) { i->enableTimed = i == mTimedActionList.begin();//enable processing only for the first action