Skip to content

Commit 8e9a310

Browse files
authored
call state change event after death event, to prevent unwanted cleanups (#1035)
* call state change event after death event, to prevent unwanted cleanups * fix arm ci * remove a problematic fix ported from fixes.inc
1 parent 0513223 commit 8e9a310

3 files changed

Lines changed: 15 additions & 30 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ jobs:
233233
234234
build-arm-gnu:
235235
name: ARM build (GNU)
236-
runs-on: ubuntu-latest
236+
runs-on: ubuntu-22.04
237237

238238
strategy:
239239
matrix:

Server/Source/player_impl.hpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -785,34 +785,6 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
785785
{
786786
PacketHelper::broadcastToStreamed(clearPlayerTasksRPC, *this, false /* skipFrom */);
787787
}
788-
789-
IPlayerVehicleData* data = queryExtension<IPlayerVehicleData>(*this);
790-
if (!data || !data->getVehicle())
791-
{
792-
// TODO: This must be fixed on client side
793-
// *
794-
// * <problem>
795-
// * ClearAnimations doesn't do anything when the animation ends if we
796-
// * pass 1 for the freeze parameter in ApplyAnimation.
797-
// * </problem>
798-
// * <solution>
799-
// * Apply an idle animation for stop and then use ClearAnimation.
800-
// * </solution>
801-
// * <see>FIXES_ClearAnimations</see>
802-
// * <author href="https://github.com/simonepri/" >simonepri</author>
803-
// *
804-
AnimationData animationData(4.0f, false, false, false, false, 1, "", "");
805-
806-
animationData.lib = "PED";
807-
animationData.name = "IDLE_STANCE";
808-
applyAnimationImpl(animationData, syncType);
809-
animationData.lib = "PED";
810-
animationData.name = "IDLE_CHAT";
811-
applyAnimationImpl(animationData, syncType);
812-
animationData.lib = "PED";
813-
animationData.name = "WALK_PLAYER";
814-
applyAnimationImpl(animationData, syncType);
815-
}
816788
}
817789

818790
void clearAnimations(PlayerAnimationSyncType syncType) override

Server/Source/player_pool.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,12 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
375375
}
376376

377377
Player& player = static_cast<Player&>(peer);
378-
player.setState(PlayerState_Wasted);
378+
379+
// Keep a record of current state before changing it to wasted, and do not dispatch state change event
380+
// We're doing this so state change event listeners don't reset player data (like removing the link between player and the vehicle they're in when dead)
381+
// Then dispatch the event manually later, after onPlayerDeath event dispatch.
382+
PlayerState oldState = player.getState();
383+
player.setState(PlayerState_Wasted, /* dispatchEvents = */ false);
379384

380385
IPlayer* killer = self.storage.get(onPlayerDeathRPC.KillerID);
381386
uint8_t reason = onPlayerDeathRPC.Reason;
@@ -407,6 +412,14 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
407412
killer,
408413
reason);
409414

415+
// Dispatch state change event manually after onPlayerDeath, so reset player data after listeners already handled death event.
416+
// Use stored state from above as old state and newly stored state in player data as new one.
417+
self.playerChangeDispatcher.dispatch(
418+
&PlayerChangeEventHandler::onPlayerStateChange,
419+
peer,
420+
peer.getState(),
421+
oldState);
422+
410423
NetCode::RPC::PlayerDeath playerDeathRPC;
411424
playerDeathRPC.PlayerID = player.poolID;
412425
PacketHelper::broadcast(playerDeathRPC, self, &peer);

0 commit comments

Comments
 (0)