Advertisement
AiRaLoKa

Save Spawn Pos By AiRaLoKa

Dec 1st, 2013
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.35 KB | None | 0 0
  1. // Save Spawn Pos by AiRaLoKa
  2. // Credits
  3. // - AiRaLoKa : For making this whole filterscript
  4. // - Zeex     : For zcmd
  5. // - Y_Less   : For y_ini
  6.  
  7. #define FILTERSCRIPT
  8.  
  9. #include <a_samp>
  10. #include <zcmd>
  11. #include <YSI\y_ini>
  12.  
  13. #define PATH "/Users/%s.ini"
  14. #define ROSU 0x00CC00FF
  15.  
  16. #if defined FILTERSCRIPT
  17.  
  18. public OnFilterScriptInit()
  19. {
  20.     print("\n--------------------------------------");
  21.     print(" Save Spawn Pos by AiRaLoKa");
  22.     print("--------------------------------------\n");
  23.     return 1;
  24. }
  25.  
  26. public OnFilterScriptExit()
  27. {
  28.     return 1;
  29. }
  30.  
  31. #else
  32. main(){}
  33. #endif
  34.  
  35. enum pInfo
  36. {
  37.     pUsePos,
  38.     Float:pA,
  39.     Float:pX,
  40.     Float:pY,
  41.     Float:pZ,
  42.     pHasSavedPos
  43. }
  44.  
  45. new PlayerInfo[MAX_PLAYERS][pInfo];
  46.  
  47. forward LoadUser_PlayerData(playerid,name[],value[]);
  48. public LoadUser_PlayerData(playerid,name[],value[])
  49. {
  50.     INI_Int("UseSpawnPos",PlayerInfo[playerid][pUsePos]);
  51.     INI_Float("FloatA",PlayerInfo[playerid][pA]);
  52.     INI_Float("FloatX",PlayerInfo[playerid][pX]);
  53.     INI_Float("FloatY",PlayerInfo[playerid][pY]);
  54.     INI_Float("FloatZ",PlayerInfo[playerid][pZ]);
  55.     INI_Int("HasSavedPos",PlayerInfo[playerid][pHasSavedPos]);
  56.     return 1;
  57. }
  58.  
  59. CMD:savespawnpos(playerid,params[])
  60. {
  61.     new Float:posA,Float:posX,Float:posY,Float:posZ;
  62.     GetPlayerPos(playerid,posX,posY,posZ);
  63.     GetPlayerFacingAngle(playerid,posA);
  64.     PlayerInfo[playerid][pA]=posA;
  65.     PlayerInfo[playerid][pX]=posX;
  66.     PlayerInfo[playerid][pY]=posY;
  67.     PlayerInfo[playerid][pZ]=posZ;
  68.     PlayerInfo[playerid][pHasSavedPos]=1;
  69.     SendClientMessage(playerid, ROSU, "[INFO]: Spawn position saved!");
  70.     return 1;
  71. }
  72. CMD:usesavedspawnpos(playerid, params[])
  73. {
  74.     if(!strcmp(params,"on"))
  75.     {
  76.         if(PlayerInfo[playerid][pHasSavedPos]==1)
  77.         {
  78.             PlayerInfo[playerid][pUsePos]=1;
  79.             SendClientMessage(playerid, ROSU, "[INFO]: You will be spawned on your saved spawn position");
  80.         }
  81.         else if(PlayerInfo[playerid][pHasSavedPos]==0)
  82.         {
  83.             SendClientMessage(playerid, 0xFF0000FF, "[ERROR]: You don't have any saved spawn position");
  84.         }
  85.     }
  86.     else if(!strcmp(params,"off"))
  87.     {
  88.         PlayerInfo[playerid][pUsePos]=0;
  89.         SendClientMessage(playerid, ROSU, "[INFO]: You will not spawned on your saved spawn position anymore");
  90.     }
  91.     return 1;
  92. }
  93.  
  94. public OnPlayerConnect(playerid)
  95. {
  96.     INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  97.     return 1;
  98. }
  99.  
  100. public OnPlayerDisconnect(playerid, reason)
  101. {
  102.         new INI:File = INI_Open(UserPath(playerid));
  103.     INI_SetTag(File, "PlayerData");
  104.         INI_WriteInt(File,"UseSpawnPos",PlayerInfo[playerid][pUsePos]);
  105.     INI_WriteFloat(File,"FloatA",PlayerInfo[playerid][pA]);
  106.     INI_WriteFloat(File,"FloatX",PlayerInfo[playerid][pX]);
  107.     INI_WriteFloat(File,"FloatY",PlayerInfo[playerid][pY]);
  108.     INI_WriteFloat(File,"FloatZ",PlayerInfo[playerid][pZ]);
  109.     INI_WriteInt(File,"HasSavedPos",PlayerInfo[playerid][pHasSavedPos]);
  110.     INI_Close(File);
  111.     return 1;
  112. }
  113.  
  114. public OnPlayerSpawn(playerid)
  115. {
  116.     if(PlayerInfo[playerid][pUsePos]==1)
  117.     {
  118.         SetPlayerPos(playerid, PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ]);
  119.         SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pA]);
  120.     }
  121.     return 1;
  122. }
  123.  
  124. stock UserPath(playerid)
  125. {
  126.     new string[128],playername[MAX_PLAYER_NAME];
  127.     GetPlayerName(playerid,playername,sizeof(playername));
  128.     format(string,sizeof(string),PATH,playername);
  129.     return string;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement