CptK

savepos - Personal Request

May 28th, 2012
24
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-------------------------------
  2. #include <a_samp>
  3. #include <YSI\y_ini>
  4. //-------------------------------
  5. #define PATH "/savepos/%s.ini"
  6. //-------------------------------
  7. new
  8.     Float:logPos[4];
  9. //-------------------------------
  10. forward LoadUser_data(playerid, name[], value[]);
  11. //-------------------------------
  12. stock GetName(playerid)
  13. {
  14.     new
  15.         pname[MAX_PLAYER_NAME];
  16.     GetPlayerName(playerid, pname, sizeof(pname));
  17.     return pname;
  18. }
  19.  
  20. stock UserPath(playerid)
  21. {
  22.     new
  23.         ppath[70];
  24.     format(ppath, sizeof(ppath), PATH, GetName(playerid));
  25.     return ppath;
  26. }
  27. //-------------------------------
  28. public LoadUser_data(playerid, name[], value[])
  29. {
  30.     INI_Float("posX", logPos[0]);
  31.     INI_Float("posY", logPos[1]);
  32.     INI_Float("posZ", logPos[2]);
  33.     INI_Float("posA", logPos[3]);
  34.     return 1;
  35. }
  36. //-------------------------------
  37. public OnFilterScriptInit()
  38. {
  39.     print("savepos loaded.\n");
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerCommandText(playerid, cmdtext[])
  44. {
  45.     if (!strcmp(cmdtext, "/loadpos", true))
  46.     {
  47.         SetPlayerPos(playerid, logPos[0], logPos[1], logPos[2]);
  48.         SetPlayerFacingAngle(playerid, logPos[3]);
  49.         SendClientMessage(playerid, -1, "Disconnection position has been successfully loaded!");
  50.         return 1;
  51.     }
  52.     return 0;
  53. }
  54.  
  55. public OnPlayerDisconnect(playerid, reason)
  56. {
  57.     new
  58.         Float:pos[4],
  59.         INI:File = INI_Open(UserPath(playerid));
  60.     GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  61.     GetPlayerFacingAngle(playerid, pos[3]);
  62.     INI_SetTag(File, "data");
  63.     INI_WriteFloat(File, "posX", pos[0]);
  64.     INI_WriteFloat(File, "posY", pos[1]);
  65.     INI_WriteFloat(File, "posZ", pos[2]);
  66.     INI_WriteFloat(File, "posA", pos[3]);
  67.     INI_Close(File);
  68.     return 1;
  69. }
RAW Paste Data