Advertisement
losnato

[Filterscript] Spawn Última Posição

Jan 19th, 2013
3,904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.78 KB | None | 0 0
  1. #include <a_samp>
  2. #include <DOF2>
  3. #include <ZCMD>
  4.  
  5. /*-------------------------------------------------------------------------------------------------------------------------------
  6. |                                                Configurações                                                                  |
  7. |             - PLAYER_FILE                                                                                                     |
  8. |                   Definição utilizada para obter o caminho do arquivo.                                                        |
  9. |                   Caso deixar padrão, é necessário a pasta Spawn dentro da scriptfiles.                                       |
  10. |                                                                                                                               |
  11. |             - SPAWN_MODE                                                                                                      |
  12. |                   Caso o modo de spawn seja 1 o jogador será forçado a ser levado a última posição salva assim                |
  13. |                   que ele der spawn pela primeira vez.                                                                        |
  14. |                                                                                                                               |
  15. |                   Caso seja 2, o jogador tem um certo tempo para poder decidir se quer continuar na última posi-              |
  16. |                   ção salva. (O tempo é configuravel)                                                                         |
  17. |                                                                                                                               |
  18. |                   Caso seja 3, um dialog sera mostrado ao jogador para que ele escolha se quer continuar da úl-               |
  19. |                   tima posição salva ou continuar no local em que spawnou.                                                    |
  20. |                                                                                                                               |
  21. |             - SPAWN_TIME                                                                                                      |
  22. |                   Tempo em segundos, em que o jogador deverá escolher se quer voltar à última posição salva, ou               |
  23. |                   continuar aonde está.                                                                                       |
  24. |                                                                                                                               |
  25. |                   O SPAWN_TIME só é utilizado caso SPAWN_MODE seja 2.                                                         |
  26. |                                                                                                                               |
  27. |             - SPAWN_COMMAND_STYLE                                                                                             |
  28. |                   Caso SPAWN_MODE seja 2, e SPAWN_COMMAND_STYLE seja 1, o jogador deverá apertar Y para continu-              |
  29. |                   continuar da útima posição salva.                                                                           |
  30. |                                                                                                                               |
  31. |                   Caso SPAWN_COMMAND_STYLE seja 2, o jogador deverá apertar digitar o comando para continuar da               |
  32. |                   útima posição salva.                                                                                        |
  33. |                                                                                                                               |
  34. |             - SPAWN_COMMAND                                                                                                   |
  35. |                   Comando utilizado para continuar do última posição salva.                                                   |
  36. |                                                                                                                               |
  37. |                   O SPAWN_COMMAND só é utilizado caso SPAWN_MODE seja 2.                                                      |
  38. |                                                                                                                               |
  39. |             - SPAWN_DIALOG                                                                                                    |
  40. |                   ID do dialog que vai ser utilizado.                                                                         |
  41. |                                                                                                                               |
  42. --------------------------------------------------------------------------------------------------------------------------------*/
  43. #define     PLAYER_FILE             "Spawn/%s.ini"
  44. #define     SPAWN_MODE              3
  45. #define     SPAWN_TIME              20//utilize em segundos, no caso 10 = 10 segundos.
  46. #define     SPAWN_COMMAND_STYLE     2
  47. #define     SPAWN_DIALOG            1380
  48.  
  49. #if SPAWN_MODE == 2
  50. new
  51.     timeCheck[MAX_PLAYERS],
  52.     timerCheckSpawn[MAX_PLAYERS],
  53.     bool: spawningPlayer[MAX_PLAYERS];
  54. #endif
  55. new
  56.     bool: playerConnected[MAX_PLAYERS];
  57.  
  58. forward CheckSpawnPos(playerid);
  59. forward CheckSpawnPosTime(playerid);
  60.  
  61. public OnFilterScriptExit()
  62. {
  63.     DOF2_Exit();
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerConnect(playerid)
  68. {
  69.     playerConnected[playerid]= true;
  70.  
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerSpawn(playerid)
  75. {
  76.     if(playerConnected[playerid])
  77.     {
  78.         new
  79.             playerFileFormatted[62];
  80.  
  81.         format(playerFileFormatted, 62, PLAYER_FILE, GetPlayerNameEx(playerid));
  82.  
  83.         if(!DOF2_FileExists(playerFileFormatted))
  84.             return DOF2_CreateFile(playerFileFormatted);
  85.  
  86.         #if SPAWN_MODE == 1
  87.             return SetTimerEx("CheckSpawnPos", 500, false, "i", playerid);
  88.         #elseif SPAWN_MODE == 2
  89.             timerCheckSpawn[playerid] = SetTimerEx("CheckSpawnPosTime", 1000, true, "i", playerid);
  90.             spawningPlayer[playerid] = true;
  91.             return 1;
  92.         #elseif SPAWN_MODE == 3
  93.             ShowDialog(playerid, SPAWN_DIALOG);
  94.         #endif
  95.  
  96.         playerConnected[playerid] = false;
  97.     }
  98.  
  99.     return 1;
  100. }
  101. #if SPAWN_MODE == 2
  102.     #if SPAWN_COMMAND_STYLE == 1
  103.     public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  104.         if ((newkeys & KEY_YES) && !(oldkeys & KEY_YES))
  105.             if(spawningPlayer[playerid]) {
  106.                 BreakLine(playerid);
  107.                 SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}Enviado à última posição salva.");
  108.                 KillTimer(timerCheckSpawn[playerid]);
  109.                 spawningPlayer[playerid] = false;
  110.                 return CheckSpawnPos(playerid);
  111.             }
  112.         return 1;
  113.     }
  114.     #endif
  115. #elseif SPAWN_MODE == 3
  116. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  117. {
  118.     switch(dialogid)
  119.     {
  120.         case SPAWN_DIALOG:
  121.         {
  122.             if(!response)
  123.                 return 1;
  124.  
  125.             SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}Enviado à última posição salva.");
  126.             CheckSpawnPos(playerid);
  127.             return 1;
  128.         }
  129.     }
  130.     return 0;
  131. }
  132. #endif
  133.  
  134. public OnPlayerDisconnect(playerid)
  135. {
  136.     new
  137.         Float: flo_player_pos[3],
  138.         Float: flo_player_fa,
  139.         int_player_int = GetPlayerInterior(playerid),
  140.         playerFileFormatted[62];
  141.  
  142.     GetPlayerPos(playerid, flo_player_pos[0], flo_player_pos[1], flo_player_pos[2]);
  143.     GetPlayerFacingAngle(playerid, flo_player_fa);
  144.  
  145.     format(playerFileFormatted, 62, PLAYER_FILE, GetPlayerNameEx(playerid));
  146.  
  147.     if(!DOF2_FileExists(playerFileFormatted))
  148.         DOF2_CreateFile(playerFileFormatted);
  149.  
  150.     DOF2_SetFloat(playerFileFormatted, "Last Pos X", flo_player_pos[0]);
  151.     DOF2_SetFloat(playerFileFormatted, "Last Pos Y", flo_player_pos[1]);
  152.     DOF2_SetFloat(playerFileFormatted, "Last Pos Z", flo_player_pos[2]);
  153.     DOF2_SetFloat(playerFileFormatted, "Last Pos FA", flo_player_fa);
  154.     DOF2_SetInt(playerFileFormatted, "Last Int", int_player_int);
  155.  
  156.     DOF2_SaveFile();
  157.  
  158.     return 1;
  159. }
  160.  
  161. public CheckSpawnPos(playerid)
  162. {
  163.     new
  164.         Float: oldPlayerPos[3],
  165.         Float: oldPlayerPosFA,
  166.         oldPlayerPosInt,
  167.         playerFileFormatted[62];
  168.  
  169.     playerConnected[playerid] = false;
  170.  
  171.     format(playerFileFormatted, 62, PLAYER_FILE, GetPlayerNameEx(playerid));
  172.  
  173.     oldPlayerPos[0] = DOF2_GetFloat(playerFileFormatted, "Last Pos X");
  174.     oldPlayerPos[1] = DOF2_GetFloat(playerFileFormatted, "Last Pos Y");
  175.     oldPlayerPos[2] = DOF2_GetFloat(playerFileFormatted, "Last Pos Z");
  176.     oldPlayerPosFA = DOF2_GetFloat(playerFileFormatted, "Last Pos FA");
  177.     oldPlayerPosInt = DOF2_GetInt(playerFileFormatted, "Last Int");
  178.  
  179.     SetPlayerPos(playerid, oldPlayerPos[0], oldPlayerPos[1], oldPlayerPos[2]);
  180.     SetPlayerFacingAngle(playerid, oldPlayerPosFA);
  181.     SetPlayerInterior(playerid, oldPlayerPosInt);
  182.  
  183.     return 1;
  184. }
  185.  
  186. #if SPAWN_MODE == 2
  187. public CheckSpawnPosTime(playerid)
  188. {
  189.     timeCheck[playerid]++;
  190.     new l_string[128];
  191.  
  192.     if (timeCheck[playerid] == 1)
  193.     {
  194.         #if SPAWN_COMMAND_STYLE == 1
  195.             format(string, sizeof string, "| LSpawn | {FFFFFF}Você tem {64DCFF}%d {FFFFFF}segundos para apertar a tecla {64DCFF}Y {FFFFFF}e continuar aonde", SPAWN_TIME);
  196.             SendClientMessage(playerid, 0x6491FFFF, string);
  197.             SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}estava quando se desconectou do servidor pela última vez.");
  198.         #elseif SPAWN_COMMAND_STYLE == 2
  199.             format(string, sizeof string, "| LSpawn | {FFFFFF}Você tem {64DCFF}%d {FFFFFF}segundos para digitar o comando {64DCFF}/continuar {FFFFFF}e continuar aonde", SPAWN_TIME);
  200.             SendClientMessage(playerid, 0x6491FFFF, string);
  201.             SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}estava quando se desconectou do servidor pela última vez.");
  202.         #endif
  203.     }
  204.     else if (timeCheck[playerid] == SPAWN_TIME/2)
  205.     {
  206.         #if SPAWN_COMMAND_STYLE == 1
  207.             BreakLine(playerid);
  208.             format(string, sizeof string, "| LSpawn | {FFFFFF}Você tem {64DCFF}%d {FFFFFF}segundos para apertar a tecla {64DCFF}Y {FFFFFF}e continuar aonde", SPAWN_TIME/2);
  209.             SendClientMessage(playerid, 0x6491FFFF, string);
  210.             SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}estava quando se desconectou do servidor pela última vez.");
  211.         #elseif SPAWN_COMMAND_STYLE == 2
  212.             BreakLine(playerid);
  213.             format(string, sizeof string, "| LSpawn | {FFFFFF}Você tem {64DCFF}%d {FFFFFF}segundos para digitar o comando {64DCFF}/continuar {FFFFFF}e continuar aonde", SPAWN_TIME/2);
  214.             SendClientMessage(playerid, 0x6491FFFF, string);
  215.             SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}estava quando se desconectou do servidor pela última vez.");
  216.         #endif
  217.     }
  218.     else if (timeCheck[playerid] == SPAWN_TIME)
  219.     {
  220.         BreakLine(playerid);
  221.         SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}O tempo acabou e você vai continuar aonde está.");
  222.         timeCheck[playerid] = 0;
  223.         spawningPlayer[playerid] = false;
  224.         KillTimer(timerCheckSpawn[playerid]);
  225.         return 1;
  226.     }
  227.  
  228.     return 1;
  229. }
  230. #endif
  231.  
  232. #if SPAWN_MODE == 2
  233.     #if SPAWN_COMMAND_STYLE == 2
  234.         CMD:continuar(playerid, params[], help)
  235.         {
  236.             if(!spawningPlayer[playerid])
  237.                 return 0;
  238.  
  239.             BreakLine(playerid);
  240.             SendClientMessage(playerid, 0x6491FFFF, "| LSpawn | {FFFFFF}Enviado à última posição salva.");
  241.             KillTimer(timerCheckSpawn[playerid]);
  242.             spawningPlayer[playerid] = false;
  243.             return CheckSpawnPos(playerid);
  244.         }
  245.     #endif
  246. #elseif SPAWN_MODE == 3
  247. ShowDialog(playerid, dialogid)
  248. {
  249.     switch(dialogid)
  250.     {
  251.         case SPAWN_DIALOG:
  252.         {
  253.             new
  254.                 formatMsg[128];
  255.  
  256.             BreakLine(playerid);
  257.             format(formatMsg, sizeof formatMsg, "{FFFFFF}Olá {64DCFF}%s{FFFFFF}, gostaria de continuar de onde você parou na sua última sessão?", GetPlayerNameEx(playerid));
  258.             ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Spawn...", formatMsg, "Sim", "Não");
  259.  
  260.             return 1;
  261.         }
  262.     }
  263.     return 1;
  264. }
  265. #endif
  266.  
  267. GetPlayerNameEx(playerid)
  268. {
  269.     new
  270.         playerName[MAX_PLAYER_NAME];
  271.  
  272.     GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
  273.  
  274.     return playerName;
  275. }
  276.  
  277. BreakLine(playerid) {
  278.     return SendClientMessage(playerid, -1, " ");
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement