Skip to content

Latest commit

 

History

History
65 lines (51 loc) · 1.61 KB

File metadata and controls

65 lines (51 loc) · 1.61 KB

Create Script

Make sure you have created a resource before.

Classes that extend IScript are getting auto initiaized.

MyScript.cs

using System;

namespace My.Package
{
    public class MyScript : IScript
    {
    }
}

Scripts can register event handlers via method attributes.

For adding a player connect handler. The method name doesn't matter for script events.

[ScriptEvent(ScriptEventType.PlayerConnect)]
public void PlayerConnect(IPlayer player, string reason)
{
  player.SetDateTime(DateTime.Now);
  player.Model = (uint) PedModel.FreemodeMale01;
}

For adding a custom event handler. The method name is used as a event name when its not defined in the attribute.

// Here the event name is 'MyEventName' and the event handler receives server events
[ServerEvent("MyEventName")]
public static void MyEventName2(string message)
{
  Console.WriteLine(message);
}

// Here the event name is 'MyCustomEvent' and the event handler receives server events
[ServerEvent]
public static void MyCustomEvent(string message)
{
  Console.WriteLine(message);
}

// Here the event name is 'MyClientEventName' and the event handler receives client events
[ClientEvent("MyClientEventName")]
public static void MyClientEventName2(string message)
{
  Console.WriteLine(message);
}

// Here the event name is 'MyClientCustomEvent' and the event handler receives client events
[ClientEvent]
public static void MyClientCustomEvent(string message)
{
  Console.WriteLine(message);
}

The ScriptEvent method signatures are the same as the signatures used when registering the events via Alt.OnPlayerConnect ect.