Guest User

IsPlayerInArea Maker

a guest
Jan 6th, 2015
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.11 KB | None | 0 0
  1. #include    <a_samp>
  2. #include    <YSI\y_commands>
  3.  
  4. #define     DIALOG_IPIA_MAKER    (204)
  5. #define     DIALOG_IPIA_SAVE     (205)
  6.  
  7. enum
  8.     aInfo
  9. {
  10.     Float:aMin_X,
  11.     Float:aMin_Y,
  12.     Float:aMax_X,
  13.     Float:aMax_Y,
  14.     bool:UsedSaveOne,
  15.     bool:UsedSaveTwo
  16. };
  17.  
  18. new AreaInfo[MAX_PLAYERS][aInfo];
  19.  
  20. YCMD:area(playerid, params[], help)
  21. {
  22.     #pragma unused params, help
  23.     return ShowPlayerDialog(playerid, DIALOG_IPIA_MAKER, DIALOG_STYLE_LIST, "IsPlayerInArea Maker", "Save the first point\nSave the second point\n{F58282}Create IsPlayerInArea\nReset All points, and Save Again", "Select", "Cancel"), 1;
  24. }
  25.  
  26. public OnPlayerDisconnect(playerid, reason)
  27. {
  28.     if(AreaInfo[playerid][UsedSaveOne] || AreaInfo[playerid][UsedSaveTwo] || AreaInfo[playerid][UsedSaveOne] != AreaInfo[playerid][UsedSaveTwo])
  29.     {
  30.         AreaInfo[playerid][aMin_X] = 0.0;
  31.         AreaInfo[playerid][aMin_Y] = 0.0;
  32.         AreaInfo[playerid][aMax_X] = 0.0;
  33.         AreaInfo[playerid][aMax_Y] = 0.0;
  34.         AreaInfo[playerid][UsedSaveOne] = false;
  35.         AreaInfo[playerid][UsedSaveTwo] = false;
  36.     }
  37.     return 1;
  38. }
  39.  
  40. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  41. {
  42.     switch (dialogid)
  43.     {
  44.         case DIALOG_IPIA_MAKER:
  45.         {
  46.             if(!response) return 0;
  47.             switch(listitem)
  48.             {
  49.                 case 0:
  50.                 {
  51.                     if(AreaInfo[playerid][UsedSaveOne]) return SendClientMessage(playerid, 0xFF0000FF, "This points alredy exist!"), 0;
  52.                     new Float:X,Float:Y,Float:Z;
  53.                     GetPlayerPos(playerid, X, Y, Z);
  54.                     AreaInfo[playerid][aMin_X] = X;
  55.                     AreaInfo[playerid][aMin_Y] = Y;
  56.                     AreaInfo[playerid][UsedSaveOne] = true;
  57.                     SendClientMessage(playerid, 0xCC9900FF, "Minimum X and Y created.");
  58.                 }
  59.                 case 1:
  60.                 {
  61.                     if(AreaInfo[playerid][UsedSaveTwo]) return SendClientMessage(playerid, 0xFF0000FF, "This points alredy exist!"), 0;
  62.                     new Float:X,Float:Y,Float:Z;
  63.                     GetPlayerPos(playerid, X, Y, Z);
  64.                     AreaInfo[playerid][aMax_X] = X;
  65.                     AreaInfo[playerid][aMax_Y] = Y;
  66.                     AreaInfo[playerid][UsedSaveTwo] = true;
  67.                     SendClientMessage(playerid, 0xCC9900FF, "Maximum X and Y created.");
  68.                 }
  69.                 case 2: ShowPlayerDialog(playerid, DIALOG_IPIA_SAVE, DIALOG_STYLE_INPUT, " ", "{F58282}Type the file name inside the box", "Save", "Cancel");
  70.                 default:
  71.                 {
  72.                     if(AreaInfo[playerid][UsedSaveOne] || AreaInfo[playerid][UsedSaveTwo] || AreaInfo[playerid][UsedSaveOne] != AreaInfo[playerid][UsedSaveTwo])
  73.                     {
  74.                         AreaInfo[playerid][aMin_X] = 0.0;
  75.                         AreaInfo[playerid][aMin_Y] = 0.0;
  76.                         AreaInfo[playerid][aMax_X] = 0.0;
  77.                         AreaInfo[playerid][aMax_Y] = 0.0;
  78.                         AreaInfo[playerid][UsedSaveOne] = false;
  79.                         AreaInfo[playerid][UsedSaveTwo] = false;
  80.                         SendClientMessage(playerid, 0xCC9900FF, "The points has reseted successfully!");
  81.                     }
  82.                     else SendClientMessage(playerid, 0xFF0000FF, "you cannot reset the point until you save some point!");
  83.                 }
  84.             }
  85.         }
  86.         case DIALOG_IPIA_SAVE:
  87.         {
  88.             if(!response) return ShowPlayerDialog(playerid, DIALOG_IPIA_MAKER, DIALOG_STYLE_LIST, "IsPlayerInArea Maker", "Save the first point\nSave the second point\n{F58282}Create IsPlayerInArea\nReset All points, and Save Again", "Select", "Cancel"), 1;
  89.             if(AreaInfo[playerid][UsedSaveOne] && AreaInfo[playerid][UsedSaveTwo])
  90.             {
  91.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_IPIA_SAVE, DIALOG_STYLE_INPUT, " ", "{F58282}Type the file name inside the box", "Save", "Cancel");
  92.                 new string[128];
  93.                 new filename[64];
  94.                 format(filename, sizeof(filename), "IsPlayerInArea_%s.ini", inputtext);
  95.                 format(string, sizeof(string), "IsPlayerInArea(playerid, %f, %f, %f, %f);\r\n",
  96.                     (AreaInfo[playerid][aMin_X] < AreaInfo[playerid][aMax_X]) ? AreaInfo[playerid][aMin_X] : AreaInfo[playerid][aMax_X],
  97.                     (AreaInfo[playerid][aMin_Y] < AreaInfo[playerid][aMax_Y]) ? AreaInfo[playerid][aMin_Y] : AreaInfo[playerid][aMax_Y],
  98.                     (AreaInfo[playerid][aMin_X] > AreaInfo[playerid][aMax_X]) ? AreaInfo[playerid][aMin_X] : AreaInfo[playerid][aMax_X],
  99.                     (AreaInfo[playerid][aMin_Y] > AreaInfo[playerid][aMax_Y]) ? AreaInfo[playerid][aMin_Y] : AreaInfo[playerid][aMax_Y]
  100.                 );
  101.                 new File:pos=fopen(filename, io_append);
  102.                 fwrite(pos, string);
  103.                 fclose(pos);
  104.                 new dialogstring[128];
  105.                 format(dialogstring, sizeof(dialogstring), "\nIsPlayerInArea saved under the name {F58282}IsPlayerInArea_%s.ini {a9c4e4}inside the scriptfiles folder!\n", inputtext);
  106.                 ShowPlayerDialog(playerid, 206, DIALOG_STYLE_MSGBOX, " ", dialogstring, "Exit", "");
  107.                 AreaInfo[playerid][aMin_X] = 0.0;
  108.                 AreaInfo[playerid][aMin_Y] = 0.0;
  109.                 AreaInfo[playerid][aMax_X] = 0.0;
  110.                 AreaInfo[playerid][aMax_Y] = 0.0;
  111.                 AreaInfo[playerid][UsedSaveOne] = false;
  112.                 AreaInfo[playerid][UsedSaveTwo] = false;
  113.             }
  114.             else SendClientMessage(playerid, 0xFF0000FF, "You have to save two points!");
  115.         }
  116.     }
  117.     return 1;
  118. }
  119.  
  120. IsPlayerInArea(playerid, Float:MinX, Float:MinY, Float:MaxX, Float:MaxY)
  121. {
  122.     new Float:x, Float:Y, Float:Z;
  123.     GetPlayerPos(playerid, X, Y, Z);
  124.     return (X >= MinX && X <= MaxX && Y >= MinY && Y <= MaxY) ? 1 : 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment