Nyft_

Salvar jogador na última posição ~Nyft

May 11th, 2021 (edited)
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.97 KB | None | 0 0
  1. #include a_samp
  2. #include dof2
  3. #include pawn.cmd
  4.  
  5. #define function%0(%1) \
  6.     forward%0(%1); public%0(%1)
  7.  
  8. static gPlayerLastTimer[MAX_PLAYERS] = {-1, ...};
  9. static Float:gPlayerLastPos[MAX_PLAYERS][4];
  10. static bool:gPlayerLastWarning[MAX_PLAYERS];
  11.  
  12. main(){}
  13.  
  14. public OnGameModeInit()
  15. {
  16.     DOF2::Exit();
  17.     return 1;
  18. }
  19.  
  20. public OnPlayerSpawn(playerid)
  21. {
  22.     new file[16 + MAX_PLAYER_NAME];
  23.     format(file, sizeof(file), "Posições/%s.ini", GetPlayerNamef(playerid));
  24.  
  25.     if(DOF2::FileExists(file) && !gPlayerLastWarning[playerid] && gPlayerLastTimer[playerid] == -1)
  26.     {
  27.         SendClientMessage(playerid, -1, "* Para continuar em sua última posição use (/continuar).");
  28.         gPlayerLastTimer[playerid] = SetTimerEx("OnPlayerLastPosition", 30000, false, "i", playerid);
  29.     }
  30.     return 1;
  31. }
  32.  
  33. public OnPlayerDisconnect(playerid, reason)
  34. {
  35.     SavePlayerLastPosition(playerid);
  36.     return 1;
  37. }
  38.  
  39. function OnPlayerLastPosition(playerid)
  40. {
  41.     ResetPlayerLastPosition(playerid);
  42.     SendClientMessage(playerid, -1, "* Se passaram 30 segundos e você não quis continuar em sua última posição.");
  43.     return 1;
  44. }
  45.  
  46. SavePlayerLastPosition(playerid)
  47. {
  48.     new file[16 + MAX_PLAYER_NAME];
  49.     format(file, sizeof(file), "Posições/%s.ini", GetPlayerNamef(playerid));
  50.  
  51.     if(!DOF2::FileExists(file))
  52.         DOF2::CreateFile(file);
  53.  
  54.     GetPlayerPos(playerid, gPlayerLastPos[playerid][0], gPlayerLastPos[playerid][1], gPlayerLastPos[playerid][2]);
  55.     GetPlayerFacingAngle(playerid, gPlayerLastPos[playerid][3]);
  56.  
  57.     DOF2::SetFloat(file, "X", gPlayerLastPos[playerid][0]);
  58.     DOF2::SetFloat(file, "Y", gPlayerLastPos[playerid][1]);
  59.     DOF2::SetFloat(file, "Z", gPlayerLastPos[playerid][2]);
  60.     DOF2::SetFloat(file, "A", gPlayerLastPos[playerid][3]);
  61.     DOF2::SaveFile();
  62. }
  63.  
  64. ResetPlayerLastPosition(playerid)
  65. {
  66.     KillTimer(gPlayerLastTimer[playerid]);
  67.     gPlayerLastTimer[playerid] = -1;
  68.     gPlayerLastWarning[playerid] = true;
  69. }
  70.  
  71. GetPlayerNamef(playerid)
  72. {
  73.     new name[MAX_PLAYER_NAME];
  74.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  75.     return name;
  76. }
  77.  
  78. CMD:continuar(playerid)
  79. {
  80.     if(gPlayerLastWarning[playerid])
  81.         return SendClientMessage(playerid, -1, "* Você não pode usar este comando agora.");
  82.  
  83.     new file[16 + MAX_PLAYER_NAME];
  84.     format(file, sizeof(file), "Posições/%s.ini", GetPlayerNamef(playerid));
  85.  
  86.     if(DOF2::FileExists(file))
  87.     {
  88.         gPlayerLastPos[playerid][0] = DOF2::GetFloat(file, "X");
  89.         gPlayerLastPos[playerid][1] = DOF2::GetFloat(file, "Y");
  90.         gPlayerLastPos[playerid][2] = DOF2::GetFloat(file, "Z");
  91.         gPlayerLastPos[playerid][3] = DOF2::GetFloat(file, "A");
  92.  
  93.         SetPlayerPos(playerid, gPlayerLastPos[playerid][0], gPlayerLastPos[playerid][1], gPlayerLastPos[playerid][2]);
  94.         SetPlayerFacingAngle(playerid, gPlayerLastPos[playerid][3]);
  95.         SetCameraBehindPlayer(playerid);
  96.         ResetPlayerLastPosition(playerid);
  97.     }
  98.     return 1;
  99. }
Add Comment
Please, Sign In to add comment