diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index a021fa9cb2..2b676bfa63 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -631,6 +631,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon /* Success ! */ if ((flags & DC_EXEC) != 0 && new_head != old_head) { *chain = new_head; + AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index)); } /* Transfer cargo of old vehicles and sell them */ @@ -644,10 +645,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon if ((flags & DC_EXEC) != 0) { old_vehs[i] = nullptr; - if (i == 0) { - AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index)); - old_head = nullptr; - } + if (i == 0) old_head = nullptr; } /* Sell the vehicle. * Note: This might temporarily construct new trains, so use DC_AUTOREPLACE to prevent