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

Very usefull plugin, I'm not expert and I won't say anything about speed or something like comments above, only thing I know I would not use any plugin in next gm that im about to create Nice plugin, really nice plugin...
Reply
#22

Quote:
Originally Posted by Hoda
View Post
Zeex, Not important but I tough let you know a simple bug in the plugin.
You have misspelled weaponid with weaponslot in SetPlayerAmmo



Which should be :



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
Thanks, fixed.
Reply
#23

Zeex I see a_npc include is missing in the plugin so can't use StartRecordingPlayback.
Was it's implementing impossible or what ?
Reply
#24

I bet he have forgot to add these for sure.

OnPlayerClickTextDraw
OnPlayerClickPlayerTextDraw

Zeex can you fix it please ?
Reply
#25

Zeex beside these :

OnPlayerClickTextDraw
OnPlayerClickPlayerTextDraw


I guess you have made a mistake with SetPVarFloat And GetPVarFloat. Are you casting wrongly ?
I do SetPVarFloat to a value like 4.5 but when I get it it's some value between 1 and 2.
Reply
#26

Quote:
Originally Posted by Hoda
View Post
Zeex beside these :

OnPlayerClickTextDraw
OnPlayerClickPlayerTextDraw


I guess you have made a mistake with SetPVarFloat And GetPVarFloat. Are you casting wrongly ?
I do SetPVarFloat to a value like 4.5 but when I get it it's some value between 1 and 2.
I've fixed both, thanks.
Reply
#27

Zeex can you please tell me which compiler you used for the official package ?

