GM-X Core

reapi core gmx GM-X Core 0.1.86-alpha

Нет прав для скачивания
Установка
  1. Скопируйте файлы согласно директориям
  2. Откройте gmx.sma и скомпилируйте плагин (инструкция).
  3. Скопируйте скомпилированный gmx.amxx в директорию "addons/amxmodx/plugins".
  4. Пропишите gmx.amxx в /amxmodx/configs/plugins-gmx.ini
Настройки
/amxmodx/configs/gmx.json

token
- токен сервера, который нужно получить в веб части
url - URL веб части, без / в конце
loglevel - уровень логирования (0 - критические ошибки, 1 - ошибки, 2 - инфо, 3 - дебаг)

Код:
{
    "token": "",
    "url": "http://127.0.0.1",
    "loglevel": 3
}
API
Код:
#if defined _gmx_included
    #endinput
#endif

#define _gmx_included

#include <gmx_consts>
#include <gmx_version>

/**
* Called when the config was loaded.
*
* @noreturn
*/
forward GMX_CfgLoaded();

/**
* Called when GM-X is initiated.
*
* @noreturn
*/
forward GMX_Init();

/**
* Called when a player is loading.
*
* @return              PLUGIN_CONTINUE to let the client load
*                      PLUGIN_HANDLED to prevent the client to load
*/
forward GMX_PlayerLoading(const id);

/**
* Called when a player was loaded.
*
* @param id            Client index
* @param data          --- Description ---
*
* @noreturn
*/
forward GMX_PlayerLoaded(const id, GripJSONValue:data);

/**
* Called when a player is disconnecting.
*
* @return              PLUGIN_CONTINUE to let saving information about player's disconnection
*                      PLUGIN_HANDLED to prevent saving information about player's disconnection
*/
forward GMX_PlayerDisconnecting(const id);

/**
* Makes request to API.
*
* @param endpoint      Part of path to api resource
* @param data          Data provided to API
* @param callback      Callback name which will be called
* @param param         Parameter which will be provided in callback
*
* @return              ID of request, -1 if error occurred
* @error               If an invalid number of arguments is set, or API is not enabled, or an
*                      invalid callback function is provided, an error will be thrown.
*/
native GMX_MakeRequest(const endpoint[], GripJSONValue:data, const callback[] = "", const param = 0);

/**
* Makes request to API.
*
* @param command       Command name
* @param callback      Callback name which will be called
*
* @return              ID of command, -1 if error occurred
* @error               If an invalid number of arguments is set, or an
*                      invalid callback function is provided, an error will be thrown.
*/
native GMX_RegisterCommand(const command[], const callback[]);

/**
* Makes request to API.
*
* @param level         Logging level
* @param fmt           Formatting rules
* @param ...           Variable number of formatting parameters
*
* @return              1 on success, 0 otherwise
*/
native GMX_Log(const GmxLogLevel:level, const fmt[], any:...);

/**
* Returns server ID
*
* @return              server ID
*/
native GMX_GetServerID();

/**
* Returns time on api part in unix timestamp
*
* @return              unix timestamp
*/
native GMX_GetServerTime();

/**
* Returns diff from server time and api part time in seconds
*
* @return              seconds
*/
native GMX_GetServerTimeDiff();

/**
* Checks if player is loaded.
*
* @param id            Client index
*
* @return              true if loaded, false otherwise
* @error               If an invalid number of arguments is set, an error will be thrown.
*/
native bool:GMX_PlayerIsLoaded(const id);

/**
* Returns player's ID.
*
* @param id            Client index
*
* @return              Player's ID if it was found
* @error               If the index is not within the range of 1 to MaxClients,
*                      or an invalid number of arguments is set, or player is not
*                      loaded, an error will be thrown.
*/
native GMX_PlayerGetPlayerId(const id);

/**
* Returns player's user ID.
*
* @param id            Client index
*
* @return              Player's user ID if it was found
* @error               If the index is not within the range of 1 to MaxClients,
*                      or an invalid number of arguments is set, or player is not
*                      loaded, an error will be thrown.
*/
native GMX_PlayerGetUserId(const id);

/**
* Returns player's session ID.
*
* @param id            Client index
*
* @return              Player's session ID if it was found
* @error               If the index is not within the range of 1 to MaxClients,
*                      or an invalid number of arguments is set, or player is not
*                      loaded, an error will be thrown.
*/
native GMX_PlayerGetSessionId(const id);

/**
* Returns player's immunity level.
*
* @param id            Client index
*
* @return              Player's immunity level if it was found
* @error               If the index is not within the range of 1 to MaxClients,
*                      or an invalid number of arguments is set, or player is not
*                      loaded, an error will be thrown.
*/
native GMX_PlayerGetImmunity(const id);

/*
* This is callback from GM-X Core that gives major/minor versions for verifying compatibility for GM-X versions.
* Do not modify this!
*/
public __gmx_version_check(const majorVersion, const minorVersion) {
    if(majorVersion != GMX_MAJOR_VERSION) {
        set_fail_state("Api major version mismatch; expected %d, real %d", GMX_MAJOR_VERSION, majorVersion);
        return;
    }

    if(minorVersion < GMX_MINOR_VERSION){
        set_fail_state("Api minor version mismatch; expected at least %d, real %d", GMX_MINOR_VERSION, minorVersion);
        return;
    }
}
Код:
#if defined _gmx_access_included
    #endinput
#endif

#define _gmx_access_included

enum GMX_PlayerAccess {
    GMX_InvalidPlayerAccess = -1,
};

/**
* Called when GM-X Access is initiated.
*
* @noreturn
*/
forward GMX_AccessInit();

/**
* Returns the key pointer of the specified key.
*
* @param key      Key name to find
*
* @return         Key pointer on success, GMX_InvalidPlayerAccess if key was not
*                 found
* @error          If an invalid number of arguments is set, an error will be
*                 thrown.
*/
native GMX_PlayerAccess:GMX_AccessGetPointer(const key[]);

/**
* Gets access key.
*
* @param access   Key pointer
* @param key      Buffer to copy key value to
* @param len      Maximum size of the buffer
*
* @return         Key pointer on success, GMX_InvalidPlayerAccess if key was not
*                 found
* @error          If an invalid number of arguments is set, or an invalid pointer
*                 is set, an error will be thrown.
*/
native GMX_AccessGetKey(const GMX_PlayerAccess:access, key[], const len);

/**
* Returns if player has access by key.
*
* @param player   Client index
* @param key      Key name
*
* @return         true if player has access, false otherwise
* @error          If player is not connected, or an invalid number of arguments is
*                 set, an error will be thrown.
*/
native bool:GMX_PlayerHasAccess(const player, const key[]);

/**
* Returns if player has access by key pointer.
*
* @param player   Client index
* @param access   Pointer to key
*
* @return         true if player has access, false otherwise
* @error          If player is not connected, or an invalid pointer is set, or an
*                 invalid number of arguments is set, an error will be thrown.
*/
native bool:GMX_PlayerHasPAccess(const player, GMX_PlayerAccess:access);
Код:
#if defined _gmx_cache_included
    #endinput
#endif

#define _gmx_cache_included

#include <grip>

/**
* Loads saved cache by name.
*
* @param name     JSON name
* @param data     JSON handle
*
* @return         true on success, false otherwise
* @error          If an invalid number of arguments is set, an error will be thrown.
*/
native bool:GMX_CacheLoad(const name[], &GripJSONValue:data);

/**
* Saves cache by name.
*
* @param name     JSON name
* @param data     JSON handle
*
* @return         true on success, false otherwise
* @error          If an invalid number of arguments is set, an error will be thrown.
*/
native bool:GMX_CacheSave(const name[], const GripJSONValue:data);
Код:
#if defined _gmx_consts_included
    #endinput
#endif

#define _gmx_consts_included

const GMX_MAX_COMMAND_LENGTH = 32;
const GMX_MAX_COMMAND_DATA_LENGTH = 64;

enum GmxResponseStatus {
    GmxResponseStatusOk,
    GmxResponseStatusCanceled,
    GmxResponseStatusError,
    GmxResponseStatusTimeout,
    GmxResponseStatusNotFound,
    GmxResponseStatusBadToken,
    GmxResponseStatusServerError,
    GmxResponseStatusBadResponse,
    GmxResponseStatusUnknownError
}

enum GmxLogLevel (+=1) {
    GmxLogCritical = 0,
    GmxLogError,
    GmxLogInfo,
    GmxLogDebug
};
Код:
#if defined _gmx_player_preferences_included
    #endinput
#endif

#define _gmx_player_preferences_included

/**
* Called when a player is loading.
*
* @param id                Client index
*
* @noreturn
*/
forward GMX_PP_PlayerLoading(const id);

/**
* Called when a player is loaded.
*
* @param id                Client index
*
* @noreturn
*/
forward GMX_PP_PlayerLoaded(const id);

/**
* Called when a value of a key is changed.
*
* @param id                Client index
* @param key               Unique key
*
* @noreturn
*/
forward APS_PlayerKeyChanged(const id, const key[]);

/**
* Checks if the specified key for player exists.
*
* @param id                Client index
* @param key               Unique key to which the value will be set
*
* @return                  true on success, false otherwise
* @error                   If the index is not within the range of 1 to MaxClients,
*                          an error will be thrown.
*/
native bool:GMX_PP_HasKey(const id, const key[]);

/**
* Gets the value of the specified key set to the player as string.
*
* @param id                Client index
* @param key               Unique key to search for
* @param dest              Buffer to copy value to
* @param length            Maximum buffer size
* @param defaultValue      Default value to set if key wasn't found
*
* @return                  Key's value set to the player or defaultValue if key wasn't found
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native GMX_PP_GetString(const id, const key[], dest[], const length, const defaultValue[] = "");

/**
* Sets a string value for a player for the specified key.
*
* @param id                Client index
* @param key               Unique key to set the value to
* @param value             Value to set
*
* @return                  1 on success, 0 otherwise
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native GMX_PP_SetString(const id, const key[], const value[]);

/**
* Gets the value of the specified key set to the player as integer.
*
* @param id                Client index
* @param key               Unique key to search for
* @param defaultValue      Default value to set if key wasn't found
*
* @return                  Key's value set to the player or defaultValue if key wasn't found
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native GMX_PP_GetNumber(const id, const key[], const defaultValue = 0);

/**
* Sets an integer value for a player for the specified key.
*
* @param id                Client index
* @param key               Unique key to set the value to
* @param value             Value to set
*
* @return                  1 on success, 0 otherwise
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native GMX_PP_SetNumber(const id, const key[], const value);

/**
* Gets the value of the specified key set to the player as boolean.
*
* @param id                Client index
* @param key               Unique key to search for
* @param defaultValue      Default value to set if key wasn't found
*
* @return                  Key's value set to the player or defaultValue if key wasn't found
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native bool:GMX_PP_GetBool(const id, const key[], const bool:defaultValue = false);

/**
* Sets a boolean value for a player for the specified key.
*
* @param id                Client index
* @param key               Unique key to set the value to
* @param value             Value to set
*
* @return                  1 on success, 0 otherwise
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native GMX_PP_SetBool(const id, const key[], const bool:value);

/**
* Gets the value of the specified key set to the player as float.
*
* @param id                Client index
* @param key               Unique key to search for
* @param defaultValue      Default value to set if key wasn't found
*
* @return                  Key's value set to the player or defaultValue if key wasn't found
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native Float:GMX_PP_GetFloat(const id, const key[], const Float:defaultValue = 0.0);

/**
* Sets a float value for a player for the specified key.
*
* @param id                Client index
* @param key               Unique key to set the value to
* @param value             Value to set
*
* @return                  1 on success, 0 otherwise
* @error                   If the index is not within the range of 1 to MaxClients
*                          or an invalid number of arguments is set, an error will be thrown.
*/
native GMX_PP_SetFloat(const id, const key[], const Float:value);
Код:
#if defined _gmx_stocks_included
    #endinput
#endif

#define _gmx_stocks_included

/**
* Returns client index if user id is found.
*
* @param userid    User id to find
*
* @return          Client index, or 0 if not ofund
*/
stock GMX_GetPlayerByUserID(const userid) {
    for (new id = 1; id <= MaxClients; id++) {
        if (is_user_connected(id) && get_user_userid(id) == userid) {
            return id;
        }
    }

    return 0;
}

/**
* Returns client index if player id is found.
*
* @param playerid   User id to find
*
* @return           Client index, or 0 if not found
*/
stock GMX_GetPlayerByPlayerID(const playerid) {
    for (new id = 1; id <= MaxClients; id++) {
        if (is_user_connected(id) && GMX_PlayerIsLoaded(id) && GMX_PlayerGetPlayerId(id) == playerid) {
            return id;
        }
    }

    return 0;
}
Код:
#if defined _gmx_version_included
    #endinput
#endif

#define _gmx_version_included

#define GMX_MAJOR_VERSION            0
#define GMX_MINOR_VERSION            1
#define GMX_MAINTENANCE_VERSION        82
#define GMX_VERSION_STR                "0.1.82-alpha"
Сверху Снизу