Exported

From GTA Network Wiki
Jump to: navigation, search

Exported
Server-Side Function

utilities-terminal.png Server-Side csharp.png C#

Provides access to exported functions and events.

Syntax

NAPI.Exported.resourceName.exportedFunction();
NAPI.Exported.resourceName.exportedEvent += new ExportedEvent(someMethod);

NOTE: This function returns data in dynamic type.

WARNING : Do not call an exported function inside another exported function.

Function example

In order to call an exported function, you must reference it as follows:

NAPI.Exported.resourceName.exportedFunction();

The function has to be listed in the meta.xml file from the resourceName resource. This is an example from the "scoreboard" resource:

<meta>
    ...
    <export class="ScoreboardScript" function="addScoreboardColumn" />
    ...
</meta>
public class ScoreboardScript : Script
{
    ...
    public void addScoreboardColumn(string name, string friendlyName, int width)
    {
    ...

Event example

<meta>
    ...
    <export class="ProfilesScript" event="onProfileLoaded" />
    ...
</meta>

If you're making exported events, you can trigger them like this:

class ProfilesScript : Script
{
  public event ExportedEvent onProfileLoaded;

  [Command("test")]
  public void TestCommand(Client sender)
  {
      // Some user wrote /test! Let's fire an event for it.
      onProfileLoaded(sender);
  }
}

If you're using exported events, you can get notified from them like this:

public MyScript()
{
    // Here, 'profiles' is a resource that is running on the server with an exported 'onProfileLoaded' event.
    NAPI.Exported.profiles.onProfileLoaded += new ExportedEvent(Profiles_onProfileLoaded);
}

private void Profiles_onProfileLoaded(object[] args)
{
    // The event also passes a Client object as its first argument.
    var client = (Client)args[0];
}


Changelog

Version Description
1.0 Release.

References