Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- // Colors
- #define yellow 0xFFFF00FF
- #define red 0xFF0000FF
- #define green 0x008000FF
- // Dialogs
- #define FIRSTSAVE_DIAGID 1
- #define SECONDSAVE_DIAGID 2
- #define SAVEFILE_DIAGID 3
- // Global Variables
- new
- Saves[MAX_PLAYERS], // Type: Integer - Description: The amount of saves that a player does
- Float:SavedX[MAX_PLAYERS], // Type: Float - Description: The X co-ordinates that a player saves
- Float:SavedY[MAX_PLAYERS], // Type: Float - Description: The Y co-ordinates that a player saves
- Float:SavedZ[MAX_PLAYERS], // Type: Float - Description: The Z co-ordinates that a player saves
- Float:XVal[MAX_PLAYERS][2], // Type: Float - Description: The min/max values of a X co-ordinate
- Float:YVal[MAX_PLAYERS][2], // Type: Float - Description: The min/max values of a Y co-ordinate
- Float:ZVal[MAX_PLAYERS][2] // Type: Float - Description: The min/max values of a Z co-ordinate
- ;
- // Functions
- 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)
- {
- if(firstX > secondX)
- {
- minX = secondX;
- maxX = firstX;
- }
- else
- {
- minX = firstX;
- maxX = secondX;
- }
- if(firstY > secondY)
- {
- minY = secondY;
- maxY = firstY;
- }
- else
- {
- minY = firstY;
- maxY = secondY;
- }
- if(firstZ > secondZ)
- {
- minZ = secondZ;
- maxZ = firstZ;
- }
- else
- {
- minZ = firstZ;
- maxZ = secondZ;
- }
- }
- stock ResetPlayerVars(playerid)
- {
- Saves[playerid] = 0;
- SavedX[playerid] = 0;
- SavedY[playerid] = 0;
- SavedZ[playerid] = 0;
- XVal[playerid][0] = 0;
- YVal[playerid][0] = 0;
- ZVal[playerid][0] = 0;
- XVal[playerid][1] = 0;
- YVal[playerid][1] = 0;
- ZVal[playerid][1] = 0;
- return 1;
- }
- stock SaveFile(filename[], infofromplayerid)
- {
- new str[128], fileStr[64], File:file;
- format(fileStr, sizeof(fileStr), "%s.txt", filename);
- file = fopen(fileStr, io_write);
- format(str, sizeof(str),"These codes were generated using Co-ordinates Generator by HellSphinX\r\n\r\n");
- fwrite(file, str);
- format(str, sizeof(str), "Min X: %f\r\n", XVal[infofromplayerid][0]);
- fwrite(file, str);
- format(str, sizeof(str), "Min Y: %f\r\n", YVal[infofromplayerid][0]);
- fwrite(file, str);
- format(str, sizeof(str), "Min Z: %f\r\n\r\n", ZVal[infofromplayerid][0]);
- fwrite(file, str);
- format(str, sizeof(str), "Max X: %f\r\n", XVal[infofromplayerid][1]);
- fwrite(file, str);
- format(str, sizeof(str), "Max Y: %f\r\n", YVal[infofromplayerid][1]);
- fwrite(file, str);
- format(str, sizeof(str), "Max Z: %f\r\n\r\n\r\n", ZVal[infofromplayerid][1]);
- fwrite(file, str);
- format(str, sizeof(str), "Thanks for using this script! Hopefully it helped you!");
- fwrite(file, str);
- fclose(file);
- return 1;
- }
- // Callbacks
- public OnFilterScriptInit()
- {
- print(" \nMaximum/Minimum Co-ordinates Generator by HellSphinX - Status: Loaded! \n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print(" \nMaximum/Minimum Co-ordinates Generator by HellSphinX - Status: Unloaded! \n");
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/savepos", cmdtext, true) == 0)
- {
- if(!IsPlayerAdmin(playerid))
- {
- SendClientMessage(playerid, red, "Error: You need to be logged as RCON Admin to use this command!");
- return 1;
- }
- if(Saves[playerid] > 0)
- {
- new str[256], Float:pos[3];
- GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
- if(pos[0] == SavedX[playerid] && pos[1] == SavedY[playerid] && pos[2] == SavedZ[playerid])
- {
- SendClientMessage(playerid, red, "Error: You did not move from the first position! Co-ordinates cannot be generated!");
- return 1;
- }
- 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]);
- 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.",
- XVal[playerid][0], YVal[playerid][0], ZVal[playerid][0],
- XVal[playerid][1], YVal[playerid][1], ZVal[playerid][1]);
- ShowPlayerDialog(playerid, SECONDSAVE_DIAGID, DIALOG_STYLE_MSGBOX, "Second position saved", str, "Save", "Cancel");
- return 1;
- }
- else
- {
- new str[256], Float:pos[3];
- GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
- format(str, sizeof(str),
- "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!",
- pos[0], pos[1], pos[2]);
- SavedX[playerid] = pos[0];
- SavedY[playerid] = pos[1];
- SavedZ[playerid] = pos[2];
- Saves[playerid] = 1;
- ShowPlayerDialog(playerid, FIRSTSAVE_DIAGID, DIALOG_STYLE_MSGBOX, "First position saved", str, "Continue", "Cancel");
- }
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case FIRSTSAVE_DIAGID:
- {
- if(response)
- {
- SendClientMessage(playerid, yellow, "All right! Move to your second position then type /savepos!");
- }
- else
- {
- SendClientMessage(playerid, green, "Everything has been reset! You can now start saving a new position!");
- ResetPlayerVars(playerid);
- }
- return 1;
- }
- case SECONDSAVE_DIAGID:
- {
- if(response)
- {
- 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");
- }
- else
- {
- SendClientMessage(playerid, yellow, "Everything is ready for a new use!");
- ResetPlayerVars(playerid);
- }
- return 1;
- }
- case SAVEFILE_DIAGID:
- {
- if(response)
- {
- new str[128];
- SaveFile(inputtext, playerid);
- format(str, sizeof(str), "A file has been saved successfully with the name %s! You can find it in your scriptfiles folder!", inputtext);
- SendClientMessage(playerid, green, str);
- SendClientMessage(playerid, yellow, "Everything is ready for a new use!");
- ResetPlayerVars(playerid);
- }
- else
- {
- SendClientMessage(playerid, yellow, "Everything is ready for a new use!");
- ResetPlayerVars(playerid);
- }
- return 1;
- }
- default:
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement