Dion ibe Posted February 22, 2016 Share Posted February 22, 2016 (edited) The GDK (Gamemode Development Kit a.k.a sampgdk) provides an API for developing SA-MP gamemodes in C or C++. Gamemodes written with GDK are no different from ordinary server plugins except that they make calls to an external library - the GDK runtime - that implements the core functionality, like SA-MP native functions, and can call you back if you want to handle certain SA-MP events (callbacks). ---------------------------------------------------------------------------------------------------------------- The structure of a GDK-based plugin is somewhat similar to that of a basic Pawn script: ---------------------------------------------------------------------------------------------------------------- *Pawn Code: 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); ServerLog::Printf("------------------------------------------\n"); ServerLog::Printf(" HelloWorld gamemode got loaded. \n"); ServerLog::Printf("------------------------------------------\n"); SetTimer(1000, true, Timer, 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 (std::strcmp(cmdtext, "/hello") == 0) { char name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); char message[128]; std::sprintf(message, "Hello, %s!", name); SendClientMessage(playerid, 0x00FF00FF, message); return true; } if (std::strcmp(cmdtext, "/pos") == 0) { float x, y, z; GetPlayerPos(playerid, &x, &y, &z); char message[128]; std::sprintf(message, "You are at (%f, %f, %f)", x, y, z); SendClientMessage(playerid, 0xFFFFFFFF, message); return true; } return false; } Of course, since it's a plugin you'll need some additional boilerplate code (please consult the Plugin development guide for more details). Besides that you also have to perform some additional initialization and cleanup steps: *Pawn Code: static ThisPlugin helloworld; PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { helloworld.Load(ppData); return true; } PLUGIN_EXPORT void PLUGIN_CALL Unload() { helloworld.Unload(); } Now if you are not planning to use timers you can stop at this point. Otherwise, there's one more thing left to do: *Pawn Code: PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() { helloworld.ProcessTimers(); } That's it! Source code @@ Thanks for your time of Watching ,if you have problem you can contact me with P.M,I'm Active :24/24 To your questions,GooD-bye.. Edited February 22, 2016 by HasseN 1 Link to comment Share on other sites More sharing options...
CoZmiNeXeV69 Posted March 5, 2016 Share Posted March 5, 2016 Thanks. Nice topic. Link to comment Share on other sites More sharing options...
FnZ Posted March 9, 2016 Share Posted March 9, 2016 Good tutorial, you should do more of them. Closed. Link to comment Share on other sites More sharing options...
Recommended Posts