This is a CMake or sampgdk bug.
Here is exactly what I did and repeated it like 7-9 times !
Used CMake and configured as VS 2010.
Made only INSTALL package.
Compiled sampgdk with no error or warning. [I also didn't modify code]
Now compiled my plugin with the generated lib.
Copied generated dll to samp folder.
Ran server.
Crashed.
Now without recompiling or anything else I just copied gdk dll from the official package which has been installed in my program files to server folder.
Replaced that with my own compiled dll.
Ran server without crash.
Aditional information :
This happens in the following code :

pawn Code:
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {
        lvdm.Load(ppData); // This line cause the crash with my compiled dll
Reply
#28

Quote:
Originally Posted by klklt0
View Post
The processing speed on the server is slower than using pawn.
It actually might be faster.
Reply
#29

GDK 3.2.1 is released!
  • Fixed functions returning a float giving wrong result
  • Fixed the type of the mode parameter of ShowPlayerMarkers()
  • Added two missing callbacks that were introduced in SA-MP 0.3e

    Code:
      bool OnPlayerClickTextDraw(int playerid, int clickedid);
      bool OnPlayerClickPlayerTextDraw(int playerid, int playertextid);
  • Renamed the weaponslot parameter of SetPlayerAmmo() to weaponid
Reply
#30

Thank you for returning and bringing your awesome creation with you, Zeex!

I have done some basic tests in the past, and yes, the speed gain from simple data access and arithmetic operations (just for example) is a lot bigger than the loss from having to call the native functions through PAWN (if this still works like that). I won't bring any numbers in as my tests may be flawed and all sorts of numbers seem to receive a lot of heat lately

How does calling functions from other plugins work? I've done a bit reading on this subject but I assume there's no really easy way to go?
Reply
#31

Calling other plugins' natives is a bit complex: you have to have an AMX instance on which you call the native function and do all the argument conversion (pushing and popping them on to the stack) similar to public functions.

You can use sampgdk_get_natives() and sampgdk_num_natives() to get the address of the native function you want to call. The former returns a pointer to the array of *all* native functions that have been registered (including those provided by plugins), not just the ones that are used by the AMX - so it's basically unimportant which AMX you'll pass in. The latter returns the number of entries in the array.

For example, to call SendClientMessage() you'd do something like this:

pawn Код:
AMX_NATIVE FindNative(const char *name) {
    const AMX_NATIVE_INFO *natives = sampgdk_get_natives();
    int num_natives = sampgdk_num_natives();

    for (int i = 0; i < num_natives; i++) {
        if (strcmp(natives[i].name, name) == 0) {
            return natives[i].func;
        }
    }

    return 0;
}

bool DoSendClientMessage(int playerid, int color, const char *message) {
    // Make this variable static to search for SendClientMessage only once.
    static AMX_NATIVE native = FindNative("SendClientMessage");

    // Push the arguments on to the stack. Here "amx" is some variable that
    // holds a pointer to some AMX instance.
    cell message_addr;
    amx_PushString(amx, &message_addr, 0, message, false, false);
    amx_Push(amx, color);
    amx_Push(amx, playerid);
    amx_Push(amx, 3 * sizeof(cell)); // 3 is the number of arguments

    // All the "push" functions increase the parameter count which is later
    // used (and reset) by amx_Exec(). But we don't use amx_Exec() so it has to
    // be reset manually.
    amx->paramcount = 0;

    // Get the "params" pointer which points to our newly pushed arguments.
    cell *params;
    amx_GetAddr(amx, amx->stk, &params);

    // Call the function and pop the arguments off the stack.
    cell retval = native(amx, params);
    amx->stk += params[0] + sizeof(cell);

    // Release all the string arguments as you would do with publics.
    amx_Release(amx, message_addr);

    return retval;
}
Note that some plugins like MySQL are built on top of third-party C or C++ libraries which you can use instead (and they are likely to be more flexible).
Reply
#32

Alright, thanks. This is, I assume, exactly what I need! Edit: perfectly working, awesome!

For the MySQL part, I already have written my own implementation of it into my own plugin with a second thread to take care of the querying. I had some thoughts about this for the streamer plugin as well, but its boost dependency and complexity frightened me enough to not write my own implementation (heh, why do something that already has been done in a much better fashion).

Fascinating!
Reply
#33

For anyone interested in calling natives in other plugins: I wrote a convenient function that does the argument conversion for you pushing and popping the arguments (and releasing if necessary) automatically:

https://gist.github.com/Zeex/5217723

Supported argument types are: float, const char* (C-strings), std:tring (C++ strings) and anything that implicitly converts to cell (all integral types including cell itself). You can extend it to support more types by specializing the NativeArgument class template.

Usage:

pawn Код:
#include "call_native.h"

bool MySendClientMessage(int playerid, int color, const char *message) {
    static AMX_NATIVE native = FindNative("SendClientMessage");
    return CallNative<bool>(YouAmxHere, native, playerid, 0x0000FFFF, message);
}
CallNative() supports up to 9 arguments but it's pretty easy to add more if you need, just add a new overload with more parameters.

Be careful passing long strings or anything that may not fit in the AMX heap/stack, which is by default 4096 bytes (can be increased with #pragma dynamic).

By the way, instead of passing a pointer to a real AMX you can use the FakeAmx class from earlier versions of GDK which can be found here:

https://github.com/Zeex/sampgdk/blob/v2.x/src/fakeamx.h
https://github.com/Zeex/sampgdk/blob...rc/fakeamx.cpp

FakeAmx will resize its heap dynamically as needed so you won't ever run out of space.
Reply
#34

xeeZ, not to be a hurt but idk, was just looking through the code..

check line 142

Код:
NativeArgument<T9> a9(amx, x8);
	NativeArgument<T8> a8(amx, x8);
shouldn't the first be x9?
Reply
#35

nice
Reply
#36

sampgdk/a_samp-decl.h
sampgdk/a_players-decl.h
sampgdk/a_objects-decl.h
sampgdk/a_vehicles-decl.h

are missing...
Reply
#37

https://github.com/Zeex/sampgdk/issues/26
Reply
#38

Oh, thanks
Reply
#39

Woah, thats intresting gonna take a look into.
Reply
#40

Can someone explain me, How to run GDK like lvdm plugin.


Sorry for stupid question
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)