AltV.Community.Events 0.0.2

dotnet add package AltV.Community.Events --version 0.0.2                
NuGet\Install-Package AltV.Community.Events -Version 0.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AltV.Community.Events" Version="0.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AltV.Community.Events --version 0.0.2                
#r "nuget: AltV.Community.Events, 0.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AltV.Community.Events as a Cake Addin
#addin nuget:?package=AltV.Community.Events&version=0.0.2

// Install AltV.Community.Events as a Cake Tool
#tool nuget:?package=AltV.Community.Events&version=0.0.2                

AltV.Community.Events

NuGet badge

Quickstart

This package helps you quickly create event as a class with provided base methods for managing event handlers.

Installation
dotnet add package AltV.Community.Events
Usage with Dependency Injection
  1. Create your event
using AltV.Net;
using AltV.Community.Events;

// .net 8 primary constructor syntax
public sealed class PlayerLoggedInEvent(IEventInvoker invoker) : Event<IPlayer>(invoker) { }

// with more parameters
public sealed class PlayerLoggedInEvent(IEventInvoker invoker) : Event<IPlayer, int, string, float, double>(invoker) { }
  1. Register necessary types to the service collection
// your resource startup

serviceCollection.AddSingleton<IEventInvoker, EventInvoker>(); // register the default event invoker
serviceCollection.AddSingleton<PlayerLoggedInEvent>(); // register the event
  1. Use the event by adding/removing handlers or invoking handlers.
// somewhere in your Script

public sealed class SpawnPlayerScript(PlayerLoggedInEvent playerLoggedInEvent)
{
    playerLoggedInEvent.AddHandler((player) =>
    {
        Console.WriteLine($"{player.Name} has logged in successfully!");
        SpawnPlayer(player);
    });
    playerLoggedInEvent.AddHandler((player) =>
    {
        Console.WriteLine("I'm another event handler");
    });
}

public sealed class PlayerConnectScript(PlayerLoggedInEvent playerLoggedInEvent)
{
    Alt.OnPlayerConnect += (player) =>
    {
        var success = AskPlayerToLogin(player);
        if (success)
        {
            playerLoggedInEvent.Invoke(player); // or InvokeAsync, InvokeAsyncSerial
        }
    };
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2 113 11/11/2024
0.0.1 101 11/9/2024