SmartlyDressedGames / Legally-Distinct-Missile

Fork of Rocket for Unturned maintained by the game developers.
MIT License
79 stars 29 forks source link

OnPlayerDeath bug #38

Closed rube200 closed 3 years ago

rube200 commented 3 years ago

With the last changes made in rocketmod, when OnPlayerDeath happens it is no longer possible to get the experience of playing dead, this can affect other plugins that also use this event.

rube200 commented 3 years ago

Order: (Before update)

OnPlayerDeath
tellDeath
OnDeath
tellDead

(After update)

tellDeath
tellDead
OnPlayerDeath
OnDeath
SDGNelson commented 3 years ago

Yeah my bad - I did not realize OnPlayerDeath was being used that way. That event was only used to show the owner how they died in the base game. #37 OnPreDeath was added for this case. Does that work, or is something else needed?

RestoreMonarchy commented 3 years ago

When I use native PrePlayerDeath event and it works (at least to read player inventory before death) but rocket OnPlayerDeath ain't updated to use it yet.

SDGNelson commented 3 years ago

I suppose it could be hooked up, but the cause/limb/instigator for the Rocket event are not available during OnPreDeath. This has not been great for backwards compatibility, but do you think there are many outdated plugins relying on that?

rube200 commented 3 years ago

I have no clue how many plugins got outdated with this change but in my cause it broke.

private void OnPlayerDeath(UnturnedPlayer player, EDeathCause cause, ELimb _, CSteamID murderer)
{
  if (player == null || murderer == CSteamID.Nil || murderer == player.CSteamID)
    return;

  if (cause == EDeathCause.KILL)
      return;

  if (!PlayerTool.tryGetSteamPlayer(murderer.ToString(), out var murder))
      return;

  murder.player.skills.askAward(player.Player.skills.experience);
  player.Player.skills.ServerSetExperience(0);
}
SDGNelson commented 3 years ago

The code snipped you posted there should still work because all of those parameters are passed to onPlayerDied. What seems to be the issue?

rube200 commented 3 years ago

Problem is that rocketmod events are executed after tellDead so server deletes the experience before plugins access it

rube200 commented 3 years ago

Code order:

tellDead
onLifeUpdated //Inventory / experience is cleared at this point
static onPlayerLifeUpdated
OnPlayerDeath
OnDeath

Before:

OnPlayerDeath
tellDead
OnDeath
onLifeUpdated //Inventory / experience is cleared at this point
static onPlayerLifeUpdated
SDGNelson commented 3 years ago

Ah okay, I see what you mean now. I will add a separate event for that and update Rocket to use it.

SDGNelson commented 3 years ago

This should be addressed in tomorrow's update. https://github.com/SmartlyDressedGames/Legally-Distinct-Missile/commit/2291e9642d464944a962fecabfdcc0d1a3e39016