SHARE
TWEET

zcmd

Slasheer Mar 17th, 2011 1,111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**********************************
  2.  *                                *
  3.  *   @Author:      ZeeX           *
  4.  *   @Version:     0.3.1          *
  5.  *   @Released:    31/10/2009     *
  6.  *                                *
  7.  **********************************/
  8.  
  9. #if defined _zcmd_included
  10.         #endinput
  11. #endif 
  12. #define _zcmd_included
  13.  
  14. #define MAX_FUNC_NAME (32)
  15.  
  16. #define COMMAND:%1(%2)          \
  17.                         forward cmd_%1(%2); \
  18.                         public cmd_%1(%2)              
  19.                        
  20. #define CMD:%1(%2) \
  21.                         COMMAND:%1(%2)
  22.  
  23. #define command(%1,%2,%3) \
  24.                         COMMAND:%1(%2, %3)      
  25.      
  26. #define cmd(%1,%2,%3) \
  27.                         COMMAND:%1(%2, %3)
  28.  
  29. #if !defined isnull
  30.         #define isnull(%1) \
  31.                                 ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  32. #endif
  33.  
  34.  
  35. forward OnPlayerCommandReceived(playerid, cmdtext[]);
  36. forward OnPlayerCommandPerformed(playerid, cmdtext[], success);
  37.  
  38.  
  39. static
  40.         bool:zcmd_g_HasOPCS = false,
  41.         bool:zcmd_g_HasOPCE = false;
  42.  
  43. #if defined FILTERSCRIPT
  44.  
  45. public OnFilterScriptInit()
  46. {
  47.         zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
  48.         zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
  49.     return CallLocalFunction("zcmd_OnFilterScriptInit", "");
  50. }
  51.  
  52. #if defined _ALS_OnFilterScriptInit
  53.     #undef OnFilterScriptInit
  54. #else
  55.     #define _ALS_OnFilterScriptInit
  56. #endif
  57. #define OnFilterScriptInit zcmd_OnFilterScriptInit
  58. forward zcmd_OnFilterScriptInit();
  59.  
  60. #else /*not a filterscript*/
  61.  
  62. public OnGameModeInit()
  63. {
  64.         zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
  65.         zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
  66.         if (funcidx("zcmd_OnGameModeInit") != -1)
  67.         {
  68.                 return CallLocalFunction("zcmd_OnGameModeInit", "");
  69.         }      
  70.         return 1;
  71. }
  72.  
  73. #if defined _ALS_OnGameModeInit
  74.     #undef OnGameModeInit
  75. #else
  76.     #define _ALS_OnGameModeInit
  77. #endif
  78. #define OnGameModeInit zcmd_OnGameModeInit
  79. forward zcmd_OnGameModeInit();
  80.  
  81. #endif /*if defined FILTERSCRIPT*/
  82.  
  83. public OnPlayerCommandText(playerid, cmdtext[])
  84. {
  85.     if (zcmd_g_HasOPCS && !CallLocalFunction("OnPlayerCommandReceived", "is", playerid, cmdtext))
  86.     {
  87.         return 1;
  88.     }
  89.     new
  90.         pos,
  91.         funcname[MAX_FUNC_NAME];
  92.     while (cmdtext[++pos] > ' ')
  93.         {
  94.                 funcname[pos-1] = tolower(cmdtext[pos]);
  95.         }
  96.         format(funcname, sizeof(funcname), "cmd_%s", funcname);
  97.     while (cmdtext[pos] == ' ') pos++;
  98.         if (!cmdtext[pos])
  99.         {
  100.                 if (zcmd_g_HasOPCE)
  101.                 {
  102.                         return CallLocalFunction("OnPlayerCommandPerformed", "isi", playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, "\1"));
  103.                 }
  104.                 return CallLocalFunction(funcname, "is", playerid, "\1");      
  105.         }
  106.         if (zcmd_g_HasOPCE)
  107.         {
  108.                 return CallLocalFunction("OnPlayerCommandPerformed", "isi", playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, cmdtext[pos]));
  109.         }
  110.         return CallLocalFunction(funcname, "is", playerid, cmdtext[pos]);
  111. }
  112.  
  113. #if defined _ALS_OnPlayerCommandText
  114.     #undef OnPlayerCommandText
  115. #else
  116.     #define _ALS_OnPlayerCommandText
  117. #endif
  118. #define OnPlayerCommandText zcmd_OnPlayerCommandText
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top