Skip to content

AMX API

dev2alert edited this page Feb 4, 2022 · 1 revision

Home ▸ AMX API

Definition

AMX - Pawn Abstract Machine (for the Pawn language).

Functions

  1. amx.callNative(name: string, paramTypes: string, ...params: (number | string | number[])[]): {retval: number} & Array<number | string | number[]>

    Call native function.

    Arguments:
    • name - function name.
    • paramTypes - types of function parameters.
      Types of parameters:
      • i - integer.
      • f - float.
      • s - string.
      • a - array of integers.
      • v - array of floats.
      • I - reference to integer.
      • F - reference to float.
      • S - reference to string.
      • A - reference to array of integers.
      • V - reference to array of floats.
    • ...params - values of function parameters.

    Return value:
    Returned retval and reference values.


  2. amx.callNativeInFloat(name: string, paramTypes: string, ...params: (number | string | number[])[]): {retval: number} & Array<number | string | number[]>

    Similar to the callNative function, except that a floating-point number is returned.


  3. amx.onPublicCall(eventName: string, paramTypes: string, callback: (...params: (number | string | number[])[]) => number | void): {paramTypes: string, callback: Function}

    Register public function listener.

    Arguments:
    • eventName - function name.
    • paramTypes - types of function parameters.
      Types of parameters:
      • i - integer.
      • f - float.
      • s - string.
      • a - array of integers.
      • v - array of floats.
    • callback - function that is called when a public function is called.

    Return value:
    Return listener.


  4. amx.removePublic(eventName: string): boolean

    Removes listeners of public functions.

    Arguments:
    • eventName - function name.

    Return value:
    Returns true if listeners have been deleted, otherwise false.


Examples

Calling native function:

import * as amx from "@sa-mp/amx";

amx.callNative("SendRconCommand", "s", "cmdlist");

Creating public function listener:

import * as amx from "@sa-mp/amx";

amx.onPublicCall("OnGameModeInit", "", () => {
    console.log("Init!");
});

amx.onPublicCall("OnPlayerConnect", "i", (playerid) => {
    const [name] = amx.callNative("GetPlayerName", "iSi", playerid, 24, 24);
    amx.callNative("SendClientMessage", "iis", playerid, 0xe6b710AA, `Hello, ${name}[${playerid}]!`);
});

Clone this wiki locally