Guest User

Untitled

a guest
Jun 5th, 2010
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.35 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define DISTANCE_BETWEEN_PLAYERS 10
  4. #define WAIT_BEFORE_HEALING_AGAIN_TIME 30000
  5. #define WAIT_BEFORE_HEALING_YOURSELF_AGAIN_TIME 10000
  6.  
  7. #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
  8.  
  9.  
  10. #define Red 0xFF0000FF
  11. #define Grey 0xAFAFAFAA
  12. #define Green 0x33AA33AA
  13. #define Yellow 0xFFFF00AA
  14. #define White 0xFFFFFFAA
  15. #define Blue 0x0000BBAA
  16. #define Lightblue 0x33CCFFAA
  17. #define Orange 0xFF9900AA
  18. #define Lime 0x10F441AA
  19. #define Magenta 0xFF00FFFFT
  20. #define Navy 0x000080AA
  21. #define Aqua 0xF0F8FFAA
  22. #define Crimson 0xDC143CAA
  23. #define Black 0x000000AA
  24. #define Brown 0XA52A2AAA
  25. #define Gold 0xB8860BAA
  26. #define Limegreen 0x32CD32AA
  27.  
  28.  
  29. new giveplayerid;
  30.  
  31. public OnPlayerCommandText(playerid, cmdtext[])
  32. {
  33.  dcmd(heal, 4, cmdtext);
  34.  dcmd(trytohealself, 13, cmdtext);
  35.  return 0;
  36. }
  37.  
  38. stock Float:GetDistanceBetweenPlayers(p1,p2){
  39.     new Float:x1,Float:y1,Float:z1,Float:x3,Float:y3,Float:z3;
  40.     if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
  41.         return -1.00;
  42.     }
  43.     GetPlayerPos(p1,x1,y1,z1);
  44.     GetPlayerPos(p2,x3,y3,z3);
  45.     return floatsqroot(floatpower(floatabs(floatsub(x3,x1)),2)+floatpower(floatabs(floatsub(y3,y1)),2)+floatpower(floatabs(floatsub(z3,z1)),2));
  46. }
  47.  
  48. dcmd_heal(playerid, params[])
  49. {
  50.     if(GetPVarInt(playerid,"HEALABUSE")>GetTickCount()) return  SendClientMessage(playerid, Red, "ERROR : You have to wait before healing again!");
  51.     new skinid = GetPlayerSkin(playerid);
  52.     if(skinid == 274 || skinid == 275 || skinid == 276)
  53.     {
  54.     new Float:health;
  55.     new healthee = GetPlayerHealth(giveplayerid, health);
  56.     if(sscanf(params, "u", giveplayerid)) SendClientMessage(playerid, Orange, "USAGE : /heal <playerid>");
  57.     else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, Red, "ERROR : That player is not connected!");
  58.     else if (giveplayerid == playerid) SendClientMessage(playerid, Red, "ERROR : You cant heal yourself!");
  59.     else if (GetDistanceBetweenPlayers(playerid, giveplayerid) > DISTANCE_BETWEEN_PLAYERS){ new string[106]; new name[MAX_PLAYER_NAME]; GetPlayerName(giveplayerid, name, sizeof(name)); format(string, sizeof(string), "ERROR : You must be close to %s before you can heal him!",name);SendClientMessage(playerid, Red, string);}
  60.     else if (healthee == 100){ new string[106]; new name[MAX_PLAYER_NAME]; GetPlayerName(giveplayerid, name, sizeof(name)); format(string, sizeof(string), "ERROR : You cant heal %s! The player has a full health!",name); SendClientMessage(playerid, Red, string);}
  61.     else
  62.     {
  63.     GetPlayerHealth(playerid, health);
  64.     SetPlayerHealth(giveplayerid, 100);
  65.     new name[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME];
  66.     GetPlayerName(giveplayerid, name, sizeof(name)); GetPlayerName(playerid, pname, sizeof(pname));
  67.     new string[106];
  68.     format(string, sizeof(string), "SERVER : You have healed player %s", name);
  69.     SendClientMessage(playerid, Limegreen, string);
  70.     format(string, sizeof(string), "SERVER : Player %s has healed you!", pname);
  71.     SetPVarInt(playerid,"HEALABUSE",GetTickCount()+WAIT_BEFORE_HEALING_AGAIN_TIME);
  72.     SendClientMessage(giveplayerid, Limegreen, string);
  73.     }
  74.     }
  75.     else
  76.     {
  77.     SendClientMessage(playerid, Red, "ERROR : Your not a Medic!");
  78.     }
  79.     return 1;
  80. }
  81.  
  82. dcmd_trytohealself(playerid, params[])
  83. {
  84. if(GetPVarInt(playerid,"HEALSELFABUSE")>GetTickCount()) return  SendClientMessage(playerid, Red, "ERROR : You have to wait before healing yourself again!");
  85. new Float:health; new skinid = GetPlayerSkin(playerid);
  86. #pragma unused params
  87. SetPVarInt(playerid,"HEALSELFABUSE",GetTickCount()+WAIT_BEFORE_HEALING_YOURSELF_AGAIN_TIME);
  88. if(skinid == 274 || skinid == 275 || skinid == 276)
  89. {
  90. switch(random(2))
  91. {
  92. case 0:SendClientMessage(playerid, Limegreen, "You have succesfully healed yourself!"), GetPlayerHealth(playerid, health),SetPlayerHealth(playerid, health+100);
  93. case 1:SendClientMessage(playerid, Red, "ERROR : Wrong healing procedure! You lost 25 health!"), GetPlayerHealth(playerid, health),SetPlayerHealth(playerid, health-25);
  94. }
  95. }
  96. else
  97. {
  98. switch(random(4))
  99. {
  100. case 0:SendClientMessage(playerid, Limegreen, "You have succesfully healed yourself!"), GetPlayerHealth(playerid, health),SetPlayerHealth(playerid, health+100);
  101. case 1:SendClientMessage(playerid, Red, "ERROR : Wrong healing procedure! You lost 50 health!"), GetPlayerHealth(playerid, health),SetPlayerHealth(playerid, health-50);
  102. case 2:SendClientMessage(playerid, Red, "ERROR : Wrong healing procedure! You lost 25 health!"), GetPlayerHealth(playerid, health),SetPlayerHealth(playerid, health-25);
  103. case 3:SendClientMessage(playerid, Red, "ERROR : You have worsen the wound! You bleeded to death!"), GetPlayerHealth(playerid, health),SetPlayerHealth(playerid, 0);
  104. }
  105. }
  106. return 1;
  107. }
  108.  
  109. stock sscanf(string[], format[], {Float,_}:...)
  110. {
  111.     #if defined isnull
  112.         if (isnull(string))
  113.     #else
  114.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  115.     #endif
  116.         {
  117.             return format[0];
  118.         }
  119.     #pragma tabsize 4
  120.     new
  121.         formatPos = 0,
  122.         stringPos = 0,
  123.         paramPos = 2,
  124.         paramCount = numargs(),
  125.         delim = ' ';
  126.     while (string[stringPos] && string[stringPos] <= ' ')
  127.     {
  128.         stringPos++;
  129.     }
  130.     while (paramPos < paramCount && string[stringPos])
  131.     {
  132.         switch (format[formatPos++])
  133.         {
  134.             case '\0':
  135.             {
  136.                 return 0;
  137.             }
  138.             case 'i', 'd':
  139.             {
  140.                 new
  141.                     neg = 1,
  142.                     num = 0,
  143.                     ch = string[stringPos];
  144.                 if (ch == '-')
  145.                 {
  146.                     neg = -1;
  147.                     ch = string[++stringPos];
  148.                 }
  149.                 do
  150.                 {
  151.                     stringPos++;
  152.                     if ('0' <= ch <= '9')
  153.                     {
  154.                         num = (num * 10) + (ch - '0');
  155.                     }
  156.                     else
  157.                     {
  158.                         return -1;
  159.                     }
  160.                 }
  161.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  162.                 setarg(paramPos, 0, num * neg);
  163.             }
  164.             case 'h', 'x':
  165.             {
  166.                 new
  167.                     num = 0,
  168.                     ch = string[stringPos];
  169.                 do
  170.                 {
  171.                     stringPos++;
  172.                     switch (ch)
  173.                     {
  174.                         case 'x', 'X':
  175.                         {
  176.                             num = 0;
  177.                             continue;
  178.                         }
  179.                         case '0' .. '9':
  180.                         {
  181.                             num = (num << 4) | (ch - '0');
  182.                         }
  183.                         case 'a' .. 'f':
  184.                         {
  185.                             num = (num << 4) | (ch - ('a' - 10));
  186.                         }
  187.                         case 'A' .. 'F':
  188.                         {
  189.                             num = (num << 4) | (ch - ('A' - 10));
  190.                         }
  191.                         default:
  192.                         {
  193.                             return -1;
  194.                         }
  195.                     }
  196.                 }
  197.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  198.                 setarg(paramPos, 0, num);
  199.             }
  200.             case 'c':
  201.             {
  202.                 setarg(paramPos, 0, string[stringPos++]);
  203.             }
  204.             case 'f':
  205.             {
  206.  
  207.                 new changestr[16], changepos = 0, strpos = stringPos;
  208.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  209.                 {
  210.                     changestr[changepos++] = string[strpos++];
  211.                     }
  212.                 changestr[changepos] = '\0';
  213.                 setarg(paramPos,0,_:floatstr(changestr));
  214.             }
  215.             case 'p':
  216.             {
  217.                 delim = format[formatPos++];
  218.                 continue;
  219.             }
  220.             case '\'':
  221.             {
  222.                 new
  223.                     end = formatPos - 1,
  224.                     ch;
  225.                 while ((ch = format[++end]) && ch != '\'') {}
  226.                 if (!ch)
  227.                 {
  228.                     return -1;
  229.                 }
  230.                 format[end] = '\0';
  231.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  232.                 {
  233.                     if (format[end + 1])
  234.                     {
  235.                         return -1;
  236.                     }
  237.                     return 0;
  238.                 }
  239.                 format[end] = '\'';
  240.                 stringPos = ch + (end - formatPos);
  241.                 formatPos = end + 1;
  242.             }
  243.             case 'u':
  244.             {
  245.                 new
  246.                     end = stringPos - 1,
  247.                     id = 0,
  248.                     bool:num = true,
  249.                     ch;
  250.                 while ((ch = string[++end]) && ch != delim)
  251.                 {
  252.                     if (num)
  253.                     {
  254.                         if ('0' <= ch <= '9')
  255.                         {
  256.                             id = (id * 10) + (ch - '0');
  257.                         }
  258.                         else
  259.                         {
  260.                             num = false;
  261.                         }
  262.                     }
  263.                 }
  264.                 if (num && IsPlayerConnected(id))
  265.                 {
  266.                     setarg(paramPos, 0, id);
  267.                 }
  268.                 else
  269.                 {
  270.                     #if !defined foreach
  271.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  272.                         #define __SSCANF_FOREACH__
  273.                     #endif
  274.                     string[end] = '\0';
  275.                     num = false;
  276.                     new
  277.                         name[MAX_PLAYER_NAME];
  278.                     id = end - stringPos;
  279.                     foreach (Player, playerid)
  280.                     {
  281.                         GetPlayerName(playerid, name, sizeof (name));
  282.                         if (!strcmp(name, string[stringPos], true, id))
  283.                         {
  284.                             setarg(paramPos, 0, playerid);
  285.                             num = true;
  286.                             break;
  287.                         }
  288.                     }
  289.                     if (!num)
  290.                     {
  291.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  292.                     }
  293.                     string[end] = ch;
  294.                     #if defined __SSCANF_FOREACH__
  295.                         #undef foreach
  296.                         #undef __SSCANF_FOREACH__
  297.                     #endif
  298.                 }
  299.                 stringPos = end;
  300.             }
  301.             case 's', 'z':
  302.             {
  303.                 new
  304.                     i = 0,
  305.                     ch;
  306.                 if (format[formatPos])
  307.                 {
  308.                     while ((ch = string[stringPos++]) && ch != delim)
  309.                     {
  310.                         setarg(paramPos, i++, ch);
  311.                     }
  312.                     if (!i)
  313.                     {
  314.                         return -1;
  315.                     }
  316.                 }
  317.                 else
  318.                 {
  319.                     while ((ch = string[stringPos++]))
  320.                     {
  321.                         setarg(paramPos, i++, ch);
  322.                     }
  323.                 }
  324.                 stringPos--;
  325.                 setarg(paramPos, i, '\0');
  326.             }
  327.             default:
  328.             {
  329.                 continue;
  330.             }
  331.         }
  332.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  333.         {
  334.             stringPos++;
  335.         }
  336.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  337.         {
  338.             stringPos++;
  339.         }
  340.         paramPos++;
  341.     }
  342.     do
  343.     {
  344.         if ((delim = format[formatPos++]) > ' ')
  345.         {
  346.             if (delim == '\'')
  347.             {
  348.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  349.             }
  350.             else if (delim != 'z')
  351.             {
  352.                 return delim;
  353.             }
  354.         }
  355.     }
  356.     while (delim > ' ');
  357.     return 0;
  358. }
Advertisement
Add Comment
Please, Sign In to add comment