samp.directory
← Scripts and libraries

katursis/samp-ptl

SA:MP Plugin Template Library (C++17)

Plugin★ 39updated Feb 2023MITC++
Open on GitHub
Try it in the Pawn compiler →

Adds its include files, with the libraries it depends on, to the Pawn compiler in your browser, ready to include in a script.

README.md

SA:MP Plugin Template Library

C++17 template library that allows you to create your own plugins for SA:MP server very easy and fast

Main features

  • Safe C++ AMX API with errors handling
  • Queue of AMX scripts (gamemode at the end)
  • Easy executing the callbacks (publics) with optional caching
  • Easy registration of natives: auto-conversion parameters from cell type to common C++ types. You may also define your own conversions by extending Script::NativeParam struct
  • Logging
  • Optional checking for a version match between the plugin and scripts

Example

#include "samp-ptl/ptl.h"

class Script : public ptl::AbstractScript<Script> {
 public:
  // native ExampleNative(int_number, Float:float_number, &ref, const text[]);
  cell n_ExampleNative(int int_number, float float_number, cell *ref,
                       std::string text) {
    Log("int_number = %d, float_number = %.2f, text = '%s'", int_number,
        float_number, text.c_str());

    *ref = 23;

    return 1;
  }
};

class Plugin : public ptl::AbstractPlugin<Plugin, Script> {
 public:
  const char *Name() { return "samp-example-plugin"; }

  bool OnLoad() {
    RegisterNative<&Script::n_ExampleNative>("ExampleNative");

    Log("plugin loaded");

    return true;
  }
};

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
  return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}

PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {
  return Plugin::DoLoad(ppData);
}

PLUGIN_EXPORT void PLUGIN_CALL Unload() {
  Plugin::DoUnload();
}

PLUGIN_EXPORT void PLUGIN_CALL AmxLoad(AMX *amx) {
  Plugin::DoAmxLoad(amx);
}

PLUGIN_EXPORT void PLUGIN_CALL AmxUnload(AMX *amx) {
  Plugin::DoAmxUnload(amx);
}

More examples

Simple plugin

Pawn.RakNet

Pawn.CMD

Pawn.Regex

amxcpp17cpp17-librarypawnpluginsa-mpsampsdkserver-side

This page is built from what GitHub publishes about the repository. samp.directory does not host the code. Report a problem with this listing

katursis/samp-ptl: SA-MP Plugin | samp.directory