Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI\y_ini>
- #define COLOR_GREEN 0x6BC61AFF
- #define COLOR_RED 0xFF0000FF
- #define COLOR_YELLOW 0xFBE800FF
- #define COLOR_ORANGE 0xFF8000FF
- #define COLOR_BLUE 0x28A4FFFF
- #define COLOR_WHITE 0xFFFFFFFF
- #define COLOR_BLACK 0x000000FF
- #define COLOR_MINT 0x88ECDDFF
- #define COLOR_PINK 0xC77CF3FF
- #define COLOR_PURPLE 0x8D0691FF
- #define COLOR_OLIVE 0x808000FF
- #define COLOR_BROWN 0x9B0000FF
- #define COLOR_GREY 0x7C7C7CFF
- #define COLOR_ORANGE_BRIGHT 0xF3CE76FF
- #define MSG_GREEN "{6BC61A}"
- #define MSG_RED "{FF0000}"
- #define MSG_YELLOW "{FBE800}"
- #define MSG_ORANGE "{FF8000}"
- #define MSG_BLUE "{28A4FF}"
- #define MSG_WHITE "{FFFFFF}"
- #define MSG_BLACK "{000000}"
- #define MSG_MINT "{88ECDD}"
- #define MSG_PINK "{C77CF3}"
- #define MSG_PURPLE "{8D0691}"
- #define MSG_OLIVE "{808000}"
- #define MSG_BROWN "{9B0000}"
- #define MSG_GREY "{7C7C7C}"
- #define MSG_ORANGE_BRIGHT "{F3CE76}"
- #define MAX_SAVED_POSITIONS_PER_PLAYER 15
- #define NULL_POS_STRING "No saved position yet! Use /spos to save a position."
- #define MAX_SAVE_POSITION_NAME_LENGTH 16
- #define MIN_SAVE_POSITION_NAME_LENGTH 2
- #define SAVE_PATH "/PlayerPositions/%s.txt"
- enum {
- DIALOG_MAIN,
- DIALOG_NAME,
- DIALOG_NAMEUSED,
- DIALOG_REMOVE
- }
- new pos_COUNTER[MAX_PLAYERS];
- new pos_NAME[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER][MAX_SAVE_POSITION_NAME_LENGTH ];
- new Float:pos_ACTUAL[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER][4];
- new pos_Handler[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER];
- new pos_INT[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER];
- new pos_VW[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER];
- new tmp2[MAX_PLAYERS];
- new main_string[128 + MAX_SAVE_POSITION_NAME_LENGTH + 2 + 10];
- new main_dialog_string[MAX_PLAYERS][1024];
- GetSlot(playerid)
- {
- new s;
- for(new i = 0; i < MAX_SAVED_POSITIONS_PER_PLAYER; i++)
- {
- if(pos_Handler[playerid][i] ==0) {
- s = i;
- break;
- }
- }
- return s;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp(cmdtext, "/spos") || !strcmp(cmdtext, "/sp"))
- {
- if(pos_COUNTER[playerid] < MAX_SAVED_POSITIONS_PER_PLAYER)
- {
- pos_COUNTER[playerid]++;
- tmp2[playerid] = GetSlot(playerid);
- pos_Handler[playerid][tmp2[playerid]] = 1;
- ShowPlayerDialog(playerid, DIALOG_NAME, DIALOG_STYLE_INPUT, ""MSG_MINT"~Name your position~", "Give a name to your current position", "Save", "Cancel");
- return 1;
- }
- else return SendClientMessage(playerid, COLOR_RED, "ERROR: "MSG_GREY"You've got the maximal amount of saved spots used! Use /rpos to remove a position.");
- }
- if(!strcmp(cmdtext, "/lpos") || !strcmp(cmdtext, "/lp"))
- {
- for(new k = 0; k < MAX_SAVED_POSITIONS_PER_PLAYER; k++)
- {
- if(pos_Handler[playerid][k] != 0) {
- format(main_dialog_string[playerid],1024, "%s\n%d. %s",main_dialog_string[playerid], k, pos_NAME[playerid][k]);
- }
- else format(main_dialog_string[playerid], 1024, "%s\n%d."MSG_RED" "NULL_POS_STRING"", main_dialog_string[playerid], k);
- }
- ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, ""MSG_MINT"~Load a position~", main_dialog_string[playerid], "Load", "Cancel");
- format(main_dialog_string[playerid],1024, "");
- return 1;
- }
- if(!strcmp(cmdtext, "/rpos"))
- {
- for(new k = 0; k < MAX_SAVED_POSITIONS_PER_PLAYER; k++)
- {
- if(pos_Handler[playerid][k] != 0) {
- format(main_dialog_string[playerid],1024, "%s\n%d. %s",main_dialog_string[playerid], k, pos_NAME[playerid][k]);
- }
- else format(main_dialog_string[playerid], 1024, "%s\n%d."MSG_RED" "NULL_POS_STRING"", main_dialog_string[playerid], k);
- }
- ShowPlayerDialog(playerid, DIALOG_REMOVE, DIALOG_STYLE_LIST, ""MSG_MINT"~Remove a position~", main_dialog_string[playerid], "Remove", "Cancel");
- format(main_dialog_string[playerid],1024, "");
- return 1;
- }
- return 0;
- }
- public OnPlayerConnect(playerid)
- {
- if(fexist(PlayerPath(playerid))) INI_ParseFile(PlayerPath(playerid), "LoadPlayerPos_%s", .bExtra = true, .extra = playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- for(new i = 0; i < MAX_SAVED_POSITIONS_PER_PLAYER; i++)
- {
- pos_ACTUAL[playerid][i][0] = 0;
- pos_ACTUAL[playerid][i][1] = 0;
- pos_ACTUAL[playerid][i][2] = 0;
- pos_ACTUAL[playerid][i][3] = 0;
- pos_COUNTER[playerid] = 0;
- pos_INT[playerid][i] = 0;
- pos_VW[playerid][i] = 0;
- format(pos_NAME[playerid][i], MAX_SAVE_POSITION_NAME_LENGTH, "");
- pos_Handler[playerid][i] = 0;
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_NAME)
- {
- if(!response)
- {
- pos_Handler[playerid][tmp2[playerid]] = 0;
- tmp2[playerid] = 0;
- pos_COUNTER[playerid]--;
- SendClientMessage(playerid, COLOR_GREY, "FAILURE: "MSG_YELLOW"Cancelled position saving.");
- }
- else
- {
- if(MIN_SAVE_POSITION_NAME_LENGTH <= strlen(inputtext) <= MAX_SAVE_POSITION_NAME_LENGTH) {
- new Float: x, Float:y, Float:z, Float:a, str_tmp[21];
- GetPlayerPos(playerid, x, y, z);
- GetPlayerFacingAngle(playerid, a);
- pos_ACTUAL[playerid][tmp2[playerid]][0] = x;
- pos_ACTUAL[playerid][tmp2[playerid]][1] = y;
- pos_ACTUAL[playerid][tmp2[playerid]][2] = z;
- pos_ACTUAL[playerid][tmp2[playerid]][3] = a;
- pos_INT[playerid][tmp2[playerid]] = GetPlayerInterior(playerid);
- pos_VW[playerid][tmp2[playerid]] = GetPlayerVirtualWorld(playerid);
- format(pos_NAME[playerid][tmp2[playerid]], MAX_SAVE_POSITION_NAME_LENGTH, "%s", inputtext);
- format(main_string, sizeof(main_string), "SUCCESS: "MSG_YELLOW"Saved position as \"%s\"(%d). /lpos to come back here! /rpos to remove it!", pos_NAME[playerid][tmp2[playerid]], tmp2[playerid]);
- SendClientMessage(playerid, COLOR_GREY, main_string);
- new INI:File = INI_Open(PlayerPath(playerid));
- INI_SetTag(File, "data");
- format(str_tmp, sizeof(str_tmp), "X_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][0]);
- format(str_tmp, sizeof(str_tmp), "Y_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][1]);
- format(str_tmp, sizeof(str_tmp), "Z_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][2]);
- format(str_tmp, sizeof(str_tmp), "A_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][3]);
- format(str_tmp, sizeof(str_tmp), "Counter_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_COUNTER[playerid]);
- format(str_tmp, sizeof(str_tmp), "Interior_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
- format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
- format(str_tmp, sizeof(str_tmp), "Name_%d", tmp2[playerid]);
- INI_WriteString(File, str_tmp, pos_NAME[playerid][tmp2[playerid]]);
- format(str_tmp, sizeof(str_tmp), "Handler_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_Handler[playerid][tmp2[playerid]]);
- INI_Close(File);
- }
- else {
- format(main_string, sizeof(main_string), "Give a name to your current position.\n\n"MSG_RED"ERROR: Valid name lengths are between %d and %d!", MIN_SAVE_POSITION_NAME_LENGTH, MAX_SAVE_POSITION_NAME_LENGTH);
- ShowPlayerDialog(playerid, DIALOG_NAME, DIALOG_STYLE_INPUT, ""MSG_MINT"~Name your position~", main_string, "Save", "Cancel");
- }
- }
- return 1;
- }
- if(dialogid == DIALOG_REMOVE)
- {
- if(!response)
- {
- SendClientMessage(playerid, COLOR_GREY, "CANCELED: "MSG_YELLOW"Cancelled position deletion.");
- }
- else
- {
- new str_tmp[21];
- tmp2[playerid] = listitem;
- pos_ACTUAL[playerid][tmp2[playerid]][0] = 0;
- pos_ACTUAL[playerid][tmp2[playerid]][1] = 0;
- pos_ACTUAL[playerid][tmp2[playerid]][2] = 0;
- pos_ACTUAL[playerid][tmp2[playerid]][3] = 0;
- pos_INT[playerid][tmp2[playerid]] = 0;
- pos_VW[playerid][tmp2[playerid]] = 0;
- format(pos_NAME[playerid][tmp2[playerid]], MAX_SAVE_POSITION_NAME_LENGTH, "");
- pos_Handler[playerid][tmp2[playerid]] = 0;
- new INI:File = INI_Open(PlayerPath(playerid));
- INI_SetTag(File, "data");
- format(str_tmp, sizeof(str_tmp), "X_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][0]);
- format(str_tmp, sizeof(str_tmp), "Y_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][1]);
- format(str_tmp, sizeof(str_tmp), "Z_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][2]);
- format(str_tmp, sizeof(str_tmp), "A_%d", tmp2[playerid]);
- INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][3]);
- format(str_tmp, sizeof(str_tmp), "Counter_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_COUNTER[playerid]);
- format(str_tmp, sizeof(str_tmp), "Interior_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
- format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
- format(str_tmp, sizeof(str_tmp), "Name_%d", tmp2[playerid]);
- INI_WriteString(File, str_tmp, pos_NAME[playerid][tmp2[playerid]]);
- format(str_tmp, sizeof(str_tmp), "Handler_%d", tmp2[playerid]);
- INI_WriteInt(File, str_tmp, pos_Handler[playerid][tmp2[playerid]]);
- INI_Close(File);
- tmp2[playerid] = 0;
- }
- return 1;
- }
- if(dialogid == DIALOG_MAIN)
- {
- if(response)
- {
- if(pos_Handler[playerid][listitem] != 0) {
- SetPlayerPosEx(playerid, pos_ACTUAL[playerid][listitem][0], pos_ACTUAL[playerid][listitem][1], pos_ACTUAL[playerid][listitem][2], pos_INT[playerid][listitem], pos_VW[playerid][listitem], pos_ACTUAL[playerid][listitem][3]);
- format(main_string, 128 + MAX_SAVE_POSITION_NAME_LENGTH + 2 + 10, "SUCCESS: "MSG_YELLOW"Teleported to: \"%s\"(%d)", pos_NAME[playerid][listitem], listitem);
- SendClientMessage(playerid, COLOR_GREY, main_string); }
- else return SendClientMessage(playerid, COLOR_GREY, "ERROR: "MSG_YELLOW"You haven't saved this position slot yet!");
- }
- return 1;
- }
- return 0;
- }
- stock SetPlayerPosEx(playerid, Float: x, Float: y, Float: z, Inte, VW, Float: a)
- {
- if(!IsPlayerInAnyVehicle(playerid)) return SetPlayerPos(playerid, x, y, z), SetPlayerInterior(playerid, Inte), SetPlayerVirtualWorld(playerid, VW), SetPlayerFacingAngle(playerid, a);
- else return SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z), SetVehicleZAngle(GetPlayerVehicleID(playerid), a), SetVehicleVirtualWorld(GetPlayerVehicleID(playerid), VW), LinkVehicleToInterior(GetPlayerVehicleID(playerid), Inte);
- }
- forward LoadPlayerPos_data(playerid,name[],value[]);
- public LoadPlayerPos_data(playerid,name[],value[])
- {
- new str_tmp[21];
- for(new i = 0; i < MAX_SAVED_POSITIONS_PER_PLAYER; i++)
- {
- format(str_tmp, sizeof(str_tmp), "X_%d", i);
- INI_Float(str_tmp, pos_ACTUAL[playerid][i][0]);
- format(str_tmp, sizeof(str_tmp), "Y_%d", i);
- INI_Float(str_tmp, pos_ACTUAL[playerid][i][1]);
- format(str_tmp, sizeof(str_tmp), "Z_%d", i);
- INI_Float(str_tmp, pos_ACTUAL[playerid][i][2]);
- format(str_tmp, sizeof(str_tmp), "A_%d", i);
- INI_Float(str_tmp, pos_ACTUAL[playerid][i][3]);
- format(str_tmp, sizeof(str_tmp), "Counter_%d", i);
- INI_Int(str_tmp, pos_COUNTER[playerid]);
- format(str_tmp, sizeof(str_tmp), "Interior_%d", i);
- INI_Int(str_tmp, pos_INT[playerid][i]);
- format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", i);
- INI_Int(str_tmp, pos_VW[playerid][i]);
- format(str_tmp, sizeof(str_tmp), "Name_%d", i);
- INI_String(str_tmp, pos_NAME[playerid][i], MAX_SAVE_POSITION_NAME_LENGTH);
- format(str_tmp, sizeof(str_tmp), "Handler_%d", i);
- INI_Int(str_tmp, pos_Handler[playerid][i]);
- }
- return 1;
- }
- PlayerPath(playerid)
- {
- new file[128], p[MAX_PLAYER_NAME];
- GetPlayerName(playerid, p, sizeof(p));
- format(file, sizeof(file), SAVE_PATH, p);
- return file;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement