Advertisement
Guest User

/cage

a guest
Sep 18th, 2010
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.02 KB | None | 0 0
  1. /* -------------------
  2. cage by Rachael
  3. ----------------------
  4. */
  5.  
  6. #include <a_samp>
  7. #include <a_players>
  8. #define COLOR_GREY              0xAFAFAFAA
  9. #define COLOR_RCON              0x3399FFAA
  10.  
  11.  
  12. enum obj { id, Float:ox, Float:oy, Float:oz, Float:xa, Float:ya, Float:za }
  13. new object_ref[10][obj] =
  14. {
  15.     { 971 , -4.374 , -0.274 , 1.674 , 0.0000 , 0.0000 , 270.0000 },
  16.     { 971 , 0.100 , 4.179 , 1.712 , 0.0000 , 0.0000 , 180.0000 },
  17.     { 971 , 0.000 , -4.724 , 1.674 , 0.0000 , 0.0000 , 0.0000 },
  18.     { 971 , 4.500 , -0.124 , 1.674 , 0.0000 , 0.0000 , 90.0000 },
  19.     { 969 , -4.428 , 4.053 , 5.139 , 270.618 , 0.0000 , 270.0000 },
  20.     { 969 , -1.428 , 4.053 , 5.139 , 270.618 , 0.0000 , 270.0000 },
  21.     { 969 , 1.396 , 4.053 , 5.139 , 270.618 , 0.0000 , 270.0000 },
  22.     { 969 , -4.428 , 4.053 , -1.76 , 270.618 , 0.0000 , 270.0000 },
  23.     { 969 , -1.428 , 4.053 , -1.76 , 270.618 , 0.0000 , 270.0000 },
  24.     { 969 , 1.396 , 4.053 , -1.76 , 270.618 , 0.0000 , 270.0000 }
  25. };
  26.  
  27. new object[120];
  28. new obj_count = 0;
  29. new cage[20][10];
  30. new cage_count= 0;
  31. enum loc { Float:cx, Float:cy, Float:cz }
  32. new cage_pos[20][loc];
  33. new astring[255];
  34.  
  35. stock strtok(const string[], &index)
  36. {
  37.     new length = strlen(string);
  38.     while ((index < length) && (string[index] <= ' '))
  39.     {
  40.         index++;
  41.     }
  42.  
  43.     new offset = index;
  44.     new result[20];
  45.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  46.     {
  47.         result[index - offset] = string[index];
  48.         index++;
  49.     }
  50.     result[index - offset] = EOS;
  51.     return result;
  52. }
  53.  
  54. stock IsNumeric(const string[])
  55. {
  56.     for(new i = 0, j = strlen(string); i < j; i++)
  57.     {
  58.         if(string[i] > '9' || string[i] < '0') return 0;
  59.     }
  60.     return 1;
  61. }
  62.  
  63. stock ReturnUser(text[], playerid = INVALID_PLAYER_ID)
  64. {
  65.     new pos = 0;
  66.     while (text[pos] < 0x21) // Strip out leading spaces
  67.     {
  68.         if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
  69.         pos++;
  70.     }
  71.     new userid = INVALID_PLAYER_ID;
  72.     if (IsNumeric(text[pos])) // Check whole passed string
  73.     {
  74.         // If they have a numeric name you have a problem (although names are checked on id failure)
  75.         userid = strval(text[pos]);
  76.         if (userid >=0 && userid < MAX_PLAYERS)
  77.         {
  78.             if(!IsPlayerConnected(userid))
  79.             {
  80.                 userid = INVALID_PLAYER_ID;
  81.             }
  82.             else
  83.             {
  84.                 return userid; // A player was found
  85.             }
  86.         }
  87.     }
  88.     // They entered [part of] a name or the id search failed (check names just incase)
  89.     new len = strlen(text[pos]);
  90.     new count = 0;
  91.     new aname[MAX_PLAYER_NAME];
  92.     for (new i = 0; i < MAX_PLAYERS; i++)
  93.     {
  94.         if (IsPlayerConnected(i))
  95.         {
  96.             GetPlayerName(i, aname, sizeof (aname));
  97.             if (strcmp(aname, text[pos], true, len) == 0) // Check segment of name
  98.             {
  99.                 if (len == strlen(aname)) // Exact match
  100.                 {
  101.                     return i; // Return the exact player on an exact match
  102.                 }
  103.                 else // Partial match
  104.                 {
  105.                     count++;
  106.                     userid = i;
  107.                 }
  108.             }
  109.         }
  110.     }
  111.     if (count != 1)
  112.     {
  113.         if (playerid != INVALID_PLAYER_ID)
  114.         {
  115.             if (count)
  116.             {
  117.                 SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow search.");
  118.             }
  119.             else
  120.             {
  121.                 SendClientMessage(playerid, 0xFF0000AA, "No matching user found.");
  122.             }
  123.         }
  124.         userid = INVALID_PLAYER_ID;
  125.     }
  126.     return userid; // INVALID_PLAYER_ID for bad return
  127. }
  128.  
  129. stock Name(playerid)  // returns player's name
  130. {
  131.     new pname[MAX_PLAYER_NAME];
  132.     GetPlayerName(playerid, pname, sizeof (pname));
  133.     return pname;
  134. }
  135.  
  136.  
  137. public OnPlayerCommandText(playerid,cmdtext[])
  138. {
  139.     if(IsPlayerAdmin(playerid))
  140.     {
  141.         new
  142.             idx,
  143.             argument[32]
  144.         ;
  145.  
  146.         argument = strtok(cmdtext,idx);
  147.  
  148.         if(!strcmp(argument,"/cage",true))
  149.         {
  150.             argument = strtok(cmdtext,idx);
  151.             if(!strlen(argument))
  152.             {
  153.                 SendClientMessage(playerid,COLOR_GREY,"USAGE: /cage [playerID/partofname|del|send|up|dn|north|south|east|west]");
  154.                 return 1;
  155.             }
  156.             new caged = ReturnUser(argument);
  157.             if(caged != INVALID_PLAYER_ID)
  158.             {
  159.                 new Float:playX, Float:playY, Float:playZ;
  160.                 GetPlayerPos(caged,playX,playY,playZ);
  161.                 cage_count++;
  162.                 cage_pos[cage_count][cx] = playX;
  163.                 cage_pos[cage_count][cy] = playY;
  164.                 cage_pos[cage_count][cz] = playZ;
  165.                 for(new i = 0; i <= 9;i++)
  166.                 {
  167.                     obj_count++;
  168.                     object[obj_count] = CreateObject(object_ref[i][id],
  169.                                                     playX+object_ref[i][ox],
  170.                                                     playY+object_ref[i][oy],
  171.                                                     playZ+object_ref[i][oz],
  172.                                                     object_ref[i][xa],
  173.                                                     object_ref[i][ya],
  174.                                                     object_ref[i][za]);
  175.                     cage[cage_count][i] = obj_count;
  176.                 }
  177.                 format(astring,sizeof(astring), "cage %d created",cage_count);
  178.                 SendClientMessage(playerid, COLOR_RCON, astring);
  179.                 return 1;
  180.             }
  181.             if(!strcmp(argument,"up",true))
  182.             {
  183.                 argument = strtok(cmdtext, idx);
  184.                 new cagenum = strval(argument);
  185.                 if(cagenum < 1 || cagenum > cage_count)
  186.                 {
  187.                     SendClientMessage(playerid,COLOR_GREY,"USAGE: /cage up [cage#] [distance]");
  188.                     return 1;
  189.                 }
  190.                 argument = strtok(cmdtext, idx);
  191.                 new Float:distance = floatstr(argument);
  192.                 if(distance <= 0)
  193.                 {
  194.                     SendClientMessage(playerid,COLOR_GREY,"invalid distance [1-1000]");
  195.                     return 1;
  196.                 }
  197.                 for(new i = 0; i <= 9;i++)
  198.                 {
  199.                     MoveObject(object[cage[cagenum][i]],
  200.                                 cage_pos[cagenum][cx]+object_ref[i][ox],
  201.                                 cage_pos[cagenum][cy]+object_ref[i][oy],
  202.                                 cage_pos[cagenum][cz]+object_ref[i][oz]+distance,
  203.                                 2.0);
  204.                 }
  205.                 cage_pos[cagenum][cz] += distance;
  206.                 new movest[128];
  207.                 format(movest,sizeof(movest),"cage %d moved up %.1fm",cagenum,distance);
  208.                 SendClientMessage(playerid,COLOR_RCON,movest);
  209.                 return 1;
  210.             }
  211.             if(!strcmp(argument,"dn",true))
  212.             {
  213.                 argument = strtok(cmdtext, idx);
  214.                 new cagenum = strval(argument);
  215.                 if(cagenum < 1 || cagenum > cage_count)
  216.                 {
  217.                     SendClientMessage(playerid,COLOR_GREY,"USAGE: /cage dn [cage#] [distance]");
  218.                     return 1;
  219.                 }
  220.                 argument = strtok(cmdtext, idx);
  221.                 new Float:distance = floatstr(argument);
  222.                 if(distance <= 0)
  223.                 {
  224.                     SendClientMessage(playerid,COLOR_GREY,"invalid distance [1-1000]");
  225.                     return 1;
  226.                 }
  227.                 for(new i = 0; i <= 9;i++)
  228.                 {
  229.                     MoveObject(object[cage[cagenum][i]],
  230.                                 cage_pos[cagenum][cx]+object_ref[i][ox],
  231.                                 cage_pos[cagenum][cy]+object_ref[i][oy],
  232.                                 cage_pos[cagenum][cz]+object_ref[i][oz]-distance,
  233.                                 2.0);
  234.                 }
  235.                 cage_pos[cagenum][cz] -= distance;
  236.                 new movest[128];
  237.                 format(movest,sizeof(movest),"cage %d moved down %.1fm",cagenum,distance);
  238.                 SendClientMessage(playerid,COLOR_RCON,movest);
  239.                 return 1;
  240.             }
  241.             if(!strcmp(argument,"north",true))
  242.             {
  243.                 argument = strtok(cmdtext, idx);
  244.                 new cagenum = strval(argument);
  245.                 if(cagenum < 1 || cagenum > cage_count)
  246.                 {
  247.                     SendClientMessage(playerid,COLOR_GREY,"USAGE: /cage north [cage#] [distance]");
  248.                     return 1;
  249.                 }
  250.                 argument = strtok(cmdtext, idx);
  251.                 new Float:distance = floatstr(argument);
  252.                 if(distance <= 0)
  253.                 {
  254.                     SendClientMessage(playerid,COLOR_GREY,"invalid distance [1-1000]");
  255.                     return 1;
  256.                 }
  257.                 for(new i = 0; i <= 9;i++)
  258.                 {
  259.                     MoveObject(object[cage[cagenum][i]],
  260.                                     cage_pos[cagenum][cx]+object_ref[i][ox],
  261.                                     cage_pos[cagenum][cy]+object_ref[i][oy]+distance,
  262.                                     cage_pos[cagenum][cz]+object_ref[i][oz],
  263.                                     2.0);
  264.                 }
  265.                 cage_pos[cagenum][cy] += distance;
  266.                 new movest[128];
  267.                 format(movest,sizeof(movest),"cage %d moved north %.1fm",cagenum,distance);
  268.                 SendClientMessage(playerid,COLOR_RCON,movest);
  269.                 return 1;
  270.             }
  271.             if(!strcmp(argument,"south",true))
  272.             {
  273.                 argument = strtok(cmdtext, idx);
  274.                 new cagenum = strval(argument);
  275.                 if(cagenum < 1 || cagenum > cage_count)
  276.                 {
  277.                     SendClientMessage(playerid,COLOR_GREY,"USAGE: /cagesouth [cage#] [distance]");
  278.                     return 1;
  279.                 }
  280.                 argument = strtok(cmdtext, idx);
  281.                 new Float:distance = floatstr(argument);
  282.                 if(distance <= 0)
  283.                 {
  284.                     SendClientMessage(playerid,COLOR_GREY,"invalid distance [1-1000]");
  285.                     return 1;
  286.                 }
  287.                 for(new i = 0; i <= 9;i++)
  288.                 {
  289.                     MoveObject(object[cage[cagenum][i]],
  290.                                     cage_pos[cagenum][cx]+object_ref[i][ox],
  291.                                     cage_pos[cagenum][cy]+object_ref[i][oy]-distance,
  292.                                     cage_pos[cagenum][cz]+object_ref[i][oz],
  293.                                     2.0);
  294.                 }
  295.                 cage_pos[cagenum][cy] -= distance;
  296.                 new movest[128];
  297.                 format(movest,sizeof(movest),"cage %d moved south %.1fm",cagenum,distance);
  298.                 SendClientMessage(playerid,COLOR_RCON,movest);
  299.                 return 1;
  300.             }
  301.             if(!strcmp(argument,"east",true))
  302.             {
  303.                 argument = strtok(cmdtext, idx);
  304.                 new cagenum = strval(argument);
  305.                 if(cagenum < 1 || cagenum > cage_count)
  306.                 {
  307.                     SendClientMessage(playerid,COLOR_GREY,"USAGE: /cage east [cage#] [distance]");
  308.                     return 1;
  309.                 }
  310.                 argument = strtok(cmdtext, idx);
  311.                 new Float:distance = floatstr(argument);
  312.                 if(distance <= 0)
  313.                 {
  314.                     SendClientMessage(playerid,COLOR_GREY,"invalid distance [1-1000]");
  315.                     return 1;
  316.                 }
  317.                 for(new i = 0; i <= 9;i++)
  318.                 {
  319.                     MoveObject(object[cage[cagenum][i]],
  320.                                     cage_pos[cagenum][cx]+object_ref[i][ox]+distance,
  321.                                     cage_pos[cagenum][cy]+object_ref[i][oy],
  322.                                     cage_pos[cagenum][cz]+object_ref[i][oz],
  323.                                     2.0);
  324.                 }
  325.                 cage_pos[cagenum][cx] += distance;
  326.                 new movest[128];
  327.                 format(movest,sizeof(movest),"cage %d moved east %.1fm",cagenum,distance);
  328.                 SendClientMessage(playerid,COLOR_RCON,movest);
  329.                 return 1;
  330.             }
  331.             if(!strcmp(argument,"west",true))
  332.             {
  333.                 argument = strtok(cmdtext, idx);
  334.                 new cagenum = strval(argument);
  335.                 if(cagenum < 1 || cagenum > cage_count)
  336.                 {
  337.                     SendClientMessage(playerid,COLOR_GREY,"USAGE: /cagewest [cage#] [distance]");
  338.                     return 1;
  339.                 }
  340.                 argument = strtok(cmdtext, idx);
  341.                 new Float:distance = floatstr(argument);
  342.                 if(distance <= 0)
  343.                 {
  344.                     SendClientMessage(playerid,COLOR_GREY,"invalid distance [1-1000]");
  345.                     return 1;
  346.                 }
  347.                 for(new i = 0; i <= 9;i++)
  348.                 {
  349.                     MoveObject(object[cage[cagenum][i]],
  350.                                     cage_pos[cagenum][cx]+object_ref[i][ox]+distance,
  351.                                     cage_pos[cagenum][cy]+object_ref[i][oy],
  352.                                     cage_pos[cagenum][cz]+object_ref[i][oz],
  353.                                     2.0);
  354.                 }
  355.                 cage_pos[cagenum][cx] -= distance;
  356.                 new movest[128];
  357.                 format(movest,sizeof(movest),"cage %d moved west %.1fm",cagenum,distance);
  358.                 SendClientMessage(playerid,COLOR_RCON,movest);
  359.                 return 1;
  360.             }
  361.             if(!strcmp(argument,"del",true))
  362.             {
  363.                 argument = strtok(cmdtext,idx);
  364.                 if(!strcmp(argument,"#all",true))
  365.                 {
  366.                     for(new i = 1; i <= cage_count;i++)
  367.                     {
  368.                         for(new j = 0; j <= 9; j++)
  369.                         {
  370.                             cage[i][j] = 0;
  371.                         }
  372.                         cage_pos[i][cx] = 0;
  373.                         cage_pos[i][cy] = 0;
  374.                         cage_pos[i][cz] = 0;
  375.                     }
  376.                     cage_count = 0;
  377.                     for(new i = 1; i <= obj_count;i++)
  378.                     {
  379.                         if(object[i])
  380.                         {
  381.                             DestroyObject(object[i]);
  382.                         }
  383.                     }
  384.                     obj_count = 0;
  385.                     SendClientMessage(playerid, COLOR_RCON, "all cages destroyed.");
  386.                     return 1;
  387.                 }
  388.                 new cage_num = strval(argument);
  389.                 if(cage_num < 1 || cage_num > cage_count)
  390.                 {
  391.                     SendClientMessage(playerid, COLOR_GREY, "USAGE: /cage del [cage num|#all]");
  392.                     return 1;
  393.                 }
  394.                 for(new i = 0; i <= 9;i++)
  395.                 {
  396.                     if(object[cage[cage_num][i]])
  397.                     {
  398.                         DestroyObject(object[cage[cage_num][i]]);
  399.                         object[cage[cage_num][i]] = 0;
  400.                         cage[cage_num][i] = 0;
  401.                     }
  402.                     cage_pos[cage_num][cx] = 0;
  403.                     cage_pos[cage_num][cy] = 0;
  404.                     cage_pos[cage_num][cz] = 0;
  405.                 }
  406.                 format(astring,sizeof(astring), "cage number %d destroyed",cage_num);
  407.                 SendClientMessage(playerid, COLOR_RCON, astring);
  408.                 return 1;
  409.             }
  410.             if(!strcmp(argument,"send",true))
  411.             {
  412.                 argument = strtok(cmdtext,idx);
  413.                 new cage_num = strval(argument);
  414.                 if(cage_num < 0 || cage_num > cage_count || cage_pos[cage_num][cx] == 0)
  415.                 {
  416.                     SendClientMessage(playerid, COLOR_GREY, "USAGE: /cagesend [cage num] [player]");
  417.                     return 1;
  418.                 }
  419.                 argument = strtok(cmdtext,idx);
  420.                 new player = ReturnUser(argument);
  421.                 if(player == INVALID_PLAYER_ID)
  422.                 {
  423.                     SendClientMessage(playerid, COLOR_GREY, "Invalid player ID.");
  424.                     return 1;
  425.                 }
  426.                 SetPlayerInterior(player,0);
  427.                 SetPlayerVirtualWorld(player,0);
  428.                 SetPlayerPos(player,cage_pos[cage_num][cx],cage_pos[cage_num][cy],cage_pos[cage_num][cz]);
  429.                 format(astring,sizeof(astring), "%s placed inside cage number %d",Name(player),cage_num);
  430.                 SendClientMessage(playerid, COLOR_RCON, astring);
  431.                 return 1;
  432.             }
  433.             SendClientMessage(playerid,COLOR_GREY,"USAGE: /cage [playerID/partofname|del|send|up|dn|north|south|east|west]");
  434.             return 1;
  435.         }
  436.         return 0;
  437.     }
  438.     return 0;
  439. }
  440.  
  441. public OnFilterScriptExit()
  442. {
  443.     for(new i = 1; i <= obj_count;i++)
  444.     {
  445.         DestroyObject(object[i]);
  446.     }
  447.     return 1;
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement