Guest User

Save, Load & Delete[Y_INI][ZCMD]

a guest
Mar 9th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.65 KB | None | 0 0
  1. /* Script: Position - Save, Load & Delete[Y_INI][ZCMD]
  2. -» Copyright © 2018 Siddharth
  3. -» Author:                 Siddharth
  4. -» Release Date:               09.03.2018
  5. -» Description:             Save/load/delete position of player with 1 command
  6. -» Saving System Used:         Y_INI (by Y_Less)
  7. -» Command Processor Used:  ZCMD (by Zeex)
  8. -» Version:                 1.0(Stable)
  9. */
  10.  
  11. /*============================================================================*/
  12. /*INCLUDES*/
  13. #include <a_samp>
  14. #include <YSI\y_ini>
  15. #include <sscanf2>
  16. #include <zcmd>
  17.  
  18. #define POSITIONPATH        "Positions/%s.ini"
  19. #define LOADPOSONSPAWN      true
  20. /*============================================================================*/
  21. enum PlayerInfo
  22. {
  23.     Int,
  24.     Vw,
  25.     Float:Apos,
  26.     Float:Xpos,
  27.     Float:Ypos,
  28.     Float:Zpos,
  29.     bool:SavedPos
  30. }
  31.  
  32. new pInfo[MAX_PLAYERS][PlayerInfo];
  33.  
  34. forward LoadPos_UserData(playerid,name[],value[]);
  35. public LoadPos_UserData(playerid,name[],value[])
  36. {
  37.     INI_Int("Interior", pInfo[playerid][Int]);
  38.     INI_Int("VirtualWorld", pInfo[playerid][Vw]);
  39.     INI_Float("Angle", pInfo[playerid][Apos]);
  40.     INI_Float("Xpos", pInfo[playerid][Xpos]);
  41.     INI_Float("Ypos", pInfo[playerid][Ypos]);
  42.     INI_Float("Zpos", pInfo[playerid][Zpos]);
  43.     INI_Bool("Saved", pInfo[playerid][SavedPos]);
  44.     return 1;
  45. }
  46. /*============================================================================*/
  47. public OnFilterScriptInit()
  48. {
  49.     print("\n______________________________________");
  50.     print("Position (v1.0) (Stable Release)");
  51.     print("SCRIPT: Loading...");
  52.     print("SCRIPT: Loaded.");
  53.     for(new i, j = GetPlayerPoolSize(); i <= j; i++)
  54.     {
  55.         if(fexist(PositionPath(i)))
  56.         {
  57.             INI_ParseFile(PositionPath(i), "LoadPos_%s", .bExtra = true, .extra = i);
  58.             SendClientMessageToAll(-1, "SERVER: Position database has been refreshed!");
  59.         }
  60.     }
  61.     print("Y_INI: Position Data Loading...");
  62.     print("Y_INI: Loaded.");
  63.     print("______________________________________\n");
  64.     return 1;
  65. }
  66.  
  67. public OnFilterScriptExit()
  68. {
  69.     print("\n______________________________________");
  70.     print("Position (v1.0) (Stable Release)");
  71.     print("Unloaded!");
  72.     print("______________________________________\n");
  73.     return 1;
  74. }
  75. /*============================================================================*/
  76. public OnPlayerConnect(playerid)
  77. {
  78.     if(fexist(PositionPath(playerid)))
  79.     {
  80.         INI_ParseFile(PositionPath(playerid), "LoadPos_%s", .bExtra = true, .extra = playerid);
  81.     }
  82.     return 1;
  83. }
  84.  
  85. public OnPlayerSpawn(playerid)
  86. {
  87.     #if LOADPOSONSPAWN == true
  88.     SetPlayerPos(playerid, pInfo[playerid][Xpos], pInfo[playerid][Ypos], pInfo[playerid][Zpos]+0.3);
  89.     #endif
  90.     return 1;
  91. }
  92.  
  93. /*============================================================================*/
  94. CMD:mypos(playerid, params[])
  95. {
  96.     new pos;
  97.     if(sscanf(params, "u", pos)) return SendClientMessage(playerid, -1, "SYNTAX: /mypos <save/load/delete>");
  98.     if(!strcmp(params, "save", true))
  99.     {
  100.         if(pInfo[playerid][SavedPos] == false)
  101.         {
  102.             pInfo[playerid][SavedPos] = true;
  103.             new Float:Xpos1, Float:Ypos1, Float:Zpos1, Float:Angle;
  104.             GetPlayerPos(playerid, Xpos1, Ypos1, Zpos1);
  105.             GetPlayerFacingAngle(playerid, Angle);
  106.  
  107.             pInfo[playerid][Xpos] = Xpos1;
  108.             pInfo[playerid][Ypos] = Ypos1;
  109.             pInfo[playerid][Zpos] = Zpos1;
  110.             pInfo[playerid][Apos] = Angle;
  111.             pInfo[playerid][Int] = GetPlayerInterior(playerid);
  112.             pInfo[playerid][Vw] = GetPlayerVirtualWorld(playerid);
  113.  
  114.             new INI:File = INI_Open(PositionPath(playerid));
  115.             INI_SetTag(File,"PositionData");
  116.             INI_WriteInt(File, "Interior", pInfo[playerid][Int]);
  117.             INI_WriteInt(File, "VirtualWorld", pInfo[playerid][Vw]);
  118.             INI_WriteFloat(File, "Angle", pInfo[playerid][Apos]);
  119.             INI_WriteFloat(File, "Xpos", pInfo[playerid][Xpos]);
  120.             INI_WriteFloat(File, "Ypos", pInfo[playerid][Ypos]);
  121.             INI_WriteFloat(File, "Zpos", pInfo[playerid][Zpos]);
  122.             INI_WriteBool(File, "Saved", pInfo[playerid][SavedPos]);
  123.             INI_Close(File);
  124.  
  125.             SendClientMessage(playerid, -1, "SUCCESS: Position is saved! Use /mypos 2 to teleport.");
  126.         } else SendClientMessage(playerid, -1, "ERROR: You already saved one position, use /mypos delete to delete it!");
  127.     }
  128.     else if(!strcmp(params,"load",true))
  129.     {
  130.         if(pInfo[playerid][SavedPos] == true)
  131.         {
  132.             SetPlayerPos(playerid, pInfo[playerid][Xpos], pInfo[playerid][Ypos], pInfo[playerid][Zpos]+0.3);
  133.             SetPlayerVirtualWorld(playerid, pInfo[playerid][Vw]);
  134.             SetPlayerInterior(playerid, pInfo[playerid][Int]);
  135.             SendClientMessage(playerid, -1, "SUCCESS: Teleported to Position.");
  136.         } else SendClientMessage(playerid, -1, "ERROR: You didn't save any Position. Use /mypos save.");
  137.     }
  138.     else if(!strcmp(params,"delete",true))
  139.     {
  140.         if(pInfo[playerid][SavedPos] == true)
  141.         {
  142.             pInfo[playerid][SavedPos] = false;
  143.             new INI:File = INI_Open(PositionPath(playerid));
  144.             INI_SetTag(File,"PositionData");
  145.             INI_WriteInt(File, "Interior", 0);
  146.             INI_WriteInt(File, "VirtualWorld", 0);
  147.             INI_WriteFloat(File, "Angle", 0);
  148.             INI_WriteFloat(File, "Xpos", 0);
  149.             INI_WriteFloat(File, "Ypos", 0);
  150.             INI_WriteFloat(File, "Zpos", 0);
  151.             INI_WriteBool(File, "Saved", pInfo[playerid][SavedPos]);
  152.             INI_Close(File);
  153.  
  154.             SendClientMessage(playerid, -1, "SUCCESS: Position is deleted! Use /mypos save.");
  155.         } else SendClientMessage(playerid, -1, "ERROR: You didn't save any Position. Use /mypos save.");
  156.  }
  157.     return 1;
  158. }
  159. /*============================================================================*/
  160. stock PositionPath(playerid)
  161. {
  162.     new string[46], pName[MAX_PLAYER_NAME];
  163.     GetPlayerName(playerid, pName, sizeof(pName));
  164.     format(string,sizeof(string), POSITIONPATH, pName);
  165.     return string;
  166. }
  167. /*============================================================================*/
Add Comment
Please, Sign In to add comment