Advertisement
Guest User

Min/Max Co-ordinates generator by HellSphinX

a guest
Jul 16th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.72 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. // Colors
  4. #define yellow 0xFFFF00FF
  5. #define red 0xFF0000FF
  6. #define green 0x008000FF
  7.  
  8. // Dialogs
  9. #define FIRSTSAVE_DIAGID 1
  10. #define SECONDSAVE_DIAGID 2
  11. #define SAVEFILE_DIAGID 3
  12.  
  13.  
  14. // Global Variables
  15. new
  16.     Saves[MAX_PLAYERS], // Type: Integer - Description: The amount of saves that a player does
  17.     Float:SavedX[MAX_PLAYERS], // Type: Float - Description: The X co-ordinates that a player saves
  18.     Float:SavedY[MAX_PLAYERS], // Type: Float - Description: The Y co-ordinates that a player saves
  19.     Float:SavedZ[MAX_PLAYERS], // Type: Float - Description: The Z co-ordinates that a player saves
  20.     Float:XVal[MAX_PLAYERS][2], // Type: Float - Description: The min/max values of a X co-ordinate
  21.     Float:YVal[MAX_PLAYERS][2], // Type: Float - Description: The min/max values of a Y co-ordinate
  22.     Float:ZVal[MAX_PLAYERS][2]  // Type: Float - Description: The min/max values of a Z co-ordinate
  23.     ;
  24.  
  25. // Functions
  26. GetMinAndMaxValuesOfCoords(Float:firstX, Float:firstY, Float:firstZ, Float:secondX, Float:secondY, Float:secondZ, &Float:minX, &Float:minY, &Float:minZ, &Float:maxX, &Float:maxY, &Float:maxZ)
  27. {
  28.     if(firstX > secondX)
  29.     {
  30.         minX = secondX;
  31.         maxX = firstX;
  32.     }
  33.     else
  34.     {
  35.         minX = firstX;
  36.         maxX = secondX;
  37.     }
  38.     if(firstY > secondY)
  39.     {
  40.         minY = secondY;
  41.         maxY = firstY;
  42.     }
  43.     else
  44.     {
  45.         minY = firstY;
  46.         maxY = secondY;
  47.     }
  48.     if(firstZ > secondZ)
  49.     {
  50.         minZ = secondZ;
  51.         maxZ = firstZ;
  52.     }
  53.     else
  54.     {
  55.         minZ = firstZ;
  56.         maxZ = secondZ;
  57.     }
  58. }
  59.  
  60. stock ResetPlayerVars(playerid)
  61. {
  62.     Saves[playerid] = 0;
  63.     SavedX[playerid] = 0;
  64.     SavedY[playerid] = 0;
  65.     SavedZ[playerid] = 0;
  66.     XVal[playerid][0] = 0;
  67.     YVal[playerid][0] = 0;
  68.     ZVal[playerid][0] = 0;
  69.     XVal[playerid][1] = 0;
  70.     YVal[playerid][1] = 0;
  71.     ZVal[playerid][1] = 0;
  72.     return 1;
  73. }
  74.  
  75. stock SaveFile(filename[], infofromplayerid)
  76. {
  77.     new str[128], fileStr[64], File:file;
  78.     format(fileStr, sizeof(fileStr), "%s.txt", filename);
  79.     file = fopen(fileStr, io_write);
  80.     format(str, sizeof(str),"These codes were generated using Co-ordinates Generator by HellSphinX\r\n\r\n");
  81.     fwrite(file, str);
  82.     format(str, sizeof(str), "Min X: %f\r\n", XVal[infofromplayerid][0]);
  83.     fwrite(file, str);
  84.     format(str, sizeof(str), "Min Y: %f\r\n", YVal[infofromplayerid][0]);
  85.     fwrite(file, str);
  86.     format(str, sizeof(str), "Min Z: %f\r\n\r\n", ZVal[infofromplayerid][0]);
  87.     fwrite(file, str);
  88.     format(str, sizeof(str), "Max X: %f\r\n", XVal[infofromplayerid][1]);
  89.     fwrite(file, str);
  90.     format(str, sizeof(str), "Max Y: %f\r\n", YVal[infofromplayerid][1]);
  91.     fwrite(file, str);
  92.     format(str, sizeof(str), "Max Z: %f\r\n\r\n\r\n", ZVal[infofromplayerid][1]);
  93.     fwrite(file, str);
  94.     format(str, sizeof(str), "Thanks for using this script! Hopefully it helped you!");
  95.     fwrite(file, str);
  96.     fclose(file);
  97.     return 1;
  98. }
  99.  
  100. // Callbacks
  101. public OnFilterScriptInit()
  102. {
  103.     print(" \nMaximum/Minimum Co-ordinates Generator by HellSphinX - Status: Loaded! \n");
  104.     return 1;
  105. }
  106.  
  107. public OnFilterScriptExit()
  108. {
  109.     print(" \nMaximum/Minimum Co-ordinates Generator by HellSphinX - Status: Unloaded! \n");
  110.     return 1;
  111. }
  112.  
  113. public OnPlayerCommandText(playerid, cmdtext[])
  114. {
  115.     if (strcmp("/savepos", cmdtext, true) == 0)
  116.     {
  117.         if(!IsPlayerAdmin(playerid))
  118.         {
  119.             SendClientMessage(playerid, red, "Error: You need to be logged as RCON Admin to use this command!");
  120.             return 1;
  121.         }
  122.         if(Saves[playerid] > 0)
  123.         {
  124.             new str[256], Float:pos[3];
  125.             GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  126.             if(pos[0] == SavedX[playerid] && pos[1] == SavedY[playerid] && pos[2] == SavedZ[playerid])
  127.             {
  128.                 SendClientMessage(playerid, red, "Error: You did not move from the first position! Co-ordinates cannot be generated!");
  129.                 return 1;
  130.             }
  131.             GetMinAndMaxValuesOfCoords(SavedX[playerid], SavedY[playerid], SavedZ[playerid], pos[0], pos[1], pos[2], XVal[playerid][0], YVal[playerid][0], ZVal[playerid][0], XVal[playerid][1], YVal[playerid][1], ZVal[playerid][1]);
  132.             format(str, sizeof(str), "Co-ordinates generated successfully!\n\nMin X: %f | Min Y: %f | Min Z: %f\nMax X: %f | Max Y: %f | Max Z: %f\n\nChoose Save to save the generated co-ordinates in a file. Cancel to cancel.",
  133.             XVal[playerid][0], YVal[playerid][0], ZVal[playerid][0],
  134.             XVal[playerid][1], YVal[playerid][1], ZVal[playerid][1]);
  135.             ShowPlayerDialog(playerid, SECONDSAVE_DIAGID, DIALOG_STYLE_MSGBOX, "Second position saved", str, "Save", "Cancel");
  136.             return 1;
  137.         }
  138.         else
  139.         {
  140.             new str[256], Float:pos[3];
  141.             GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  142.             format(str, sizeof(str),
  143.             "You have successfully saved your current position\nX: %f |  Y: %f |  Z: %f\nNow you can save a second position\n\nChoose Continue to continue. Cancel to reset everything!",
  144.             pos[0], pos[1], pos[2]);
  145.             SavedX[playerid] = pos[0];
  146.             SavedY[playerid] = pos[1];
  147.             SavedZ[playerid] = pos[2];
  148.             Saves[playerid] = 1;
  149.             ShowPlayerDialog(playerid, FIRSTSAVE_DIAGID, DIALOG_STYLE_MSGBOX, "First position saved", str, "Continue", "Cancel");
  150.         }
  151.         return 1;
  152.     }
  153.     return 0;
  154. }
  155.  
  156. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  157. {
  158.     switch(dialogid)
  159.     {
  160.         case FIRSTSAVE_DIAGID:
  161.         {
  162.             if(response)
  163.             {
  164.                 SendClientMessage(playerid, yellow, "All right! Move to your second position then type /savepos!");
  165.             }
  166.             else
  167.             {
  168.                 SendClientMessage(playerid, green, "Everything has been reset! You can now start saving a new position!");
  169.                 ResetPlayerVars(playerid);
  170.             }
  171.             return 1;
  172.         }
  173.         case SECONDSAVE_DIAGID:
  174.         {
  175.             if(response)
  176.             {
  177.                 ShowPlayerDialog(playerid, SAVEFILE_DIAGID, DIALOG_STYLE_INPUT, "Saving process...", "Enter a name for your file and click Save then you will find a text file\nwith that name in your scriptfiles folder!", "Save", "Cancel");
  178.             }
  179.             else
  180.             {
  181.                 SendClientMessage(playerid, yellow, "Everything is ready for a new use!");
  182.                 ResetPlayerVars(playerid);
  183.             }
  184.             return 1;
  185.         }
  186.         case SAVEFILE_DIAGID:
  187.         {
  188.             if(response)
  189.             {
  190.                 new str[128];
  191.                 SaveFile(inputtext, playerid);
  192.                 format(str, sizeof(str), "A file has been saved successfully with the name %s! You can find it in your scriptfiles folder!", inputtext);
  193.                 SendClientMessage(playerid, green, str);
  194.                 SendClientMessage(playerid, yellow, "Everything is ready for a new use!");
  195.                 ResetPlayerVars(playerid);
  196.             }
  197.             else
  198.             {
  199.                 SendClientMessage(playerid, yellow, "Everything is ready for a new use!");
  200.                 ResetPlayerVars(playerid);
  201.             }
  202.             return 1;
  203.         }
  204.         default:
  205.             return 1;
  206.     }
  207.     return 0;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement