Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SA-MP Plugin Invoke Function
- By Peter Beverloo
- This function demonstrates how you can call native pawn-functions using
- plugins. The whole usage of the function is explained in the n_TestInvoke
- function, which sends a message to all the clients connected to the server.
- The function itself might be complicated and messy, however, the usage
- is simple. Each function you use has to be defined as a PAWN_FUNCTION
- structure, which contains three elements;
- struct PAWN_FUNCTION
- {
- int ParamCnt; // Number of parameters for the function
- char Function[ 33 ]; // Name of the function, ex. "GetPlayerPos"
- char Params[ 18 ]; // Parameters for the function; i f v p s
- };
- The first entry is obvious, the number of parameters the pawn function
- expects. The second one is the name of the function, "GetPlayerName" for
- example. As the pawn-limit for functionnames is 32 characters, this doesn't
- need to be any bigger. The third variable, Params, explains the way
- parameters are handled. There are five possible options:
- Parameters:
- i = integer
- f = float value
- s = string
- v = variable
- p = string var (GetPlayerName etc.)
- While the first three might be clear, the other two might need some
- explaining. A variable is what is used in GetPlayerPos, where the floats
- get returned in their respective variables. You would use it like this;
- float fPosX, fPosY, fPosZ;
- const PAWN_FUNCTION GetPlayerPos = { 4, "GetPlayerPos", "ivvv" };
- PawnCommand( &GetPlayerPos, playerid, &fPosX, &fPosY, &fPosZ );
- The player's position will be stored in the three float values. The "p"
- parameter-type is used for strings which get returned, as is the case
- with GetPlayerIp and GetPlayerName. Usage of those functions is like
- this;
- char szPlayerName[ 25 ];
- PawnCommand( &GetPlayerName, playerid, szPlayerName, 24 );
- That's pretty much all there is to say. Again, the code's quite messy
- but it works on both Linux as Windows, I'm using it myself. Keep in
- mind that AMX is SINGLE THREADED, meaning you cannot have multiple
- threads which both execute pawn-functions.
- Peter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement