diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 3c88fcb51..05f6c14cf 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -994,18 +994,23 @@ namespace Game.Entities SetControlled(false, UnitState.Root); // SMSG_MOVE_FORCE_UNROOT, ~MOVEMENTFLAG_ROOT - Position pos; - if (exitPosition == null) // Exit position not specified - pos = vehicle.GetBase().GetPosition(); // This should use passenger's current position, leaving it as it is now - // because we calculate positions incorrect (sometimes under map) - else - pos = exitPosition; - AddUnitState(UnitState.Move); if (player != null) player.SetFallInformation(0, GetPositionZ()); + Position pos; + // If we ask for a specific exit position, use that one. Otherwise allow scripts to modify it + if (exitPosition != null) + pos = exitPosition; + else + { + // Set exit position to vehicle position and use the current orientation + pos = vehicle.GetBase().GetPosition(); + pos.SetOrientation(GetOrientation()); + Global.ScriptMgr.ModifyVehiclePassengerExitPos(this, vehicle, pos); + } + float height = pos.GetPositionZ() + vehicle.GetBase().GetCollisionHeight(); MoveSplineInit init = new(this); @@ -1015,7 +1020,7 @@ namespace Game.Entities init.SetFall(); init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), height, false); - init.SetFacing(GetOrientation()); + init.SetFacing(pos.GetOrientation()); init.SetTransportExit(); GetMotionMaster().LaunchMoveSpline(init, EventId.VehicleExit, MovementGeneratorPriority.Highest); diff --git a/Source/Game/Scripting/CoreScripts.cs b/Source/Game/Scripting/CoreScripts.cs index f3b132ab9..a9123aac9 100644 --- a/Source/Game/Scripting/CoreScripts.cs +++ b/Source/Game/Scripting/CoreScripts.cs @@ -303,6 +303,9 @@ namespace Game.Scripting // Called when Spell Damage is being Dealt public virtual void ModifySpellDamageTaken(Unit target, Unit attacker, ref int damage, SpellInfo spellInfo) { } + + // Called when an unit exits a vehicle + public virtual void ModifyVehiclePassengerExitPos(Unit passenger, Vehicle vehicle, Position pos) { } } public class GenericCreatureScript : CreatureScript where AI : CreatureAI diff --git a/Source/Game/Scripting/ScriptManager.cs b/Source/Game/Scripting/ScriptManager.cs index 866680e15..065a7be5f 100644 --- a/Source/Game/Scripting/ScriptManager.cs +++ b/Source/Game/Scripting/ScriptManager.cs @@ -1100,6 +1100,10 @@ namespace Game.Scripting ForEach(p => p.ModifySpellDamageTaken(target, attacker, ref dmg, spellInfo)); damage = dmg; } + public void ModifyVehiclePassengerExitPos(Unit passenger, Vehicle vehicle, Position pos) + { + ForEach(p => p.ModifyVehiclePassengerExitPos(passenger, vehicle, pos)); + } // AreaTriggerEntityScript public AreaTriggerAI GetAreaTriggerAI(AreaTrigger areaTrigger)