Trinitycore: Core: Respawn position after movements

Created on 10 Jul 2016  路  25Comments  路  Source: TrinityCore/TrinityCore

For many npcs, if they despawn after a waypoint or a follow action they will respawn where the despawn happen instead of the home position.

Steps to reproduce the problem:

  1. Execute this sql: https://github.com/TrinityCore/TrinityCore/issues/16915#issuecomment-208766974
  2. .go c id 8023
  3. .quest add 2994 and .add 9472
  4. Open the cage and wait until the end of the event
  5. wait until the npc respawn 2min
  6. go -119.83095, -3499.7751, 119.578827
  7. The npc will be there where it despawns instead of the home position.

This issue happen for many other npcs.

EDIT: This issue happen if the npc despawn while z_position > z_ground

Branch(es): 3.3.5 / 6.x

TC hash/commit: rev. 8edc1caf3263

Branch-3.3.5a Branch-master Comp-Core Sub-ScriptingEngine Sub-Waypoints

Most helpful comment

reproduce, debug, understand the cause, think of a fix, implement the fix. any tc community member can do it,

All 25 comments

Related to [Core/SAI] SMART_ACTION_SET_HOME_POS #11593 ?

this sounds like a change added by a commit in last weeks that changed the behavior

First time I noticed this was the 17th April.

Was there a PR that changed waypoint functionality setting Home at every waypoint to avoid npc going back to start after evading ?

Edit: https://github.com/TrinityCore/TrinityCore/pull/11609 , is HomePosition the same as Respawn position too ?

Yes this does not seem to effect every creature with wp but confirming for Brunhilldar Prisoners and all 3 OOX homing robots.

Know the above example is sai but all of the npcs I have encountered this problem with so the majority are cpp scripted.

Yet dont know if grid has something to do with this as for example the brunhildar prisoners if when doing cold hearted when you drop the prisoners off and wait for them to despawn then they respawn at home position if you fly off before they have despawned then they respawn under quest giver.

I reverted https://github.com/TrinityCore/TrinityCore/pull/11609 but the issue is not fixed.

Not related, see https://github.com/TrinityCore/TrinityCore/blob/6.x/src/server/game/Entities/Creature/Creature.cpp#L2372 - it should always get db spawn coords for respawn, no exceptions

It's not related to waypoints only, as npc 8023 despawn after a follow action.

Do you have any way to reproduce it shorter than watching a 2 minute event?

@Shauren just open the cage, take a beer than .go -119.83095, -3499.7751, 119.578827
The other quest requires escorting npcs.

More info:

  • It's not needed to wait for a respawn, using .respawn near where Sharpbeak despawns will be enough.
  • Killing and re-respawning Sharpbeak again will cause it to return to the original spawn point as normal.
  • It's not a client desync issue, using .gps returns the current position.

any news on this? ths crap will also break this script https://github.com/TrinityCore/TrinityCore/issues/18739 feelsbadman

BIG HACK - makes you cry

diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
index 70c44f6..fbe7f0e 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp
@@ -174,6 +174,8 @@ void npc_escortAI::JustRespawned()
     if (me->getFaction() != me->GetCreatureTemplate()->faction)
         me->RestoreFaction();

+    me->NearTeleportTo(me->GetHomePosition().GetPositionX(), me->GetHomePosition().GetPositionY(), me->GetHomePosition().GetPositionZ(), me->GetHomePosition().GetOrientation(), false);
+
     Reset();
 }

diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp
index 40c4049..4116b19 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp
@@ -173,6 +173,8 @@ void FollowerAI::JustRespawned()
     if (me->getFaction() != me->GetCreatureTemplate()->faction)
         me->setFaction(me->GetCreatureTemplate()->faction);

+    me->NearTeleportTo(me->GetHomePosition().GetPositionX(), me->GetHomePosition().GetPositionY(), me->GetHomePosition().GetPositionZ(), me->GetHomePosition().GetOrientation(), false);
+
     Reset();
 }

diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index ca89a59..bbf6c67 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -510,6 +510,7 @@ void SmartAI::JustRespawned()
     mDespawnState = 0;
     mEscortState = SMART_ESCORT_NONE;
     me->SetVisible(true);
+    me->NearTeleportTo(me->GetHomePosition().GetPositionX(), me->GetHomePosition().GetPositionY(), me->GetHomePosition().GetPositionZ(), me->GetHomePosition().GetOrientation(), false);
     if (me->getFaction() != me->GetCreatureTemplate()->faction)
         me->RestoreFaction();
     mJustReset = true;

This issue happen if the npc despawn while z_position > z_ground

@Rushor did you find which line is causing the issue (before working on a fix) ?

@jackpoz sadly no, i only knew that: .die > .respawn > .die > .respawn causes the creature to teleport to it's homeposition again. That's the reason why i added it directly in the respawncall.

But Killyanas note will help to find the reason for sure

/push - pls by the lord of the Trinitycore god, fix this :(

reproduce, debug, understand the cause, think of a fix, implement the fix. any tc community member can do it,

Creature::RemoveCorpse calls Map::CreatureRelocation https://github.com/TrinityCore/TrinityCore/blob/master/src/server/game/Maps/Map.cpp#L993 but when creature respawn point is in different cell or grid relocation is postponed:

       // delay creature move for grid/cell to grid/cell moves
       if (old_cell.DiffCell(new_cell) || old_cell.DiffGrid(new_cell))
            AddCreatureToMoveList(creature, x, y, z, ang);

If creature is respawned before MoveAllCreaturesInMoveList() - we have bug. Can we safely ask map to process relocation in place (e.g. with another parameter) or it would lead to bugs?

If creature is respawned before MoveAllCreaturesInMoveList()

is this the case of this issue ? could you please share the callstacks with the respawn being called right after Creature::RemoveCorpse() without any MoveAllCreaturesInMoveList() in between ? just to confirm it's the cause of the issue.
if you relocate the creature while updating it then you are going to update the creature twice and/or invalidate iterators.

@BAndysc could you give info on that post by @jackpoz ? :)

MoveAllCreaturesInMoveList happens after each map update, the "timeframe" would be very rough and the creature would get relocated anyway (no matter the dead/alive) state. Ill take a look. If bug is repeatable anyone should be able to fix.

edit: just as I thought, a spline had to be launched and overwrite relocation to respawn point

Thank you @xinef1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

minkokomaung picture minkokomaung  路  69Comments

click picture click  路  51Comments

Amit86 picture Amit86  路  58Comments

ZenoX92 picture ZenoX92  路  53Comments

n4ndo picture n4ndo  路  51Comments