Skip to content

Latest commit

 

History

History
73 lines (53 loc) · 2.7 KB

key-inputs-module.md

File metadata and controls

73 lines (53 loc) · 2.7 KB

Key Inputs Module

The key inputs module offers you the use of serverside key up and key down events which you can subscribe to and trigger your desired actions. You can add specific keys to listen for that not every keystroke gets sent to the server.

[!INCLUDE requirements]

Getting started

Start by installing the latest version from Nuget. You will need to install both server-side and client-side packages for the module to work properly.

platform nuget platform nuget

Initialization

A quick and simple example:

Note

These steps have to be done for both client-side and server-side!

var builder = Host.CreateDefaultBuilder( );

builder.ConfigureServices( (context, services) =>
{
    services.RegisterKeyInputModule( ); // <--- Register the key inputs module
} );
    
var host = builder.UseConsoleLifetime( ).Build( );
_ = host.Services.InitializeKeyInputModule( ); // <-- Initialize the key inputs module

await host.RunAsync();

On client-side you have to provide a list of keys you want to listen for on module initialization.

Tip

If you still have problems initializing the module you can check out the scaleforms module example in our boilerplate!

Using the module

You can use the module both on client-side and server-side.

Server-side

using AltV.Atlas.IoC.Attributes;
using AltV.Atlas.KeyInputs.Server.Events;
using AltV.Atlas.KeyInputs.Shared.Enums;
using AltV.Net.Elements.Entities;

[Injectable(InstantiateOnBoot = true)]
public class PlayerKeyDownEvent
{
    private readonly AtlasKeyInputEvents _atlasKeyInputEvents;

    public PlayerKeyDownEvent( AtlasKeyInputEvents atlasKeyInputEvents )
    {
        _atlasKeyInputEvents = atlasKeyInputEvents;
        _atlasKeyInputEvents.OnPlayerKeyDown += OnPlayerKeyDown;
    }

    private void OnPlayerKeyDown( IPlayer player, AtlasKey key )
    {
        if( key != AtlasKey.F4 )
            return;

        player.Kick();
    }
}

Examples

You can find examples for all our modules in our boilerplates client-side and server-side