Guest User

Cage system by [AK]Nazgul

a guest
May 3rd, 2013
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.27 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4.  
  5. #define COLOR_RED 0xFF2100FF
  6. #define COLOR_PINK 0xFF00FFFF
  7.  
  8. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  9.  
  10. new caged[MAX_PLAYERS];
  11. new Float:CageInfoX[MAX_PLAYERS];
  12. new Float:CageInfoY[MAX_PLAYERS];
  13. new Float:CageInfoZ[MAX_PLAYERS];
  14. new cage1[MAX_PLAYERS];
  15. new cage2[MAX_PLAYERS];
  16. new cage3[MAX_PLAYERS];
  17. new cage4[MAX_PLAYERS];
  18. new cage5[MAX_PLAYERS];
  19. new cage6[MAX_PLAYERS];
  20.    
  21. //------------------------------------------------------------------------------
  22.  
  23. public OnFilterScriptInit()
  24. {
  25.     print("\n--------------------------------------");
  26.     print(" Cage system by [AK]Nazgul");
  27.     print("--------------------------------------\n");
  28.     return 1;
  29. }
  30.  
  31. public OnFilterScriptExit()
  32. {
  33.     return 1;
  34. }
  35.  
  36. //------------------------------------------------------------------------------
  37.  
  38. forward cagetimer(playerid);
  39. public cagetimer(playerid)
  40. {
  41.     SetPlayerPos(playerid,CageInfoX[playerid],CageInfoY[playerid],CageInfoZ[playerid]+2);
  42. }
  43.  
  44. //------------------------------------------------------------------------------
  45.  
  46. public OnPlayerSpawn(playerid)
  47. {
  48.     if(caged[playerid] == 1)
  49.     {
  50.         SetTimerEx("cagetimer",500,false,"u",playerid);
  51.     }
  52.     return 1;
  53. }
  54.  
  55. //------------------------------------------------------------------------------
  56.  
  57. public OnPlayerCommandText(playerid, cmdtext[])
  58. {
  59.     dcmd(cage, 4, cmdtext);
  60.     dcmd(dcage, 5, cmdtext);
  61.     dcmd(kill, 4, cmdtext);
  62.     return 0;
  63. }
  64. //##############################################################################
  65. //######################################DCMD####################################
  66.     dcmd_kill(playerid,params[])
  67.     {
  68.         #pragma unused params
  69.         SetPlayerHealth(playerid,0);
  70.         return 1;
  71.     }
  72.     dcmd_cage(playerid,params[])
  73.     {
  74.         if(IsPlayerAdmin(playerid))
  75.         {
  76.             new pID;
  77.             if(sscanf(params,"u",pID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /cage [ID]");
  78.             if(caged[pID] == 1) return SendClientMessage(playerid,COLOR_RED,"Player already caged.");
  79.            
  80.             DestroyObject(cage1[pID]);
  81.             DestroyObject(cage2[pID]);
  82.             DestroyObject(cage3[pID]);
  83.             DestroyObject(cage4[pID]);
  84.             DestroyObject(cage5[pID]);
  85.             DestroyObject(cage6[pID]);
  86.  
  87.             new string[128];
  88.             new Float:X, Float:Y, Float:Z;
  89.  
  90.             GetPlayerPos(pID,X,Y,Z);
  91.             cage1[pID] = CreateObject(985, X, Y, Z+10, 0, 0, 0);
  92.             cage2[pID] = CreateObject(985, X+4 ,Y-4 , Z+10, 0, 0, 90);
  93.             cage3[pID] = CreateObject(985, X-4 , Y-4 , Z+10, 0, 0, 90);
  94.             cage4[pID] = CreateObject(985, X , Y-8 , Z+10, 0, 0, 0);
  95.             cage5[pID] = CreateObject(985, X , Y-4 , Z+8.2, 90, 0, 0);
  96.             cage6[pID] = CreateObject(985, X , Y-4 , Z+8.2, 90, 0, 180);
  97.  
  98.             SetPlayerPos(pID,X,Y- 2,Z+15);
  99.             CageInfoX[pID]= X;
  100.             CageInfoY[pID]= Y-2;
  101.             CageInfoZ[pID]= Z+15;
  102.             caged[pID] = 1;
  103.             format(string,128,"[Admin] You have caged %s -> /dcage <id> to uncage.",PlayerName(pID));
  104.             SendClientMessage(playerid,COLOR_RED,string);
  105.             new str[128];
  106.             format(str,128,"** ADMIN CAGE: %s (%i) has been caged",PlayerName(pID),pID);
  107.             SendClientMessageToAll(COLOR_PINK,str);
  108.             return 1;
  109.         }
  110.         else{SendClientMessage(playerid,COLOR_RED,"You can't use this command!"); return 1;}
  111.     }
  112.    
  113.     dcmd_dcage(playerid,params[])
  114.     {
  115.         if(IsPlayerAdmin(playerid))
  116.         {
  117.             new pID;
  118.             if(sscanf(params,"u",pID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /dcage [ID]");
  119.             if(caged[pID] == 0) return SendClientMessage(playerid,COLOR_RED,"Player not caged.");
  120.            
  121.             DestroyObject(cage1[pID]);
  122.             DestroyObject(cage2[pID]);
  123.             DestroyObject(cage3[pID]);
  124.             DestroyObject(cage4[pID]);
  125.             DestroyObject(cage5[pID]);
  126.             DestroyObject(cage6[pID]);
  127.            
  128.             SetPlayerPos(pID,CageInfoX[pID],CageInfoY[pID],CageInfoZ[pID]-10);
  129.             caged[pID] = 0;
  130.             new str[128];
  131.             format(str,128,"** ADMIN CAGE: %s (%i) has been uncaged",PlayerName(pID),pID);
  132.             SendClientMessageToAll(COLOR_PINK,str);
  133.             return 1;
  134.         }
  135.         else{SendClientMessage(playerid,COLOR_RED,"You can't use this command!"); return 1;}
  136.     }
  137.    
  138. //------------------------------------------------------------------------------
  139.  
  140. stock PlayerName(playerid)
  141. {
  142.     new name[MAX_PLAYER_NAME];
  143.     GetPlayerName(playerid,name,sizeof(name)); return name;
  144. }
  145.  
  146. //##############################################################################
  147. //######################################SSCANF##################################
  148.  
  149. stock sscanf(string[], format[], {Float,_}:...)
  150. {
  151.     #if defined isnull
  152.         if (isnull(string))
  153.     #else
  154.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  155.     #endif
  156.         {
  157.             return format[0];
  158.         }
  159.     #pragma tabsize 4
  160.     new
  161.         formatPos = 0,
  162.         stringPos = 0,
  163.         paramPos = 2,
  164.         paramCount = numargs(),
  165.         delim = ' ';
  166.     while (string[stringPos] && string[stringPos] <= ' ')
  167.     {
  168.         stringPos++;
  169.     }
  170.     while (paramPos < paramCount && string[stringPos])
  171.     {
  172.         switch (format[formatPos++])
  173.         {
  174.             case '\0':
  175.             {
  176.                 return 0;
  177.             }
  178.             case 'i', 'd':
  179.             {
  180.                 new
  181.                     neg = 1,
  182.                     num = 0,
  183.                     ch = string[stringPos];
  184.                 if (ch == '-')
  185.                 {
  186.                     neg = -1;
  187.                     ch = string[++stringPos];
  188.                 }
  189.                 do
  190.                 {
  191.                     stringPos++;
  192.                     if ('0' <= ch <= '9')
  193.                     {
  194.                         num = (num * 10) + (ch - '0');
  195.                     }
  196.                     else
  197.                     {
  198.                         return -1;
  199.                     }
  200.                 }
  201.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  202.                 setarg(paramPos, 0, num * neg);
  203.             }
  204.             case 'h', 'x':
  205.             {
  206.                 new
  207.                     num = 0,
  208.                     ch = string[stringPos];
  209.                 do
  210.                 {
  211.                     stringPos++;
  212.                     switch (ch)
  213.                     {
  214.                         case 'x', 'X':
  215.                         {
  216.                             num = 0;
  217.                             continue;
  218.                         }
  219.                         case '0' .. '9':
  220.                         {
  221.                             num = (num << 4) | (ch - '0');
  222.                         }
  223.                         case 'a' .. 'f':
  224.                         {
  225.                             num = (num << 4) | (ch - ('a' - 10));
  226.                         }
  227.                         case 'A' .. 'F':
  228.                         {
  229.                             num = (num << 4) | (ch - ('A' - 10));
  230.                         }
  231.                         default:
  232.                         {
  233.                             return -1;
  234.                         }
  235.                     }
  236.                 }
  237.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  238.                 setarg(paramPos, 0, num);
  239.             }
  240.             case 'c':
  241.             {
  242.                 setarg(paramPos, 0, string[stringPos++]);
  243.             }
  244.             case 'f':
  245.             {
  246.  
  247.                 new changestr[16], changepos = 0, strpos = stringPos;
  248.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  249.                 {
  250.                     changestr[changepos++] = string[strpos++];
  251.                     }
  252.                 changestr[changepos] = '\0';
  253.                 setarg(paramPos,0,_:floatstr(changestr));
  254.             }
  255.             case 'p':
  256.             {
  257.                 delim = format[formatPos++];
  258.                 continue;
  259.             }
  260.             case '\'':
  261.             {
  262.                 new
  263.                     end = formatPos - 1,
  264.                     ch;
  265.                 while ((ch = format[++end]) && ch != '\'') {}
  266.                 if (!ch)
  267.                 {
  268.                     return -1;
  269.                 }
  270.                 format[end] = '\0';
  271.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  272.                 {
  273.                     if (format[end + 1])
  274.                     {
  275.                         return -1;
  276.                     }
  277.                     return 0;
  278.                 }
  279.                 format[end] = '\'';
  280.                 stringPos = ch + (end - formatPos);
  281.                 formatPos = end + 1;
  282.             }
  283.             case 'u':
  284.             {
  285.                 new
  286.                     end = stringPos - 1,
  287.                     id = 0,
  288.                     bool:num = true,
  289.                     ch;
  290.                 while ((ch = string[++end]) && ch != delim)
  291.                 {
  292.                     if (num)
  293.                     {
  294.                         if ('0' <= ch <= '9')
  295.                         {
  296.                             id = (id * 10) + (ch - '0');
  297.                         }
  298.                         else
  299.                         {
  300.                             num = false;
  301.                         }
  302.                     }
  303.                 }
  304.                 if (num && IsPlayerConnected(id))
  305.                 {
  306.                     setarg(paramPos, 0, id);
  307.                 }
  308.                 else
  309.                 {
  310.                     #if !defined foreach
  311.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  312.                         #define __SSCANF_FOREACH__
  313.                     #endif
  314.                     string[end] = '\0';
  315.                     num = false;
  316.                     new
  317.                         name[MAX_PLAYER_NAME];
  318.                     id = end - stringPos;
  319.                     foreach (Player, playerid)
  320.                     {
  321.                         GetPlayerName(playerid, name, sizeof (name));
  322.                         if (!strcmp(name, string[stringPos], true, id))
  323.                         {
  324.                             setarg(paramPos, 0, playerid);
  325.                             num = true;
  326.                             break;
  327.                         }
  328.                     }
  329.                     if (!num)
  330.                     {
  331.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  332.                     }
  333.                     string[end] = ch;
  334.                     #if defined __SSCANF_FOREACH__
  335.                         #undef foreach
  336.                         #undef __SSCANF_FOREACH__
  337.                     #endif
  338.                 }
  339.                 stringPos = end;
  340.             }
  341.             case 's', 'z':
  342.             {
  343.                 new
  344.                     i = 0,
  345.                     ch;
  346.                 if (format[formatPos])
  347.                 {
  348.                     while ((ch = string[stringPos++]) && ch != delim)
  349.                     {
  350.                         setarg(paramPos, i++, ch);
  351.                     }
  352.                     if (!i)
  353.                     {
  354.                         return -1;
  355.                     }
  356.                 }
  357.                 else
  358.                 {
  359.                     while ((ch = string[stringPos++]))
  360.                     {
  361.                         setarg(paramPos, i++, ch);
  362.                     }
  363.                 }
  364.                 stringPos--;
  365.                 setarg(paramPos, i, '\0');
  366.             }
  367.             default:
  368.             {
  369.                 continue;
  370.             }
  371.         }
  372.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  373.         {
  374.             stringPos++;
  375.         }
  376.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  377.         {
  378.             stringPos++;
  379.         }
  380.         paramPos++;
  381.     }
  382.     do
  383.     {
  384.         if ((delim = format[formatPos++]) > ' ')
  385.         {
  386.             if (delim == '\'')
  387.             {
  388.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  389.             }
  390.             else if (delim != 'z')
  391.             {
  392.                 return delim;
  393.             }
  394.         }
  395.     }
  396.     while (delim > ' ');
  397.     return 0;
  398. }
Advertisement
Add Comment
Please, Sign In to add comment