S4T3K

zcmd to sampGDK

Oct 13th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <sampgdk\a_samp.h>
  4. #include <map>
  5. #include <string>
  6. #include <functional>
  7.  
  8. #ifndef _ZCMD_H
  9. #define _ZCMD_H
  10.  
  11. extern std::map<std::string, std::function<bool(int, char*)>> commands;
  12.  
  13. #define COMMAND:command(playerid, params) \
  14.     bool cmd_command(int playerid, char* params); \
  15.     commands[#command] = cmd_command(playerid, params); \
  16.     bool cmd_command(int playerid, char* params)
  17.  
  18. #define CMD:command(playerid, params) \
  19.     COMMAND:command(playerid, params)
  20.  
  21. #define command(cmd, playerid, params) \
  22.     COMMAND:cmd(playerid, params)
  23.  
  24. #define cmd(command, playerid, params) \
  25.     COMMAND:command(playerid, params)
  26.  
  27. #ifndef isnull
  28.     #define isnull(str) \
  29.         ((!(str[0])) || (((str[0]) == '\1') && (!(str[1]))))
  30. #endif
  31.  
  32. PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char* cmdtext)
  33. {
  34.     char* cmd;
  35.     int pos;
  36.  
  37.     while (cmdtext[++pos] > ' ')
  38.         cmd[pos - 1] = tolower(cmdtext[pos]);
  39.  
  40.     while (cmdtext[pos] == ' ') pos++;
  41.     char* params = const_cast<char*>(strstr(cmdtext, &cmdtext[pos]));
  42.    
  43.     if (!cmdtext[pos])
  44.         return commands[cmd](playerid, "");
  45.     else
  46.         return commands[cmd](playerid, params);
  47. }
  48.  
  49. #endif
Advertisement
Add Comment
Please, Sign In to add comment