Advertisement
Guest User

Untitled

a guest
Sep 4th, 2010
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. SA-MP Plugin Invoke Function
  2. By Peter Beverloo
  3.  
  4. This function demonstrates how you can call native pawn-functions using
  5. plugins. The whole usage of the function is explained in the n_TestInvoke
  6. function, which sends a message to all the clients connected to the server.
  7. The function itself might be complicated and messy, however, the usage
  8. is simple. Each function you use has to be defined as a PAWN_FUNCTION
  9. structure, which contains three elements;
  10.  
  11. struct PAWN_FUNCTION
  12. {
  13. int ParamCnt; // Number of parameters for the function
  14. char Function[ 33 ]; // Name of the function, ex. "GetPlayerPos"
  15. char Params[ 18 ]; // Parameters for the function; i f v p s
  16. };
  17.  
  18. The first entry is obvious, the number of parameters the pawn function
  19. expects. The second one is the name of the function, "GetPlayerName" for
  20. example. As the pawn-limit for functionnames is 32 characters, this doesn't
  21. need to be any bigger. The third variable, Params, explains the way
  22. parameters are handled. There are five possible options:
  23.  
  24. Parameters:
  25. i = integer
  26. f = float value
  27. s = string
  28. v = variable
  29. p = string var (GetPlayerName etc.)
  30.  
  31. While the first three might be clear, the other two might need some
  32. explaining. A variable is what is used in GetPlayerPos, where the floats
  33. get returned in their respective variables. You would use it like this;
  34.  
  35. float fPosX, fPosY, fPosZ;
  36. const PAWN_FUNCTION GetPlayerPos = { 4, "GetPlayerPos", "ivvv" };
  37. PawnCommand( &GetPlayerPos, playerid, &fPosX, &fPosY, &fPosZ );
  38.  
  39. The player's position will be stored in the three float values. The "p"
  40. parameter-type is used for strings which get returned, as is the case
  41. with GetPlayerIp and GetPlayerName. Usage of those functions is like
  42. this;
  43.  
  44. char szPlayerName[ 25 ];
  45. PawnCommand( &GetPlayerName, playerid, szPlayerName, 24 );
  46.  
  47. That's pretty much all there is to say. Again, the code's quite messy
  48. but it works on both Linux as Windows, I'm using it myself. Keep in
  49. mind that AMX is SINGLE THREADED, meaning you cannot have multiple
  50. threads which both execute pawn-functions.
  51.  
  52. Peter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement