Gamemode SDK for C/C++ (GDK)
#1

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:

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();
}
Full code

Download

To download binary packages for Windows and Linux please visit this page.

Source code

The source code is hosted on GitHub.
Reply
#2

The most useful plugin for SA-MP !
Is this integrated to 0.3x with all functions ?
Offtopic :
By the way are you really the Zeex ?!!1??
Reply
#3

I know C++ and so I can certainly code in this, but may I know the advantages of this?
Reply
#4

Do you mean you know C++ syntax by 'I know C++' !?
This is not enough.

Advantages :
OOP
CLR (.NET) useful classes.
Speed improvement in calculations.

And every single advantage which I have mentioned worth to whole SA-MP project !
Reply
#5

Nah, I know C++ as in the better way, not the syntax way. Well, not that great, but oKay.
1st advantage and the 3rd makes sense to me!
Reply
#6

Quote:
Originally Posted by Rajat_Pawar
View Post
I know C++ and so I can certainly code in this, but may I know the advantages of this?
Advantages:
  • Possiblity to do OOP
  • Possiblity to use namespaces
  • You can implement other c/++ code on the server, for example, mysql , sockets, and so on.
  • Possiblity of have dynamic arrays
  • Possiblity of using the multithreading system
  • Etc
Disadvantages:
  • The processing speed on the server is slower than using pawn.
Reply
#7

Quote:
Originally Posted by klklt0
View Post
Advantages:
  • Possiblity to do OOP
  • Possiblity to use namespaces
  • You can implement other c/++ code on the server, for example, mysql , sockets, and so on.
  • Possiblity of have dynamic arrays
  • Possiblity of using the multithreading system
  • Etc
Disadvantages:
  • The processing speed on the server is slower than using pawn.
Off topic :
Are you trying to increase your post count or what ?
No one of your advantages are more than what I have already wrote.

On Topic :
However your named disadvantage is completely false. The C++ or any compiled native CPU opcode processing is much much faster than a scripting language which depends on it's run-times.

The only speed decrease is for calling pawn native functions which in no way this count as processing speed !

Also for you knowledge, so next time you wont make false responses. When total speed is increased you can't count this as disadvantage; no matter if it's in processing field or anything else; it is NOT counted as disadvantage.


More :
Most of scripting for SA-MP is calculations and rarely script calls native pawn functions [only SA-MP includes]
It's usually called when processing is finished.
So to everybody who is going to use this plugin except speed increasing and not decreasing in total.
Reply
#8

Quote:
Originally Posted by Hoda
View Post
Off topic :
Are you trying to increase your post count or what ?
No one of your advantages are more than what I have already wrote.
Then just look for the posts you've done, because you just have 5 posts, and you're still spamming like hell.

Quote:
Originally Posted by Hoda
View Post
However your named disadvantage is completely false. The C++ or any compiled native CPU opcode processing is much much faster than a scripting language which depends on it's run-times.

The only speed decrease is for calling pawn native functions which in no way this count as processing speed !

Also for you knowledge, so next time you wont make false responses. When total speed is increased you can't count this as disadvantage; no matter if it's in processing field or anything else; it is NOT counted as disadvantage.
Lol? SA-MP main script is PAWN, so every script called in PAWN will automatically get performed.
PLUGINS will get processed when the SCRIPT call him or whatsoever, so AUTOMATICALLY the processing SPEED is SLOWER.
Sa-mp pawn script calls the plugin
Sa-mp server will proccess the call.
Plugin will receive the call from the sa-mp server
plugin will proccess the call AWAY from the SA-MP server.
then plugin will return the reply for the server
which the server will return for the value defined to return on the function.


Isn't it more slower than pawn?:
Sa-mp script calls the function
SA-MP server process the call
SA-MP server returns the value defined to return on the function.

So SA-MP plugins takes more time to be proccessed, and not the sa-mp functions for pawn.
So it's a disadvantage.

And once again, THIS IS A FORUM, remember that.
Reply
#9

You even didn't try this plugin.. no game-mode or any pawn code call this plugin functions.

I leave this to experienced guys and those who are going to benchmark this because of your lacking of knowledge will just take away my time.
Reply
#10

Quote:
Originally Posted by Hoda
View Post
You even didn't try this plugin.. no game-mode or any pawn code call this plugin functions.

I leave this to experienced guys and those who are going to benchmark this because of your lacking of knowledge will just take away my time.
Lack of knowledge?
Cmon, you should be joking with me

Just a noob don't know that having a gamemode based on a plugin it is still going to be on the same speed.
C/++ is a Impressive language, YES IT IS!, c++ is used here to give more functionality to pawn, not to write full gamemodes on it!
And you still say a Lack of knowledge?

A plugin to be executed will use more ram than the server function and script himself-
You still say a lack of knowledge?

This plugin can be runned without the .pwn script being created, but it still get's called BY THE SERVER to be executed, so it will be always more slower than the pawn script!
And you still say a lack of knowledge?

I am on a programming course for more than 1 year now, but since 4 years ago i script in c/++ based languages[php, java, javascript, c#, squirrel] as well on non c++ based languages[lua, python, delphin, pascal]
And you still say a lack of knowledge?

Just look for you, most likely you can't even declare a function in c/++ with OOP and Namespace.
And you still say a lack of knowledge?
Reply
#11

Awesome!
Reply
#12

Quote:
Originally Posted by klklt0
View Post
Lack of knowledge?
Cmon, you should be joking with me

Just a noob don't know that having a gamemode based on a plugin it is still going to be on the same speed.
C/++ is a Impressive language, YES IT IS!, c++ is used here to give more functionality to pawn, not to write full gamemodes on it!
And you still say a Lack of knowledge?

A plugin to be executed will use more ram than the server function and script himself-
You still say a lack of knowledge?

This plugin can be runned without the .pwn script being created, but it still get's called BY THE SERVER to be executed, so it will be always more slower than the pawn script!
And you still say a lack of knowledge?

I am on a programming course for more than 1 year now, but since 4 years ago i script in c/++ based languages[php, java, javascript, c#, squirrel] as well on non c++ based languages[lua, python, delphin, pascal]
And you still say a lack of knowledge?

Just look for you, most likely you can't even declare a function in c/++ with OOP and Namespace.
And you still say a lack of knowledge?
I'm getting cancer with all your posts in this thread.
Think about this:
Pawn code is processed into opcodes which an abstract machine will process and convert it (or simply call, accordingly to the opcode and processor). That makes arithmetic and binary operations, flow control and native function calling possible and very easy to the scripter to develop an usable piece of code.

From the other side, let's think about an example: float.inc.
Will you dare to tell me a "locally" processor opcode complied dynamic library would be any slower than a pawn script on a script with only float and arithmetic functions?
If you think your high level libraries knowledge will, in some way, help you in this conversation about an opcode abstract machine and C++ std functions, you're fairly wrong.

Computers are all about the math. So, do your math! Literally.
Reply
#13

I'm not going to enumerate all of the advantages of C++ over the utter limited interpreted language and its VM designed to run in embedded systems with very limited resources. I'd just add that the little overhead involved in calling SA-MP natives or getting called back by the server that you might be concerned of is nothing compared to the speed of highly optimized native code you get with C/C++ (given that your server is not running on a toster).
Reply
#14

Quote:
Originally Posted by Y_Less
View Post
klklt0: Have you actually read the source of this plugin at all? Or the source of the PAWN BVM (which is open-source)? If not, then I'd support the claim of "lack of knowledge" and add that you have an "abundance of speculation" - not the same thing at all.
I've readed a bit of the GDK code, not all.
And the disadvantage was more considerated for the plugins on overall, and not for this plugin himself.
The little difference of this plugin to others is that it doesn't uses a .pwn script, but it still keeps getting called by the sa-mp server, the delay can exists or not, of course it depends on the code the function have, the calcules the server have to do, and so on, like you said.

But for other plugins, it is a bit slower because the Server needs to request to the PAWN SCRIPT which will request to the SERVER to execute the function X, which after executed will return the data to the SERVER, which will return to the PAWN function.

Since i don't know the sa-mp server architecture i can't neither say too much about it, nor how it does work internally.
So, since then it will have a little delay on the execution[even't if we don't notice it, there is a little delay].
It's like

Calls the function | executes the function | return the data
Server -> Pawn -> Server -> Plugin -> Server -> Pawn.

Quote:
Originally Posted by Y_Less
View Post
By the way, serveral of your points were dangerously close to attacking the poster not the post - that is flaming and expressly against forum rules, debates are not.
I won't repeat it again, just make sure that he don't do the same.


@Stewie`
Are you perfect?
Because i'm not.
Failing and doing errors is a natural, no one is perfect, everyone fails, everyone do errors, and the most important, everyone learn with their errors.
Reply
#15

Quote:
Originally Posted by Y_Less
View Post
But as you point out this plugin doesn't go through PAWN scripts, so why even bring the point up?
Nevermind it
Reply
#16

Quote:
Originally Posted by klklt0
View Post
Are you perfect?
Because i'm not.
Failing and doing errors is a natural, no one is perfect, everyone fails, everyone do errors, and the most important, everyone learn with their errors.
So there's your dilemma. I'm not perfect, but I try not to bullshit on something I don't know and also not to cause an indignation shitstorm like you did. You have to fill your chest and say: Please tell me where I'm wrong while I carefully read over all comments and try to aggregate as knowledge as possible! Yay.

Please don't get me wrong.
Reply
#17

Come on guys, chill out, we are kind of going off topic here. I would also like to congratulate xeeZ on this development, I find it quite useful and might post in here later about them, after ******-ing.

OFF-TOPIC: Also, klklt0, I suggest you try 'discussing' this over IRC with Y_Less, as it's almost impossible here to have a healthy discussion / debate with a moderator / beta tester without hundreds of 'loyal members' abusing you.
(No offense at any members)
Reply
#18

Quote:
Originally Posted by Stewie`
View Post
So there's your dilemma. I'm not perfect, but I try not to bullshit on something I don't know and also not to cause an indignation shitstorm like you did. You have to fill your chest and say: Please tell me where I'm wrong while I carefully read over all comments and try to aggregate as knowledge as possible! Yay.

Please don't get me wrong.
I understand what you mean.


Quote:
Originally Posted by Rajat_Pawar
View Post
Come on guys, chill out, we are kind of going off topic here. I would also like to congratulate xeeZ on this development, I find it quite useful and might post in here later about them, after ******-ing.

OFF-TOPIC: Also, klklt0, I suggest you try 'discussing' this over IRC with Y_Less, as it's almost impossible here to have a healthy discussion / debate with a moderator / beta tester without hundreds of 'loyal members' abusing you.
(No offense at any members)
I'm not a huge fan of IRC though xd
Reply
#19

I think I will try to understand all the plugin and the script... btw.. Are u the creator of the ZCMD?
Reply
#20

Zeex, Not important but I tough let you know a simple bug in the plugin.
You have misspelled weaponid with weaponslot in SetPlayerAmmo

Quote:

SAMPGDK_NATIVE_EXPORT bool SAMPGDK_NATIVE_CALL sampgdk_SetPlayerAmmo(int playerid, int weaponslot, int ammo);

Which should be :
Quote:

SAMPGDK_NATIVE_EXPORT bool SAMPGDK_NATIVE_CALL sampgdk_SetPlayerAmmo(int playerid, int weaponid, int ammo);

I wanted to do a commit to GitHub but since this won't make a difference I leave this to you and your wish

EDIT : Ahh after saw a_players.inc provided with latest version of server I found out this was not your fault but Kalkor
I have reported this as a bug so he can fix it in next versions
EDIT 2: Wiki : https://sampwiki.blast.hk/wiki/SetPlayerAmmo
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)