Universal PvP hooks for PvE pluginsSolved

PR: 4.3.0-PVP hooks for PVE plugins.
Hello! I propose adding universal hooks OnPlayerEnterPVP and OnPlayerExitPVP for adding/removing players to/from a PvP mode/zone.
These universal hooks are specifically intended for PvE plugins. They allow PvP makers to notify PvE plugins about which players to mark/unmark with a PvP flag, especially by passing zone IDs, as players can be in multiple zones at once. 
This also allows unsubscribing from the OnEnterZone/OnLeaveZone(ZoneManager) hooks and avoids unnecessary calls to the API method IsDynamicPVPZone(DynamicPVP) every time the ZoneManager hooks are triggered, especially when there are many other zones aside from yours. 
Additionally, the OnPlayerExitPVP hook includes the option to pass the PvP delay, which helps avoid extra hooks for PvP delay, as a player might still be in other PvP zones when leaving one, causing your PvP delay hook to trigger frequently and making it less useful.

In your case, in version 4.3.0, you only need to add 3 lines
If you modify the conditions in OnLeaveZone, it's just 2 lines.
At line 1717:

Interface.CallHook("OnPlayerEnterPVP", player, zoneId);// Inform PvE plugins that they need to mark the player with a PvP flag and pass the unique PvP zone ID


At line 1754:

Interface.CallHook("OnPlayerExitPVP", player, zoneId);// Inform PvE plugins when a player leaves a PvP zone, passing the unique PvP zone ID, WITHOUT the PvP delay


At line 1757:

Interface.CallHook("OnPlayerExitPVP", player, zoneId, baseEvent.PvpDelayTime);// Inform PvE plugins when a player leaves a PvP zone, passing the unique PvP zone ID, WITH the PvP delay

OnPlayerEnterPVP:
Used to add a player to PVP mode/zone.
To call the OnPlayerEnterPVP hook, you need to pass 2 parameters:

  1. <BasePlayer>player - The player to add to PVP;
  2. <string>zoneID - A unique identifier for your PVP zone.
    This parameter is very important because a player can be in multiple PVP zones at the same time and passing the zoneID in this case allows for correct processing of the player's location within them.

Interface.CallHook("OnPlayerEnterPVP", player, "*Your unique zone identifier*");//Calling the OnPlayerEnterPVP hook to tell PVE plugins that the player needs to be added to the specified PVP zone.​


Merged post

OnPlayerExitPVP:
Used to remove a player from PVP mode/zone.
Calling this hook guarantees the player’s removal from the specified PVP zone, but does not guarantee the removal from PVP mode, as there may be other zones in addition to yours.
Also, when a player dies, they are automatically removed from all PVP zones.
To call the OnPlayerExitPVP hook, you need to pass 3 parameters, 1 of which is optional:

  1. <BasePlayer>player - The player to remove from PVP;
  2. <string>zoneID - A unique identifier for your PVP zone;
  3. <float>pvpDelay - Optional. When the player exits your PVP zone, you can also pass the PVP delay time.
    However, if the player still has other active PVP zones, your PVP delay will not take effect.

Interface.CallHook("OnPlayerExitPVP", player, "*Your unique zone identifier*", 10f);//Calling the OnPlayerExitPVP hook to tell PVE plugins that the player needs to be removed from the specified PVP zone, with the pvpDelay(10 seconds) specified if the player no longer has any active PVP zones.​

PR: 4.4.1-PVP hooks for PVE plugins.
Lines:

  • 1717 => 2221
  • 1754 => 2258
  • 1757 => 2261

Implemented in 4.5.0.

Hello. Thank you very much!

Locked automatically