Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.14 KB | None | 0 0
  1. #include <a_samp>
  2. #include <YSI\y_ini>
  3.  
  4. #define COLOR_GREEN                     0x6BC61AFF
  5. #define COLOR_RED                       0xFF0000FF
  6. #define COLOR_YELLOW                    0xFBE800FF
  7. #define COLOR_ORANGE                    0xFF8000FF
  8. #define COLOR_BLUE                      0x28A4FFFF
  9. #define COLOR_WHITE                     0xFFFFFFFF
  10. #define COLOR_BLACK                     0x000000FF
  11. #define COLOR_MINT                      0x88ECDDFF
  12. #define COLOR_PINK                      0xC77CF3FF
  13. #define COLOR_PURPLE                    0x8D0691FF
  14. #define COLOR_OLIVE                     0x808000FF
  15. #define COLOR_BROWN                     0x9B0000FF
  16. #define COLOR_GREY                      0x7C7C7CFF
  17. #define COLOR_ORANGE_BRIGHT             0xF3CE76FF
  18.  
  19. #define MSG_GREEN                       "{6BC61A}"
  20. #define MSG_RED                         "{FF0000}"
  21. #define MSG_YELLOW                      "{FBE800}"
  22. #define MSG_ORANGE                      "{FF8000}"
  23. #define MSG_BLUE                        "{28A4FF}"
  24. #define MSG_WHITE                       "{FFFFFF}"
  25. #define MSG_BLACK                       "{000000}"
  26. #define MSG_MINT                        "{88ECDD}"
  27. #define MSG_PINK                        "{C77CF3}"
  28. #define MSG_PURPLE                      "{8D0691}"
  29. #define MSG_OLIVE                       "{808000}"
  30. #define MSG_BROWN                       "{9B0000}"
  31. #define MSG_GREY                        "{7C7C7C}"
  32. #define MSG_ORANGE_BRIGHT               "{F3CE76}"
  33.  
  34. #define MAX_SAVED_POSITIONS_PER_PLAYER  15
  35. #define NULL_POS_STRING                 "No saved position yet! Use /spos to save a position."
  36.  
  37. #define MAX_SAVE_POSITION_NAME_LENGTH   16
  38. #define MIN_SAVE_POSITION_NAME_LENGTH   2
  39.  
  40. #define SAVE_PATH                       "/PlayerPositions/%s.txt"
  41.  
  42. enum {
  43.     DIALOG_MAIN,
  44.     DIALOG_NAME,
  45.     DIALOG_NAMEUSED,
  46.     DIALOG_REMOVE
  47. }
  48.  
  49. new pos_COUNTER[MAX_PLAYERS];
  50. new pos_NAME[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER][MAX_SAVE_POSITION_NAME_LENGTH ];
  51. new Float:pos_ACTUAL[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER][4];
  52. new pos_Handler[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER];
  53. new pos_INT[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER];
  54. new pos_VW[MAX_PLAYERS][MAX_SAVED_POSITIONS_PER_PLAYER];
  55.  
  56. new tmp2[MAX_PLAYERS];
  57.  
  58. new main_string[128 + MAX_SAVE_POSITION_NAME_LENGTH + 2 + 10];
  59.  
  60. new main_dialog_string[MAX_PLAYERS][1024];
  61.  
  62. GetSlot(playerid)
  63. {
  64.     new s;
  65.     for(new i = 0; i < MAX_SAVED_POSITIONS_PER_PLAYER; i++)
  66.     {
  67.         if(pos_Handler[playerid][i] ==0) {
  68.             s = i;
  69.             break;
  70.         }
  71.     }
  72.     return s;
  73. }
  74.  
  75.    
  76. public OnPlayerCommandText(playerid, cmdtext[])
  77. {
  78.     if(!strcmp(cmdtext, "/spos") || !strcmp(cmdtext, "/sp"))
  79.     {
  80.         if(pos_COUNTER[playerid] < MAX_SAVED_POSITIONS_PER_PLAYER)
  81.         {
  82.             pos_COUNTER[playerid]++;
  83.             tmp2[playerid] = GetSlot(playerid);
  84.             pos_Handler[playerid][tmp2[playerid]] = 1;
  85.             ShowPlayerDialog(playerid, DIALOG_NAME, DIALOG_STYLE_INPUT, ""MSG_MINT"~Name your position~", "Give a name to your current position", "Save", "Cancel");
  86.             return 1;
  87.         }
  88.         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.");
  89.     }
  90.     if(!strcmp(cmdtext, "/lpos") || !strcmp(cmdtext, "/lp"))
  91.     {
  92.         for(new k = 0; k < MAX_SAVED_POSITIONS_PER_PLAYER; k++)
  93.         {
  94.             if(pos_Handler[playerid][k] != 0) {
  95.             format(main_dialog_string[playerid],1024, "%s\n%d. %s",main_dialog_string[playerid], k, pos_NAME[playerid][k]);
  96.             }
  97.             else format(main_dialog_string[playerid], 1024, "%s\n%d."MSG_RED" "NULL_POS_STRING"", main_dialog_string[playerid], k);
  98.         }
  99.         ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, ""MSG_MINT"~Load a position~", main_dialog_string[playerid], "Load", "Cancel");
  100.         format(main_dialog_string[playerid],1024, "");
  101.         return 1;
  102.     }
  103.     if(!strcmp(cmdtext, "/rpos"))
  104.     {
  105.         for(new k = 0; k < MAX_SAVED_POSITIONS_PER_PLAYER; k++)
  106.         {
  107.             if(pos_Handler[playerid][k] != 0) {
  108.             format(main_dialog_string[playerid],1024, "%s\n%d. %s",main_dialog_string[playerid], k, pos_NAME[playerid][k]);
  109.             }
  110.             else format(main_dialog_string[playerid], 1024, "%s\n%d."MSG_RED" "NULL_POS_STRING"", main_dialog_string[playerid], k);
  111.         }
  112.         ShowPlayerDialog(playerid, DIALOG_REMOVE, DIALOG_STYLE_LIST, ""MSG_MINT"~Remove a position~", main_dialog_string[playerid], "Remove", "Cancel");
  113.         format(main_dialog_string[playerid],1024, "");
  114.         return 1;
  115.     }
  116.     return 0;
  117. }
  118.  
  119.  
  120. public OnPlayerConnect(playerid)
  121. {
  122.     if(fexist(PlayerPath(playerid))) INI_ParseFile(PlayerPath(playerid), "LoadPlayerPos_%s", .bExtra = true, .extra = playerid);
  123.     return 1;
  124. }
  125.  
  126. public OnPlayerDisconnect(playerid, reason)
  127. {
  128.     for(new i = 0; i < MAX_SAVED_POSITIONS_PER_PLAYER; i++)
  129.     {
  130.         pos_ACTUAL[playerid][i][0] = 0;
  131.         pos_ACTUAL[playerid][i][1] = 0;
  132.         pos_ACTUAL[playerid][i][2] = 0;
  133.         pos_ACTUAL[playerid][i][3] = 0;
  134.         pos_COUNTER[playerid] = 0;
  135.         pos_INT[playerid][i] = 0;
  136.         pos_VW[playerid][i] = 0;
  137.         format(pos_NAME[playerid][i], MAX_SAVE_POSITION_NAME_LENGTH, "");
  138.         pos_Handler[playerid][i] = 0;
  139.     }
  140.     return 1;
  141. }
  142. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  143. {
  144.     if(dialogid == DIALOG_NAME)
  145.     {
  146.         if(!response)
  147.         {
  148.             pos_Handler[playerid][tmp2[playerid]] = 0;
  149.             tmp2[playerid] = 0;
  150.             pos_COUNTER[playerid]--;
  151.             SendClientMessage(playerid, COLOR_GREY, "FAILURE: "MSG_YELLOW"Cancelled position saving.");
  152.         }
  153.         else
  154.         {
  155.             if(MIN_SAVE_POSITION_NAME_LENGTH <= strlen(inputtext) <= MAX_SAVE_POSITION_NAME_LENGTH) {
  156.                 new Float: x, Float:y, Float:z, Float:a, str_tmp[21];
  157.                 GetPlayerPos(playerid, x, y, z);
  158.                 GetPlayerFacingAngle(playerid, a);
  159.                 pos_ACTUAL[playerid][tmp2[playerid]][0] = x;
  160.                 pos_ACTUAL[playerid][tmp2[playerid]][1] = y;
  161.                 pos_ACTUAL[playerid][tmp2[playerid]][2] = z;
  162.                 pos_ACTUAL[playerid][tmp2[playerid]][3] = a;
  163.                 pos_INT[playerid][tmp2[playerid]] = GetPlayerInterior(playerid);
  164.                 pos_VW[playerid][tmp2[playerid]] = GetPlayerVirtualWorld(playerid);
  165.                 format(pos_NAME[playerid][tmp2[playerid]], MAX_SAVE_POSITION_NAME_LENGTH, "%s", inputtext);
  166.                 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]);
  167.                 SendClientMessage(playerid, COLOR_GREY, main_string);
  168.                
  169.                 new INI:File = INI_Open(PlayerPath(playerid));
  170.                 INI_SetTag(File, "data");
  171.                 format(str_tmp, sizeof(str_tmp), "X_%d", tmp2[playerid]);
  172.                 INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][0]);
  173.                 format(str_tmp, sizeof(str_tmp), "Y_%d", tmp2[playerid]);
  174.                 INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][1]);
  175.                 format(str_tmp, sizeof(str_tmp), "Z_%d", tmp2[playerid]);
  176.                 INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][2]);
  177.                 format(str_tmp, sizeof(str_tmp), "A_%d", tmp2[playerid]);
  178.                 INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][3]);
  179.                 format(str_tmp, sizeof(str_tmp), "Counter_%d", tmp2[playerid]);
  180.                 INI_WriteInt(File, str_tmp, pos_COUNTER[playerid]);
  181.                 format(str_tmp, sizeof(str_tmp), "Interior_%d", tmp2[playerid]);
  182.                 INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
  183.                 format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", tmp2[playerid]);
  184.                 INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
  185.                 format(str_tmp, sizeof(str_tmp), "Name_%d", tmp2[playerid]);
  186.                 INI_WriteString(File, str_tmp, pos_NAME[playerid][tmp2[playerid]]);
  187.                 format(str_tmp, sizeof(str_tmp), "Handler_%d", tmp2[playerid]);
  188.                 INI_WriteInt(File, str_tmp, pos_Handler[playerid][tmp2[playerid]]);
  189.                 INI_Close(File);
  190.             }
  191.             else {
  192.                 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);
  193.                 ShowPlayerDialog(playerid, DIALOG_NAME, DIALOG_STYLE_INPUT, ""MSG_MINT"~Name your position~", main_string, "Save", "Cancel");
  194.             }
  195.         }
  196.         return 1;
  197.     }
  198.     if(dialogid == DIALOG_REMOVE)
  199.     {
  200.         if(!response)
  201.         {
  202.             SendClientMessage(playerid, COLOR_GREY, "CANCELED: "MSG_YELLOW"Cancelled position deletion.");
  203.         }
  204.         else
  205.         {
  206.             new str_tmp[21];
  207.             tmp2[playerid] = listitem;
  208.             pos_ACTUAL[playerid][tmp2[playerid]][0] = 0;
  209.             pos_ACTUAL[playerid][tmp2[playerid]][1] = 0;
  210.             pos_ACTUAL[playerid][tmp2[playerid]][2] = 0;
  211.             pos_ACTUAL[playerid][tmp2[playerid]][3] = 0;
  212.             pos_INT[playerid][tmp2[playerid]] = 0;
  213.             pos_VW[playerid][tmp2[playerid]] = 0;
  214.             format(pos_NAME[playerid][tmp2[playerid]], MAX_SAVE_POSITION_NAME_LENGTH, "");
  215.             pos_Handler[playerid][tmp2[playerid]] = 0;
  216.            
  217.             new INI:File = INI_Open(PlayerPath(playerid));
  218.             INI_SetTag(File, "data");
  219.             format(str_tmp, sizeof(str_tmp), "X_%d", tmp2[playerid]);
  220.             INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][0]);
  221.             format(str_tmp, sizeof(str_tmp), "Y_%d", tmp2[playerid]);
  222.             INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][1]);
  223.             format(str_tmp, sizeof(str_tmp), "Z_%d", tmp2[playerid]);
  224.             INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][2]);
  225.             format(str_tmp, sizeof(str_tmp), "A_%d", tmp2[playerid]);
  226.             INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][3]);
  227.             format(str_tmp, sizeof(str_tmp), "Counter_%d", tmp2[playerid]);
  228.             INI_WriteInt(File, str_tmp, pos_COUNTER[playerid]);
  229.             format(str_tmp, sizeof(str_tmp), "Interior_%d", tmp2[playerid]);
  230.             INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
  231.             format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", tmp2[playerid]);
  232.             INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
  233.             format(str_tmp, sizeof(str_tmp), "Name_%d", tmp2[playerid]);
  234.             INI_WriteString(File, str_tmp, pos_NAME[playerid][tmp2[playerid]]);
  235.             format(str_tmp, sizeof(str_tmp), "Handler_%d", tmp2[playerid]);
  236.             INI_WriteInt(File, str_tmp, pos_Handler[playerid][tmp2[playerid]]);
  237.             INI_Close(File);
  238.             tmp2[playerid] = 0;
  239.         }
  240.         return 1;
  241.     }
  242.     if(dialogid == DIALOG_MAIN)
  243.     {
  244.         if(response)
  245.         {
  246.             if(pos_Handler[playerid][listitem] != 0) {
  247.             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]);
  248.             format(main_string, 128 + MAX_SAVE_POSITION_NAME_LENGTH + 2 + 10, "SUCCESS: "MSG_YELLOW"Teleported to: \"%s\"(%d)", pos_NAME[playerid][listitem], listitem);
  249.             SendClientMessage(playerid, COLOR_GREY, main_string); }
  250.             else return SendClientMessage(playerid, COLOR_GREY, "ERROR: "MSG_YELLOW"You haven't saved this position slot yet!");
  251.         }
  252.         return 1;
  253.     }
  254.     return 0;
  255. }
  256.  
  257. stock SetPlayerPosEx(playerid, Float: x, Float: y, Float: z, Inte, VW, Float: a)
  258. {
  259.     if(!IsPlayerInAnyVehicle(playerid)) return SetPlayerPos(playerid, x, y, z), SetPlayerInterior(playerid, Inte), SetPlayerVirtualWorld(playerid, VW), SetPlayerFacingAngle(playerid, a);
  260.     else return SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z), SetVehicleZAngle(GetPlayerVehicleID(playerid), a), SetVehicleVirtualWorld(GetPlayerVehicleID(playerid), VW), LinkVehicleToInterior(GetPlayerVehicleID(playerid), Inte);
  261. }
  262.  
  263. forward LoadPlayerPos_data(playerid,name[],value[]);
  264. public LoadPlayerPos_data(playerid,name[],value[])
  265. {
  266.     new str_tmp[21];
  267.     for(new i = 0; i < MAX_SAVED_POSITIONS_PER_PLAYER; i++)
  268.     {
  269.         format(str_tmp, sizeof(str_tmp), "X_%d", i);
  270.         INI_Float(str_tmp, pos_ACTUAL[playerid][i][0]);
  271.         format(str_tmp, sizeof(str_tmp), "Y_%d", i);
  272.         INI_Float(str_tmp, pos_ACTUAL[playerid][i][1]);
  273.         format(str_tmp, sizeof(str_tmp), "Z_%d", i);
  274.         INI_Float(str_tmp, pos_ACTUAL[playerid][i][2]);
  275.         format(str_tmp, sizeof(str_tmp), "A_%d", i);
  276.         INI_Float(str_tmp, pos_ACTUAL[playerid][i][3]);
  277.         format(str_tmp, sizeof(str_tmp), "Counter_%d", i);
  278.         INI_Int(str_tmp, pos_COUNTER[playerid]);
  279.         format(str_tmp, sizeof(str_tmp), "Interior_%d", i);
  280.         INI_Int(str_tmp, pos_INT[playerid][i]);
  281.         format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", i);
  282.         INI_Int(str_tmp, pos_VW[playerid][i]);
  283.         format(str_tmp, sizeof(str_tmp), "Name_%d", i);
  284.         INI_String(str_tmp, pos_NAME[playerid][i], MAX_SAVE_POSITION_NAME_LENGTH);
  285.         format(str_tmp, sizeof(str_tmp), "Handler_%d", i);
  286.         INI_Int(str_tmp, pos_Handler[playerid][i]);
  287.     }
  288.     return 1;
  289. }
  290.  
  291. PlayerPath(playerid)
  292. {
  293.     new file[128], p[MAX_PLAYER_NAME];
  294.     GetPlayerName(playerid, p, sizeof(p));
  295.     format(file, sizeof(file), SAVE_PATH, p);
  296.     return file;
  297. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement