Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI\y_commands>
- #include <SII>
- #include <sscanf2>
- #define GREEN 0x21DD00FF
- #define RED 0xE60000FF
- #define ADMIN_RED 0xFB0000FF
- #define WHITE 0xFFFFFFFF
- #define ORANGE 0xF97804FF
- #define LIGHTRED 0xFF8080FF
- #define LIGHTBLUE 0x00C2ECFF
- #define PURPLE 0xB360FDFF
- #define BLUE 0x1229FAFF
- #define LIGHTGREEN 0x38FF06FF
- #define DARKPINK 0xE100E1FF
- #define DARKGREEN 0x008040FF
- #define AQUAGREEN 0x00CACAFB
- #define NICESKY 0x99FFFFAA
- #define GREY 0xCECECEFF
- #define ORANGERED 0xFF4500FF
- #define PINK 0xFFC0CBFF
- #define SAVE_POS_DIALOG 15
- #define LOAD_POS_DIALOG 16
- #define SAVE_POS_SLOT1 17
- #define SAVE_POS_SLOT2 18
- #define SAVE_POS_SLOT3 19
- new Float:SPosXS1,
- Float:SPosYS1,
- Float:SPosZS1;
- // I think i dont even need those two, but puted them just in case
- //
- new Float:SPosXS2,
- Float:SPosYS2,
- Float:SPosZS2;
- new Float:SPosXS3,
- Float:SPosYS3,
- Float:SPosZS3;
- //
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == SAVE_POS_DIALOG)
- {
- if(response == 1)
- {
- switch(listitem)
- {
- case 0: ShowPlayerDialog(playerid, SAVE_POS_SLOT1, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", " ", "Save","Cancel");
- case 1: ShowPlayerDialog(playerid, SAVE_POS_SLOT2, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", " ", "Save","Cancel");
- case 2: ShowPlayerDialog(playerid, SAVE_POS_SLOT3, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", " ", "Save","Cancel");
- }
- }
- }
- if(dialogid == SAVE_POS_SLOT1)
- {
- if(response == 1)
- {
- GetPlayerPos(playerid, SPosXS1, SPosYS1, SPosZS1);
- if(INI_Open(getINI(playerid)))
- {
- INI_WriteString("SpawnPosSlot1Name", inputtext);
- INI_WriteFloat("SpawnPosXSlot1",SPosXS1);
- INI_WriteFloat("SpawnPosYSlot1",SPosYS1);
- INI_WriteFloat("SpawnPosZSlot1",SPosZS1);
- INI_Save();
- INI_Close();
- }
- }
- }
- if(dialogid == SAVE_POS_SLOT2)
- {
- if(response == 1)
- {
- GetPlayerPos(playerid, SPosXS2, SPosYS2, SPosZS2);
- if(INI_Open(getINI(playerid)))
- {
- INI_WriteString("SpawnPosSlot2Name", inputtext);
- INI_WriteFloat("SpawnPosXSlot2",SPosXS2);
- INI_WriteFloat("SpawnPosYSlot2",SPosYS2);
- INI_WriteFloat("SpawnPosZSlot2",SPosZS2);
- INI_Save();
- INI_Close();
- }
- }
- }
- if(dialogid == SAVE_POS_SLOT3)
- {
- if(response == 1)
- {
- GetPlayerPos(playerid, SPosXS3, SPosYS3, SPosZS3);
- if(INI_Open(getINI(playerid)))
- {
- INI_WriteString("SpawnPosSlot3Name", inputtext);
- INI_WriteFloat("SpawnPosXSlot3",SPosXS3);
- INI_WriteFloat("SpawnPosYSlot3",SPosYS3);
- INI_WriteFloat("SpawnPosZSlot3",SPosZS3);
- INI_Save();
- INI_Close();
- }
- }
- }
- // The loading slot dialog:
- if(dialogid == LOAD_POS_DIALOG)
- {
- // Run this code if the user pressed 'load'
- if(response)
- {
- // Open the file again
- if(INI_Open(getINI(playerid)))
- {
- // Declare some variables to store the coordinates in.
- new
- Float:x,
- Float:y,
- Float:z;
- // Run a different code block depending on the listitem:
- switch(listitem)
- {
- case 0:
- {
- x = INI_ReadFloat("SpawnPosXSlot1");
- y = INI_ReadFloat("SpawnPosYSlot1");
- z = INI_ReadFloat("SpawnPosZSlot1");
- }
- case 1:
- {
- x = INI_ReadFloat("SpawnPosXSlot2");
- y = INI_ReadFloat("SpawnPosYSlot2");
- z = INI_ReadFloat("SpawnPosZSlot2");
- }
- case 2:
- {
- x = INI_ReadFloat("SpawnPosXSlot3");
- y = INI_ReadFloat("SpawnPosYSlot3");
- z = INI_ReadFloat("SpawnPosZSlot3");
- }
- }
- // Perform this check to see if the loaded coordinates are valid.
- // If all the coordinates are 0.0, the slot probably doesn't exist.
- // So let the player choose a different slot.
- if(x == 0.0 && y == 0.0 && z == 0.0)
- {
- // Show the menu again so the player can choose a new slot.
- ShowPlayerSlotList(playerid);
- }
- else
- {
- // Set the player position to the stored coordinates.
- SetPlayerPos(playerid, x, y, z);
- }
- // Close the file to clear memory and allow another file to be opened in the future.
- INI_Close();
- }
- else
- {
- // INI_Open returned 0 meaning the file didn't open, warn the player or something.
- }
- }
- }
- return 0;
- }
- YCMD:spos(playerid,params[], help)
- {
- #pragma unused params
- #pragma unused help
- ShowPlayerDialog(playerid, SAVE_POS_DIALOG, DIALOG_STYLE_LIST, "{FFFFFF}Choose {00FF00}Save Slot","Slot 1\nSlot 2\nSlot 3","Save","Cancel");
- return 1;
- }
- YCMD:lpos(playerid,params[], help)
- {
- #pragma unused params
- #pragma unused help
- // Use a function to display the menu
- // This way, you can display the menu from anywhere without needing to write all the code again.
- ShowPlayerSlotList(playerid);
- return 1;
- }
- ShowPlayerSlotList(playerid)
- {
- new
- list[(128 + 1) * 3], // 128 is the max-length of the slot name, 1 is the \n character, multiply by 3 for 3 lines.
- tmp[128 + 1]; // Used to store the slot name loaded from the file.
- if(INI_Open(getINI(playerid)))
- {
- // Only run this code if INI_Open returned 1, aka the file opened successfully.
- // Read the slot name, store it to 'tmp'.
- if(INI_ReadString(tmp, "SpawnPosSlot1Name"))
- {
- // If INI_ReadString returned 1, the string was loaded.
- // Set the last character to a '\n' for the menu newline.
- tmp[strlen(tmp)] = '\n';
- // Stick it onto the end of 'list' with 'strcat'.
- strcat(list, tmp);
- }
- else
- {
- // If INI_ReadString returned 0, insert the slot number instead.
- strcat(list, "Slot 1\n");
- }
- // Same as above for the other slots:
- if(INI_ReadString(tmp, "SpawnPosSlot2Name"))
- {
- tmp[strlen(tmp)] = '\n';
- strcat(list, tmp);
- }
- else
- {
- strcat(list, "Slot 2\n");
- }
- if(INI_ReadString(tmp, "SpawnPosSlot3Name"))
- {
- tmp[strlen(tmp)] = '\n';
- strcat(list, tmp);
- }
- else
- {
- strcat(list, "Slot 3\n");
- }
- // The dialog is also under the INI_Open block so it only shows if the file opened properly.
- ShowPlayerDialog(playerid, LOAD_POS_DIALOG, DIALOG_STYLE_LIST, "{FFFFFF}Choose {00FF00}Save Slot",list,"Load","Cancel");
- // Close the file to clear memory and allow another file to be opened in the future.
- INI_Close();
- }
- else
- {
- // INI_Open returned 0 meaning the file didn't open, warn the player or something.
- }
- }
- stock getINI(playerid)
- {
- new account[64], pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof(pName));
- format(account,30,"Users/%s.ini", pName);
- return account;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement