08.03.2013, 07:08
(
Last edited by xeeZ; 25/08/2014 at 09:12 AM.
)
NEW: Setting up GDK with CMake
Gamemode SDK for C/C++ (GDK)
The GDK (Gamemode Development Kit) allows you to write SA-MP gamemodes in C/C++. It provides most the functions you would find in Pawn, except those that overlap with the C standard library, like file I/O or string functions, or could be easily implemented on top of it. Callbacks are supported as well.
Example
Here's a "Hello, World!" gamemode:
Full code
Download
To download binary packages for Windows and Linux please visit this page.
Source code
The source code is hosted on GitHub.
Gamemode SDK for C/C++ (GDK)
The GDK (Gamemode Development Kit) allows you to write SA-MP gamemodes in C/C++. It provides most the functions you would find in Pawn, except those that overlap with the C standard library, like file I/O or string functions, or could be easily implemented on top of it. Callbacks are supported as well.
Example
Here's a "Hello, World!" gamemode:
pawn Code:
#include <stdio.h>
#include <string.h>
#include <sampgdk/a_players.h>
#include <sampgdk/a_samp.h>
#include <sampgdk/core.h>
#include <sampgdk/sdk.h>
using sampgdk::logprintf;
void SAMPGDK_CALL PrintTickCountTimer(int timerid, void *params) {
logprintf("Tick count: %d", GetTickCount());
}
PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {
SetGameModeText("Hello, World!");
AddPlayerClass(0, 1958.3783f, 1343.1572f, 15.3746f, 269.1425f, 0, 0, 0, 0, 0, 0);
SetTimer(1000, true, PrintTickCountTimer, 0);
return true;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid) {
SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the HelloWorld server!");
return true;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int playerid, int classid) {
SetPlayerPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
SetPlayerCameraPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
SetPlayerCameraLookAt(playerid, 1958.3783f, 1343.1572f, 15.3746f, CAMERA_CUT);
return true;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char *cmdtext) {
if (strcmp(cmdtext, "/hello") == 0) {
char name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
char message[MAX_CLIENT_MESSAGE];
sprintf(message, "Hello, %s!", name);
SendClientMessage(playerid, 0x00FF00FF, message);
return true;
}
return false;
}
PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
return sampgdk::Supports() | SUPPORTS_PROCESS_TICK;
}
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {
return sampgdk::Load(ppData);
}
PLUGIN_EXPORT void PLUGIN_CALL Unload() {
sampgdk::Unload();
}
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
sampgdk::ProcessTick();
}
Download
To download binary packages for Windows and Linux please visit this page.
Source code
The source code is hosted on GitHub.