whiplk

[Include] JCMD - Processador de comandos(new v2)

Nov 2nd, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.08 KB | None | 0 0
  1. /******************************************************************************\
  2. |                                                                              |
  3. |                       [Include] - Processador de comandos                    |
  4. |                             By Jeffrey_Hatrix                                |
  5. |                       Special thanks to:                                     |
  6. |                       Y_Less - for spend your time chatting me               |
  7. |                           Willian_Luigi - for speed ideas                    |
  8. |                                                                              |
  9. \******************************************************************************/
  10.  
  11. // Versão 2 - perdeu velocidade, ganhou funcionalidade mas está em testes.
  12. // A versão Original está mais rápida e mais funcional, só será lançada após a conclusão das ideias.
  13. // Obs: a nomenclatura está a risco de gerar conflitos, mas para os curiosos e espertos.
  14. // Sim, este problema já foi corrigido na versão original. A velocidade foi afetada um pouco
  15. // mas na versão original ela foi reconstituida.
  16.  
  17.  
  18. /*                              - Exemplos de comandos -                        *\
  19. |   call<NOME>(playerid, params[])                                           |
  20. |   {                                                                        |
  21. |       SendClientMessage(playerid, -1, "Você digitou o nome /NOME");    |
  22. |       return 1;                                                        |
  23. |   }                                                                        |
  24. |                                                                                |
  25. |                                                                                |
  26. |   with params:                                                             |
  27. |   call<vida>(playerid,params[])                                            |
  28. |   {                                                                        |
  29. |       if(isnull(params)) return false;                                 |
  30. |       SetPlayerHealth(playerid, strval(params));                       |
  31. |       SendClientMessage(playerid, -1, "você encheu sua vida...");      |
  32. |       return true;                                                     |
  33. |   }                                                                        |
  34. \*                                                              */
  35. /*
  36. Features:
  37.     - Processador totalmente atualizado do 0, isto é re-feito.
  38.     - Case sensitive incluído(/CoMAnDo = /comando) !
  39.     - Space params incluído(/comando          param) !
  40.     - Callback de gerenciamento OnPerformedCmd incluída(quando o comando é processado) !
  41.     - Callback de gerenciamento OnReceivedCmd incluída(quando o comando é enviado, pré-processo) !
  42.     - Velocidade e otimização em progresso(Somente na versão original) !
  43. */
  44. #if !defined isnull
  45.     #define isnull(%0) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  46. #endif
  47. #define call<%0>(%1) forward @%0(%1); public @%0(%1)
  48. forward OnPerformedCmd(playerid, cmdtext[], success);
  49. forward OnReceivedCmd(playerid,cmdtext[]);
  50.  
  51. new bool:g_callback_OPC = false, bool:g_callback_OSC = false;
  52.  
  53. public
  54.     OnGameModeInit()
  55. {
  56.     printf("GameMode Iniciado!");
  57.     if (funcidx("OnPerformedCmd") != -1) g_callback_OPC = true;
  58.     if (funcidx("OnReceivedCmd") != -1) g_callback_OSC = true;
  59.     if (funcidx("gOnGameModeInit") != -1)
  60.     {
  61.         return CallLocalFunction ("gOnGameModeInit", "");
  62.     }
  63.     return 1 ;
  64. }
  65.  
  66. #if defined _ALS_OnGameModeInit
  67.     #undef OnGameModeInit
  68. #else
  69.     #define _ALS_OnGameModeInit
  70. #endif
  71. #define OnGameModeInit gOnGameModeInit
  72. forward gOnGameModeInit();
  73. public OnPlayerCommandText(playerid, cmdtext[])
  74. {
  75.     if (g_callback_OSC && !CallLocalFunction("OnReceivedCmd", "is", playerid, cmdtext)) return 1;
  76.     static g_nome[32], g_params[32];
  77.     new g_index = strfind(cmdtext, " ");
  78.  
  79.     for (new g_sense = 0; ((g_index && (g_sense < g_index)) || (g_sense < strlen(cmdtext))); g_sense++) cmdtext[g_sense] = tolower(cmdtext[g_sense]);
  80.     if (g_index != -1)
  81.     {
  82.         if ((cmdtext[g_index + 1]) == '\0') cmdtext[g_index] = '\0';
  83.         else
  84.         {
  85.             g_params[0] = EOS;
  86.             new g_idx = g_index;
  87.             while (cmdtext[g_idx] == 0x20) g_idx ++;
  88.             strmid(g_params, cmdtext, g_idx, strlen(cmdtext));
  89.             g_nome[0] = EOS, cmdtext[0] = '@', cmdtext[g_index] = EOS;
  90.             format (g_nome, 32, cmdtext);
  91.             if (funcidx(g_nome) != -1)
  92.             {
  93.                 return CallLocalFunction(g_nome, "is", playerid, g_params), g_callback_OPC?CallLocalFunction("OnPerformedCmd", "isi", playerid, cmdtext, 1):1;
  94.             }
  95.         }
  96.     }
  97.     g_nome[0] = EOS, cmdtext[0] = '@', cmdtext[g_index] = EOS;
  98.     format(g_nome, 32, cmdtext);
  99.     if (funcidx(g_nome) != -1)
  100.     {
  101.         printf("_%s_", g_nome);
  102.         return CallLocalFunction(g_nome, "is", playerid, "\1"), g_callback_OPC?CallLocalFunction("OnPerformedCmd", "isi", playerid, cmdtext, 1):1;
  103.     }
  104.     return g_callback_OPC?CallLocalFunction("OnPerformedCmd", "isi", playerid, cmdtext, 0):1;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment