Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DamageHandlerExtensions #208

Open
wants to merge 2 commits into
base: 13.1
Choose a base branch
from

Conversation

SrLicht
Copy link
Contributor

@SrLicht SrLicht commented Jun 27, 2023

With this extensions you can get damagetype from a DamageHandlerBase.

Examples

using PluginAPI.Core.Extensions;

[PluginEvent(ServerEventType.PlayerDeath)]
void OnPlayerDied(Player player, Player attacker, DamageHandlerBase damageHandler)
{
     DamageType type = damageHandler.GetDamageType();
			
     Log.Info("DamageType is " + type);
}
using PluginAPI.Core.Extensions;

[PluginEvent]
void OnPlayerDied(PlayerDeathEvent ev)
{
	DamageType type = ev.DamageHandler.GetDamageType();
			
	Log.Info("DamageType is " + type);
}

I even added some more specific ones for DamageType.Scp096 and DamageType.Scp939.

Scp939 and Scp096 specific DamageTypes

[PluginEvent(ServerEventType.PlayerDeath)]
void OnPlayerDied(Player player, Player attacker, DamageHandlerBase damageHandler)
{
    DamageType type = damageHandler.GetDamageType();

    if (type == DamageType.Scp096)
    {
        var typeScp096 = (damageHandler as Scp096DamageHandler).GetScp096DamageType();

        if (typeScp096 is DamageType.Scp096Charge)
        {
            // your code here
        }
    }

    if (type is DamageType.Scp939)
    {
        var typeScp939 = (damageHandler as Scp939DamageHandler).GetScp939DamageType();

        if (typeScp939 is DamageType.Scp939Claw)
        {
            // Your Code
        }
    }
}

Resolves #187

* The fact that I had to create an extension to get data from private filds is sad.

* Some DamageType are not available because I have no way to get them without modifying the events.

* DamageHandlerExtensions will probably be removed when Northwood implements its system.
* and enabling unsafe code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant