Advertisement
Guest User

Untitled

a guest
Aug 24th, 2010
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.54 KB | None | 0 0
  1. #include <a_samp>
  2. // Ez a DCMD definíciója
  3. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  4.  
  5. public OnPlayerCommandText(playerid, cmdtext[])
  6. {
  7.     dcmd(heal, 4, cmdtext);
  8.     return 0;
  9. }
  10. //Ez a heal parancs DCMD-ben
  11. dcmd_heal(playerid, params[])
  12. {
  13.     new giveplayerid; //ez lesz a másik játékos
  14.     if (sscanf(params, "u", giveplayerid)) SendClientMessage(playerid, 0xFF0000AA, "Használat: /heal [playerid]");
  15.     else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Hiba: Nincs ilyen játékos!");
  16.     else{
  17.         new name[MAX_PLAYER_NAME],string[200];
  18.         GetPlayerName(playerid, name, sizeof(name));
  19.         format(string, sizeof string, "%s feltöltötte valakinek az életét", name);
  20.         SendClientMessageToAll(0xFF0000AA,string);
  21.     }
  22.     return 1;
  23. }
  24. // Ez az SScanf
  25. stock sscanf(string[], format[], {Float,_}:...)
  26. {
  27.     #if defined isnull
  28.         if (isnull(string))
  29.     #else
  30.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  31.     #endif
  32.         {
  33.             return format[0];
  34.         }
  35.     #pragma tabsize 4
  36.     new
  37.         formatPos = 0,
  38.         stringPos = 0,
  39.         paramPos = 2,
  40.         paramCount = numargs(),
  41.         delim = ' ';
  42.     while (string[stringPos] && string[stringPos] <= ' ')
  43.     {
  44.         stringPos++;
  45.     }
  46.     while (paramPos < paramCount && string[stringPos])
  47.     {
  48.         switch (format[formatPos++])
  49.         {
  50.             case '\0':
  51.             {
  52.                 return 0;
  53.             }
  54.             case 'i', 'd':
  55.             {
  56.                 new
  57.                     neg = 1,
  58.                     num = 0,
  59.                     ch = string[stringPos];
  60.                 if (ch == '-')
  61.                 {
  62.                     neg = -1;
  63.                     ch = string[++stringPos];
  64.                 }
  65.                 do
  66.                 {
  67.                     stringPos++;
  68.                     if ('0' <= ch <= '9')
  69.                     {
  70.                         num = (num * 10) + (ch - '0');
  71.                     }
  72.                     else
  73.                     {
  74.                         return -1;
  75.                     }
  76.                 }
  77.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  78.                 setarg(paramPos, 0, num * neg);
  79.             }
  80.             case 'h', 'x':
  81.             {
  82.                 new
  83.                     num = 0,
  84.                     ch = string[stringPos];
  85.                 do
  86.                 {
  87.                     stringPos++;
  88.                     switch (ch)
  89.                     {
  90.                         case 'x', 'X':
  91.                         {
  92.                             num = 0;
  93.                             continue;
  94.                         }
  95.                         case '0' .. '9':
  96.                         {
  97.                             num = (num << 4) | (ch - '0');
  98.                         }
  99.                         case 'a' .. 'f':
  100.                         {
  101.                             num = (num << 4) | (ch - ('a' - 10));
  102.                         }
  103.                         case 'A' .. 'F':
  104.                         {
  105.                             num = (num << 4) | (ch - ('A' - 10));
  106.                         }
  107.                         default:
  108.                         {
  109.                             return -1;
  110.                         }
  111.                     }
  112.                 }
  113.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  114.                 setarg(paramPos, 0, num);
  115.             }
  116.             case 'c':
  117.             {
  118.                 setarg(paramPos, 0, string[stringPos++]);
  119.             }
  120.             case 'f':
  121.             {
  122.  
  123.                 new changestr[16], changepos = 0, strpos = stringPos;
  124.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  125.                 {
  126.                     changestr[changepos++] = string[strpos++];
  127.                     }
  128.                 changestr[changepos] = '\0';
  129.                 setarg(paramPos,0,_:floatstr(changestr));
  130.             }
  131.             case 'p':
  132.             {
  133.                 delim = format[formatPos++];
  134.                 continue;
  135.             }
  136.             case '\'':
  137.             {
  138.                 new
  139.                     end = formatPos - 1,
  140.                     ch;
  141.                 while ((ch = format[++end]) && ch != '\'') {}
  142.                 if (!ch)
  143.                 {
  144.                     return -1;
  145.                 }
  146.                 format[end] = '\0';
  147.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  148.                 {
  149.                     if (format[end + 1])
  150.                     {
  151.                         return -1;
  152.                     }
  153.                     return 0;
  154.                 }
  155.                 format[end] = '\'';
  156.                 stringPos = ch + (end - formatPos);
  157.                 formatPos = end + 1;
  158.             }
  159.             case 'u':
  160.             {
  161.                 new
  162.                     end = stringPos - 1,
  163.                     id = 0,
  164.                     bool:num = true,
  165.                     ch;
  166.                 while ((ch = string[++end]) && ch != delim)
  167.                 {
  168.                     if (num)
  169.                     {
  170.                         if ('0' <= ch <= '9')
  171.                         {
  172.                             id = (id * 10) + (ch - '0');
  173.                         }
  174.                         else
  175.                         {
  176.                             num = false;
  177.                         }
  178.                     }
  179.                 }
  180.                 if (num && IsPlayerConnected(id))
  181.                 {
  182.                     setarg(paramPos, 0, id);
  183.                 }
  184.                 else
  185.                 {
  186.                     #if !defined foreach
  187.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  188.                         #define __SSCANF_FOREACH__
  189.                     #endif
  190.                     string[end] = '\0';
  191.                     num = false;
  192.                     new
  193.                         name[MAX_PLAYER_NAME];
  194.                     id = end - stringPos;
  195.                     foreach (Player, playerid)
  196.                     {
  197.                         GetPlayerName(playerid, name, sizeof (name));
  198.                         if (!strcmp(name, string[stringPos], true, id))
  199.                         {
  200.                             setarg(paramPos, 0, playerid);
  201.                             num = true;
  202.                             break;
  203.                         }
  204.                     }
  205.                     if (!num)
  206.                     {
  207.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  208.                     }
  209.                     string[end] = ch;
  210.                     #if defined __SSCANF_FOREACH__
  211.                         #undef foreach
  212.                         #undef __SSCANF_FOREACH__
  213.                     #endif
  214.                 }
  215.                 stringPos = end;
  216.             }
  217.             case 's', 'z':
  218.             {
  219.                 new
  220.                     i = 0,
  221.                     ch;
  222.                 if (format[formatPos])
  223.                 {
  224.                     while ((ch = string[stringPos++]) && ch != delim)
  225.                     {
  226.                         setarg(paramPos, i++, ch);
  227.                     }
  228.                     if (!i)
  229.                     {
  230.                         return -1;
  231.                     }
  232.                 }
  233.                 else
  234.                 {
  235.                     while ((ch = string[stringPos++]))
  236.                     {
  237.                         setarg(paramPos, i++, ch);
  238.                     }
  239.                 }
  240.                 stringPos--;
  241.                 setarg(paramPos, i, '\0');
  242.             }
  243.             default:
  244.             {
  245.                 continue;
  246.             }
  247.         }
  248.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  249.         {
  250.             stringPos++;
  251.         }
  252.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  253.         {
  254.             stringPos++;
  255.         }
  256.         paramPos++;
  257.     }
  258.     do
  259.     {
  260.         if ((delim = format[formatPos++]) > ' ')
  261.         {
  262.             if (delim == '\'')
  263.             {
  264.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  265.             }
  266.             else if (delim != 'z')
  267.             {
  268.                 return delim;
  269.             }
  270.         }
  271.     }
  272.     while (delim > ' ');
  273.     return 0;
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement