Advertisement
Guest User

Sistema de corrida avançado(By White_Blue)

a guest
Jan 16th, 2023
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 38.92 KB | None | 0 0
  1. // Includes necessárias
  2. #include <a_samp>
  3. #include <DOF2>
  4. #include <foreach>
  5. #include <Pawn.CMD> // Se quiser utilizar zcmd ou semelhante, fique à vontade.
  6. #include <sscanf2>
  7.  
  8. // Cores
  9. #define Vermelho                                                                0xFF0000AA
  10. #define Verde                                                                   0x00D700AA
  11. #define Azul                                                                    0x00FFFFAA
  12. #define Amarelo                                                                 0xFFFFFFAA
  13. #define LARANJA                                                                 0xFFFF00AA
  14.  
  15. // Sistema de Corrida
  16. enum CRInfo
  17. {
  18.     Float: PosCorrida[3],
  19.     GangZoneCorrida,
  20.     bool: CorridaAtivo,
  21.     NomeCorrida[30],
  22.     VagasCorrida,
  23.     PlayersCorrida,
  24.     Text: TextDrawsCorrida[3],
  25.     Int_Corrida,
  26.     Virtual_World,
  27.     bool: CorridaCongelado,
  28.     CorridaVida,
  29.     Corridakev,
  30.     TotalCP,
  31.     bool: IsRace,
  32.     bool: CorridaIniciado,
  33.     bool: CorridaTrancado,
  34.     Organizador[MAX_PLAYER_NAME],
  35.     Vencedores,
  36.     TimerRandom,
  37.     TimerIniciar,
  38.     Contagem,
  39.     Tempo,
  40.     InicioRandomico,
  41.     bool: VagasOcupadas[50],
  42.     CPStyle
  43. };
  44.  
  45. // Info corrida
  46. #define MAX_CorridaS                                                            100
  47. #define MAX_CPS                                                                 200
  48. #define VIRTUAL_WORLD                                                           80
  49. #define CorridaText
  50. #define PASTA_Corrida "/Corridas/Corrida%d.ini" // Crie a pasta com o nome "Corridas" sem aspas na pasta scriptfiles de sua Gamemode.
  51.  
  52. enum CarrosInfo
  53. {
  54.     VehID,
  55.     Float:CoordY,
  56.     Float:CoordX,
  57.     Float:CoordZ,
  58.     Float:Angulo
  59. };
  60.  
  61.  
  62. // Var
  63. #if defined CorridaText
  64. new Text:Text_Corrida;
  65. #endif
  66.  
  67. new timer;
  68.  
  69. #if defined CorridaText
  70. new NewsLine[][] =
  71. {
  72.     "~b~Corrida ~y~ativada   ~n~ ~r~use ~g~/ircorrida",
  73.     "~y~Corrida ~b~ativada   ~n~ ~g~use ~r~/ircorrida"
  74.  
  75. };
  76. #endif
  77.  
  78. new Float:CarrosInfos[MAX_PLAYERS][CarrosInfo];
  79. new Float:CheckPoint[MAX_PLAYERS][MAX_CPS][3];
  80. new CarroCorrida[MAX_PLAYERS] = INVALID_VEHICLE_ID;
  81. new ListaCorrida[MAX_PLAYERS][MAX_CorridaS];
  82. new Float:CPCoord[MAX_CPS][3];
  83. new Float:VeiculoCoord[MAX_PLAYERS][4];
  84. new VeiculoModel[MAX_PLAYERS];
  85. new VeiculoCorrida[MAX_PLAYERS];
  86. new IsPlayerCountdownStarted[MAX_PLAYERS];
  87. new PlayerCountdownCount[MAX_PLAYERS];
  88. new PlayerCountdownTimer[MAX_PLAYERS];
  89. new IsCountdownStarted;
  90. // Corrida
  91. new interiorc;
  92. new Proibido = 1;
  93. new CorridaTextDraw = 0;
  94. new CorridaCriado = 0;
  95. new VagasNaCorrida = 0;
  96. new PlayersNaCorrida = 0;
  97. new Online = 0;
  98. new ExpulsoCorrida[MAX_PLAYERS] = 0;
  99. new Float:cX;
  100. new Float:cY;
  101. new Float:cZ;
  102. new guerra;
  103. new noCorrida[MAX_PLAYERS];
  104.  
  105. // Forwards
  106. forward RaceTextUpdate(playerid);
  107. forward IsNumeric(const string[]);
  108.  
  109. // Dialogs
  110. #define DIALOG_CRIAR_Corrida                                                    0
  111. #define DIALOG_CRIAR_POSICAO                                                    1
  112. #define DIALOG_DEFINIR_VAGAS                                                    2
  113. #define DIALOG_CONFIGS                                                          3
  114. #define DIALOG_Corrida_PERSONALIZADO                                            4
  115. #define DIALOG_NOME_CORRIDA                                                     5
  116. #define DIALOG_CARREGAR_Corrida                                                 6
  117. #define DIALOG_DELETAR_Corrida                                                  7
  118. #define DIALOG_VIRTUAL_WORLD_Corrida                                            8
  119. #define DIALOG_DEFINIR_CHECK                                                    9
  120.  
  121. new E_Enum[CRInfo];
  122. new StringEV[128];
  123.  
  124. new vid[MAX_PLAYERS] = INVALID_VEHICLE_ID;
  125.  
  126. public OnGameModeExit() {
  127.     DOF2_Exit();
  128.     return 1;
  129. }
  130.  
  131. public OnPlayerConnect(playerid) {
  132.     Online++;
  133.     return 1;
  134. }
  135.  
  136. CMD:cv(playerid, params[]) { // Comando para criar veículo simples para salvar ao criar uma corrida.
  137.     new Float:X, Float:Y, Float:Z, Float:Angle, model;
  138.    
  139.     if(sscanf(params, "d", model)) return SendClientMessage(playerid, Vermelho, "Use: /cv [id]");
  140.  
  141.     GetPlayerPos(playerid, X, Y, Z);
  142.     GetPlayerFacingAngle(playerid, Angle);
  143.     if(vid[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(vid[playerid]);
  144.  
  145.  
  146.     vid[playerid] = AddStaticVehicleEx(model, X, Y, Z, Angle, 0, 0, 30);
  147.     PutPlayerInVehicle(playerid, vid[playerid], 0);
  148.     LinkVehicleToInterior(vid[playerid], GetPlayerInterior(playerid));
  149.     SetVehicleVirtualWorld(vid[playerid], GetPlayerVirtualWorld(playerid));
  150.     return 1;
  151. }
  152.  
  153. public OnPlayerStateChange(playerid, newstate, oldstate) {
  154.     if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT && vid[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(vid[playerid]);
  155.     return 1;
  156. }
  157.  
  158. CMD:criarcorrida(playerid, params[])
  159. {
  160.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "Você não tem permissão para usar esse Comando.");
  161.     if(E_Enum[CorridaAtivo] == true) return SendClientMessage(playerid, Vermelho, "-> Já existe uma corrida ativada.");
  162.     if(GetPVarInt(playerid, "CriandoCorridaPersonalizado")) return SendClientMessage(playerid, Vermelho, "-> Você está criando um circuito, termine-o primeiro.");
  163.     ShowPlayerDialog(playerid, DIALOG_CRIAR_Corrida, DIALOG_STYLE_LIST, "Criar Corrida", "Criar Corrida\nCarregar Corrida", "Selecionar", "Voltar");
  164.     return 1;
  165. }
  166.  
  167. CMD:expulsarcorrida(playerid, params[]) {
  168.     new plid, motivo[64];
  169.     if(sscanf(params, "us[64]", plid, motivo)) return SendClientMessage(playerid, Vermelho, "/expulsarcorrida [id] [motivo]");
  170.     PlayerExpulsePlayerEvent(playerid, plid, motivo);
  171.     return 1;
  172. }
  173.  
  174. CMD:ircorrida(playerid, params[]) {
  175.     if(E_Enum[CorridaAtivo] == false) return SendClientMessage(playerid, Vermelho, "-> Não há corrida disponivel no momento.");
  176.     if(GetPVarInt(playerid, "NoCorrida")) return SendClientMessage(playerid, Vermelho, "-> Você já está em uma corrida.");
  177.     if(GetPVarInt(playerid, "ExpulsoCorrida")) return SendClientMessage(playerid, Vermelho, "-> Você foi expulso da corrida.");
  178.     if(E_Enum[CorridaTrancado] == true) return SendClientMessage(playerid, Vermelho, "-> A corrida está trancada.");
  179.  
  180.     SetPlayerEventPos(playerid);
  181.     return 1;
  182. }
  183.  
  184. CMD:fecharcorrida(playerid, params[]) {
  185.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "-> Somente administrador pode usar este comando.");
  186.     if(IsOrganizador(playerid)) return 1;
  187.     PlayerClosetEvent(playerid);
  188.     return 1;
  189. }
  190.  
  191. CMD:cancelarcorrida(playerid, params[]) {
  192.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "Você não possui permissão para utilizar este comando.");
  193.     if(IsOrganizador(playerid)) return 1;
  194.     PlayerCancelEvent(playerid);
  195.     return 1;
  196. }
  197.  
  198. CMD:saircorrida(playerid, params[]) {
  199.     if(!GetPVarInt(playerid, "NoCorrida")) return SendClientMessage(playerid, Vermelho, "-> Você não está em uma corrida.");
  200.  
  201.     DestroyVehicle(GetPlayerVehicleID(playerid));
  202.     SendClientMessage(playerid, Vermelho, "-> Você saiu da corrida.");
  203.     DisableRemoteVehicleCollisions(playerid, 0);
  204.  
  205.     format(StringEV, sizeof(StringEV), "{4682B4}| {FFFFFF}CORRIDA {4682B4}| {FFFFFF}%s saiu da corrida, use: {4682B4}/saircorrida {FFFFFF}caso queira sair.", GetPlayerNameEx(playerid));
  206.     SendClientMessageToAll(-1, StringEV);
  207.  
  208.     SpawnPlayer(playerid);
  209.     return 1;
  210. }
  211.  
  212. CMD:veiculo(playerid, params[]) {
  213.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "Você não possui permissão para utilizar este comando.");
  214.     if(!GetPVarInt(playerid, "SaveVeiculo")) return SendClientMessage(playerid, Vermelho, "Você não está criando uma corrida.");
  215.     if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, Vermelho, "Por favor, crie o veículo para salva-lo.");
  216.  
  217.     new Float: vPos[4], Car = GetPlayerVehicleID(playerid), Modelo = GetVehicleModel(Car);
  218.     GetVehiclePos(Car, vPos[0], vPos[1], vPos[2]);
  219.     GetVehicleZAngle(Car, vPos[3]);
  220.  
  221.     CarrosInfos[GetPVarInt(playerid, "VID")][CoordX] = vPos[0];
  222.     CarrosInfos[GetPVarInt(playerid, "VID")][CoordY] = vPos[1];
  223.     CarrosInfos[GetPVarInt(playerid, "VID")][CoordZ] = vPos[2];
  224.     CarrosInfos[GetPVarInt(playerid, "VID")][Angulo] = vPos[3];
  225.     CarrosInfos[GetPVarInt(playerid, "VID")][VehID] = Modelo;
  226.  
  227.     SetTimerEx("CriarVeiculoCorrida", 2000, false, "ddffff", playerid, Modelo, vPos[0], vPos[1], vPos[2], vPos[3]);
  228.     SendClientMessage(playerid, Verde, "O veículo está sendo salvo, aguarde.");
  229.     return 1;
  230. }
  231.  
  232. CMD:check(playerid, params[]) {
  233.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "Você não possui permissão para utilizar este comando.");
  234.     if(!GetPVarInt(playerid, "SaveCheck")) return SendClientMessage(playerid, Vermelho, "Você não está criando uma corrida.");
  235.  
  236.     new Float: jPos[3];
  237.     GetPlayerPos(playerid, jPos[0], jPos[1], jPos[2]);
  238.  
  239.     CheckPoint[playerid][GetPVarInt(playerid, "CPID")][0] = jPos[0];
  240.     CheckPoint[playerid][GetPVarInt(playerid, "CPID")][1] = jPos[1];
  241.     CheckPoint[playerid][GetPVarInt(playerid, "CPID")][2] = jPos[2];
  242.  
  243.     new msg[85];
  244.     format(msg, sizeof(msg), "-> CP %d salvo com sucesso, você pode finalizar a corrida usando '/finalizar'.", GetPVarInt(playerid, "CPID"));
  245.     SendClientMessage(playerid, Verde, msg);
  246.     SetPVarInt(playerid, "CPID", GetPVarInt(playerid, "CPID") + 1);
  247.     return 1;
  248. }
  249.  
  250. CMD:finalizar(playerid, params[])
  251. {
  252.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "Você não possui permissão para utilizar este comando.");
  253.  
  254.     new Arq[90];
  255.     if(GetPVarInt(playerid, "SaveVeiculo"))
  256.     {
  257.         format(Arq, sizeof(Arq), PASTA_Corrida, GetPVarInt(playerid, "CorridaID"));
  258.  
  259.         new line[200], name[90];
  260.         for(new V; V < GetPVarInt(playerid, "VID"); V++)
  261.         {
  262.             format(line, sizeof(line), "%d, %f, %f, %f, %f", CarrosInfos[V][VehID], CarrosInfos[V][CoordX], CarrosInfos[V][CoordY], CarrosInfos[V][CoordZ], CarrosInfos[V][Angulo]);
  263.             format(name, sizeof(name), "Veiculo%d", V);
  264.             DOF2_SetString(Arq, name, line);
  265.             if(CarroCorrida[V] != INVALID_VEHICLE_ID)
  266.             {
  267.                 DestroyVehicle(CarroCorrida[V]);
  268.                 CarroCorrida[V] = INVALID_VEHICLE_ID;
  269.             }
  270.         }
  271.  
  272.         DOF2_SetInt(Arq, "Vagas", GetPVarInt(playerid, "VID"));
  273.  
  274.         DeletePVar(playerid, "SaveVeiculo");
  275.         DeletePVar(playerid, "VID");
  276.         SendClientMessage(playerid, Verde, "-> Veículos salvos com sucesso, agora salve os CP's.");
  277.         SendClientMessage(playerid, Verde, "-> Vá até a largada e use '/check'.");
  278.         SetPVarInt(playerid, "SaveCheck", 1);
  279.         return 1;
  280.     }
  281.     if(GetPVarInt(playerid, "SaveCheck")) {
  282.         format(Arq, sizeof(Arq), PASTA_Corrida, GetPVarInt(playerid, "CorridaID"));
  283.  
  284.         new line[200], name[90];
  285.         for(new C; C < GetPVarInt(playerid, "CPID"); C ++)
  286.         {
  287.             format(line, sizeof(line), "%f, %f, %f", CheckPoint[playerid][C][0], CheckPoint[playerid][C][1], CheckPoint[playerid][C][2]);
  288.             format(name, sizeof(name), "CheckPoint%d", C);
  289.             DOF2_SetString(Arq, name, line);
  290.         }
  291.  
  292.         DOF2_SetInt(Arq, "TotalCPs", GetPVarInt(playerid, "CPID"));
  293.         DOF2_SetInt(Arq, "Interior", GetPlayerInterior(playerid));
  294.  
  295.         ResetPlayerCorrida(playerid);
  296.         SendClientMessage(playerid, Verde, "-> Corrida criada com sucesso, basta carrega-lo no menu do comando '/criarcorrida'.");
  297.         return 1;
  298.     }
  299.     return 1;
  300. }
  301.  
  302. PlayerClosetEvent(playerid) {
  303.     if(E_Enum[CorridaAtivo] == false) return SendClientMessage(playerid, Vermelho, "~ Não há corrida ativa no momento.");
  304.     ResetAllCorrida(0);
  305.     DisableRemoteVehicleCollisions(playerid, 0);
  306.  
  307.     new msg[128];
  308.     if(playerid != GetMaxPlayers()+1) format(msg, sizeof(msg), "{5A9BC6}[!] O(A) Administrador(a) %s fechou a corrida.", GetPlayerNameEx(playerid));
  309.     else format(msg, sizeof(msg), "-> O Admin Bot fechou a corrida.");
  310.     SendClientMessageToAll(Amarelo, msg);
  311.     return 0;
  312. }
  313.  
  314. ResetAllCorrida(opcao) {
  315.  
  316.     E_Enum[PosCorrida][0] = 0.0;
  317.     E_Enum[PosCorrida][1] = 0.0;
  318.     E_Enum[PosCorrida][2] = 0.0;
  319.  
  320.     for(new V; V < MAX_PLAYERS; V++) {
  321.         VeiculoCoord[V][0] = 0.0;
  322.         VeiculoCoord[V][1] = 0.0;
  323.         VeiculoCoord[V][2] = 0.0;
  324.         VeiculoCoord[V][3] = 0.0;
  325.         VeiculoModel[V] = 0;
  326.     }
  327.  
  328.     for(new C; C < E_Enum[TotalCP]; C++) {
  329.         CPCoord[C][0] = 0.0;
  330.         CPCoord[C][1] = 0.0;
  331.         CPCoord[C][2] = 0.0;
  332.     }
  333.  
  334.     GangZoneDestroy(E_Enum[GangZoneCorrida]);
  335.  
  336.     E_Enum[CorridaAtivo] = false;
  337.     format(E_Enum[NomeCorrida], 30, "N/D");
  338.     E_Enum[VagasCorrida] = 0;
  339.     E_Enum[PlayersCorrida] = 0;
  340.     for(new v; v < 50; v++) E_Enum[VagasOcupadas][v] = false;
  341.  
  342.     for(new t; t < 3; t++) TextDrawHideForAll(E_Enum[TextDrawsCorrida][t]);
  343.     E_Enum[Int_Corrida] = 0;
  344.     E_Enum[Virtual_World] = 0;
  345.     E_Enum[CorridaCongelado] = false;
  346.     E_Enum[CorridaVida] = 100;
  347.     E_Enum[Corridakev] = 0;
  348.     E_Enum[TotalCP] = 0;
  349.     E_Enum[IsRace] = false;
  350.     E_Enum[CorridaIniciado] = false;
  351.     E_Enum[CorridaTrancado] = false;
  352.     E_Enum[CPStyle] = 0;
  353.     format(E_Enum[Organizador], 24, "Ninguem");
  354.     if(!opcao) E_Enum[Tempo] = gettime();
  355.     KillTimer(E_Enum[InicioRandomico]);
  356.  
  357.     foreach(Player, i) {
  358.         if(GetPVarInt(i, "NoCorrida")) {
  359.             DestroyVehicle(VeiculoCorrida[i]);
  360.             VeiculoCorrida[i] = INVALID_VEHICLE_ID;
  361.             SpawnPlayer(i);
  362.             DisablePlayerRaceCheckpoint(i);
  363.             RemovePlayerMapIcon(i, 20);
  364.             SetPlayerVirtualWorld(i, 0);
  365.         }
  366.         DeletePVar(i, "NoCorrida");
  367.         DeletePVar(i, "ExpulsoCorrida");
  368.         DeletePVar(i, "ProximoCP");
  369.         DeletePVar(i, "VagaID");
  370.     }
  371.     return 0;
  372. }
  373.  
  374. PlayerCancelEvent(playerid) {
  375.     if(E_Enum[CorridaAtivo] == false) return SendClientMessage(playerid, Vermelho, "~ Não há Corrida corrida ativa no momento.");
  376.     ResetAllCorrida(1);
  377.     DisableRemoteVehicleCollisions(playerid, 0);
  378.  
  379.     new msg[128];
  380.     if(playerid != GetMaxPlayers()+1) format(msg, sizeof(msg), "{5A9BC6}[!] O(A) Administrador(a) %s cancelou a corrida.", GetPlayerNameEx(playerid));
  381.     else format(msg, sizeof(msg), "{5A9BC6}[!] O Admin Bot cancelou a corrida.");
  382.     SendClientMessageToAll(Verde, msg);
  383.  
  384.     return 0;
  385. }
  386.  
  387.  
  388. IsOrganizador(playerid) {
  389.     if(IsPlayerAdmin(playerid)) return 0;
  390.     new Msg;
  391.     if(strcmp(GetPlayerNameEx(playerid), E_Enum[Organizador])) Msg = SendClientMessage(playerid, Vermelho, "~ Você não é o organizador(a) do Corrida!");
  392.     return Msg;
  393. }
  394.  
  395. GetNextEvent() {
  396.     new Arq[90];
  397.     for(new e; e < MAX_CorridaS; e ++) {
  398.         format(Arq, sizeof(Arq), PASTA_Corrida, e);
  399.         if(!DOF2_FileExists(Arq)) return e;
  400.     }
  401.     return -1;
  402. }
  403.  
  404.  
  405. CMD:comecarcorrida(playerid, params[])
  406. {
  407.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "Você não possui permissão para utilizar este comando.");
  408.     if(E_Enum[CorridaAtivo] == false) return SendClientMessage(playerid, Vermelho, "Não há nenhum Corrida no momento.");
  409.     if(E_Enum[CorridaIniciado] == true) return SendClientMessage(playerid, Vermelho, "Corrida já foi iniciado.");
  410.     if(IsOrganizador(playerid)) return 1;
  411.  
  412.     foreach(Player, i) {
  413.         if(GetPVarInt(i, "NoCorrida")) CreatePlayerCountdown(i, 5, 1);
  414.     }
  415.  
  416.     SetTimer("IniciarCorrida", 6000, false);
  417.  
  418.     new msg[60];
  419.     format(msg, sizeof(msg), "-> O(a) Administrador(a) %s iniciou a corrida.", GetPlayerNameEx(playerid));
  420.     SendClientMessageToAll(Azul, msg);
  421.     return 1;
  422. }
  423.  
  424. public OnPlayerSpawn(playerid) {
  425.     ResetPlayerCorrida(playerid);
  426.     return 1;
  427. }
  428.  
  429. ResetPlayerCorrida(playerid) {
  430.     if(!IsPlayerConnected(playerid)) return 1;
  431.     if(GetPVarInt(playerid, "NoCorrida") && E_Enum[CorridaAtivo] == true) {
  432.         E_Enum[PlayersCorrida] -= 1;
  433.         E_Enum[VagasOcupadas][GetPVarInt(playerid, "VagaID")] = false;
  434.         new Td[60];
  435.         format(Td, sizeof(Td), "Vagas: %d/%d", E_Enum[PlayersCorrida], E_Enum[VagasCorrida]);
  436.         TextDrawSetString(E_Enum[TextDrawsCorrida][2], Td);
  437.         if(E_Enum[PlayersCorrida] == 0 && E_Enum[CorridaIniciado] == true) {
  438.             SendClientMessageToAll(LARANJA, "{5A9BC6}[!] O Admin Bot fechou a corrida por falta de participantes.");
  439.             ResetAllCorrida(0);
  440.         }
  441.     }
  442.  
  443.     DestroyVehicle(VeiculoCorrida[playerid]);
  444.     VeiculoCorrida[playerid] = INVALID_VEHICLE_ID;
  445.  
  446.     DeletePVar(playerid, "VagaID");
  447.     DeletePVar(playerid, "CorridaID");
  448.     DeletePVar(playerid, "SaveVeiculo");
  449.     DeletePVar(playerid, "ExpulsoCorrida");
  450.     DeletePVar(playerid, "CPID");
  451.     DeletePVar(playerid, "SaveCheck");
  452.     DeletePVar(playerid, "NoCorrida");
  453.     DeletePVar(playerid, "VID");
  454.     DeletePVar(playerid, "ProximoCP");
  455.     DisablePlayerRaceCheckpoint(playerid);
  456.     SetPlayerVirtualWorld(playerid, 0);
  457.     SetPlayerInterior(playerid, 0);
  458.  
  459.     if(GetPVarInt(playerid, "CriandoCorridaPersonalizado") == 1)
  460.     {
  461.         DeletePVar(playerid, "CriandoCorridaPersonalizado");
  462.         for(new c; c < MAX_CPS; c++) {
  463.             if(c < MAX_PLAYERS)
  464.             {
  465.                 CarrosInfos[c][CoordX] = 0.0, CarrosInfos[c][CoordY] = 0.0, CarrosInfos[c][CoordZ] = 0.0, CarrosInfos[c][Angulo] = 0.0;
  466.                 CarrosInfos[c][VehID] = 0, DestroyVehicle(CarroCorrida[c]), CarroCorrida[c] = INVALID_VEHICLE_ID;
  467.             }
  468.             CheckPoint[playerid][c][0] = 0.0, CheckPoint[playerid][c][1] = 0.0, CheckPoint[playerid][c][2] = 0.0;
  469.         }
  470.     }
  471.     return 0;
  472. }
  473.  
  474. public OnPlayerDisconnect(playerid, reason) {
  475.     if(GetPVarInt(playerid, "CriandoCorridaPersonalizado")) DeletarCorrida(GetPVarInt(playerid, "CorridaID"));
  476.     else if(GetPVarInt(playerid, "NoCorrida")) ResetPlayerCorrida(playerid);
  477.    
  478.     if(noCorrida[playerid] == 1)
  479.     {
  480.         if(Proibido == 0)
  481.         {
  482.             PlayersNaCorrida--;
  483.             noCorrida[playerid] = 0;
  484.             format(StringEV, 128, "{4682B4}! Desocupou-se uma vaga no Corrida! Corra! Use: {FFFFFF}/irCorrida.", PlayersNaCorrida, VagasNaCorrida);
  485.             SendClientMessageToAll(-1, StringEV);
  486.         }
  487.     }
  488.     return 1;
  489. }
  490.  
  491. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  492.     // Sistema de Corrida
  493.     if(dialogid == DIALOG_CRIAR_Corrida && response == 1)
  494.     {
  495.         if(listitem == 0)
  496.         {
  497.             if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Vermelho, "-> Você precisa está na rcon para criar corrida.");
  498.             ShowPlayerDialog(playerid, DIALOG_Corrida_PERSONALIZADO, DIALOG_STYLE_LIST, "Corrida", "Criar Corrida", "Selecionar", "Voltar");
  499.         }
  500.         if(listitem == 1) {
  501.             if(gettime() - E_Enum[Tempo] < 600) return SendClientMessage(playerid, Amarelo, "-> Aguarde algum tempo para criar outra corrida.");
  502.             new str[5000], d[180], cont, Arq[90];
  503.             for(new e; e < MAX_CorridaS; e ++) {
  504.                 format(Arq, sizeof(Arq), PASTA_Corrida, e);
  505.                 if(!DOF2_FileExists(Arq)) continue;
  506.                 format(d, sizeof(d), "Nome: %s - Vagas: %d - Tipo: %s - Criador(a): %s\n", DOF2_GetString(Arq, "Nome"), DOF2_GetInt(Arq, "Vagas"), DOF2_GetString(Arq, "Tipo"), DOF2_GetString(Arq, "Criador"));
  507.                 strcat(str, d, sizeof(str));
  508.                 ListaCorrida[playerid][cont] = e;
  509.                 cont++;
  510.             }
  511.             if(!cont) return SendClientMessage(playerid, Vermelho, "-> Não tem nenhuma corrida disponivel.");
  512.             else ShowPlayerDialog(playerid, DIALOG_CARREGAR_Corrida, DIALOG_STYLE_LIST, "{FFFFFF}Corrida", str, "Carregar", "Voltar");
  513.             return 1;
  514.         }
  515.     }
  516.  
  517.     if(dialogid == DIALOG_CARREGAR_Corrida) {
  518.         if(!response) return ShowPlayerDialog(playerid, DIALOG_CRIAR_Corrida, DIALOG_STYLE_LIST, "Criar Corrida", "Criar Corrida\nCarregar Corrida", "Selecionar", "Voltar");
  519.         if(listitem >= 0) return CarregarCorrida(playerid, ListaCorrida[playerid][listitem]);
  520.     }
  521.  
  522.     if(dialogid == DIALOG_Corrida_PERSONALIZADO) {
  523.         if(!response) return ShowPlayerDialog(playerid, DIALOG_CRIAR_Corrida, DIALOG_STYLE_LIST, "Criar Corrida", "Criar Corrida\nCarregar Corrida", "Selecionar", "Voltar");
  524.         if(listitem == 0) ShowPlayerDialog(playerid, DIALOG_NOME_CORRIDA, DIALOG_STYLE_INPUT, "Corrida", "Digite um nome para a corrida:\n", "Continuar", "Voltar");
  525.     }
  526.  
  527.     if(dialogid == DIALOG_NOME_CORRIDA) {
  528.         if(!response) return ShowPlayerDialog(playerid, DIALOG_Corrida_PERSONALIZADO, DIALOG_STYLE_LIST, "Corrida", "Criar Corrida", "Selecionar", "Voltar");
  529.         if(!strlen(inputtext)) {
  530.             SendClientMessage(playerid, Vermelho, "-> Insira um nome para a corrida.");
  531.             ShowPlayerDialog(playerid, DIALOG_NOME_CORRIDA, DIALOG_STYLE_INPUT, "Corrida", "Digite um nome para a corrida:\n", "Continuar", "Voltar");
  532.             return 1;
  533.         }
  534.         new Arq[90];
  535.         for(new e; e < MAX_CorridaS; e++) {
  536.             format(Arq, sizeof(Arq), PASTA_Corrida, e);
  537.             if(!DOF2_FileExists(Arq)) continue;
  538.             if(strcmp(DOF2_GetString(Arq, "Nome"), inputtext)) continue;
  539.             SendClientMessage(playerid, Vermelho, "-> Uma corrida já está com esse nome.");
  540.             ShowPlayerDialog(playerid, DIALOG_NOME_CORRIDA, DIALOG_STYLE_INPUT, "Corrida", "Digite um nome para a corrida:\n", "Continuar", "Voltar");
  541.             return 1;
  542.         }
  543.         SetPVarInt(playerid, "CorridaID", GetNextEvent());
  544.         SetPVarInt(playerid, "CriandoCorridaPersonalizado", 1);
  545.         format(Arq, sizeof(Arq), PASTA_Corrida, GetPVarInt(playerid, "CorridaID"));
  546.         DOF2_CreateFile(Arq);
  547.         DOF2_SetString(Arq, "Nome", inputtext);
  548.         DOF2_SetString(Arq, "Tipo", "Race");
  549.         DOF2_SetString(Arq, "Criador", GetPlayerNameEx(playerid));
  550.         SetPVarInt(playerid, "SaveVeiculo", 1);
  551.         ShowPlayerDialog(playerid, DIALOG_DEFINIR_CHECK, DIALOG_STYLE_INPUT, "{FFFFFF}Estilo CP", "{FFFFFF}Digite o ID do checkpoint que deseja:\n\n{FF0000}Ultilize Apenas os ID's:\nID: 3 - CheckAéreo\nID: 0 - CheckCorrida", "Definir", "");
  552.         SendClientMessage(playerid, Vermelho, "~ Vá até a posição do veículo e use '/veiculo'.");
  553.         return 1;
  554.     }
  555.  
  556.     if(dialogid == DIALOG_DEFINIR_CHECK) {
  557.         if(!response) return ShowPlayerDialog(playerid, DIALOG_DEFINIR_CHECK, DIALOG_STYLE_LIST, "Estilo CP", "Digite o id do checkpoint que deseja:\n", "Definir", "");
  558.         if(!IsNumeric(inputtext)) return SendClientMessage(playerid, Vermelho, "-> Valor não disponivel"), ShowPlayerDialog(playerid, DIALOG_DEFINIR_CHECK, DIALOG_STYLE_LIST, "Estilo CP", "Digite o id do checkpoint que deseja:\n", "Definir", ""), 1;
  559.         if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_DEFINIR_CHECK, DIALOG_STYLE_LIST, "Estilo CP", "Digite o id do checkpoint que deseja:\n", "Definir", "");
  560.         if(strval(inputtext) > 3) return SendClientMessage(playerid, Vermelho, "-> Valores Permitidos: 0-3"), ShowPlayerDialog(playerid, DIALOG_DEFINIR_CHECK, DIALOG_STYLE_LIST, "Estilo CP", "Digite o id do checkpoint que deseja:\n", "Definir", ""), 1;
  561.         new Arq[90];
  562.         format(Arq, sizeof(Arq), PASTA_Corrida, GetPVarInt(playerid, "CorridaID"));
  563.         if(!DOF2_FileExists(Arq)) return 1;
  564.         DOF2_SetInt(Arq, "CheckStyle", strval(inputtext));
  565.         SendClientMessage(playerid, Verde, "-> CheckPoint salvo com sucesso.");
  566.         return 1;
  567.     }
  568.     return 1;
  569. }
  570.  
  571. stock PlayerCreateEvent(playerid, vagas, const nome[], Float:eX, Float:eY, Float:eZ, eI)
  572. {
  573.     if(CorridaCriado == 1)
  574.     {
  575.         SendClientMessage(playerid, Vermelho, "Um Corrida já foi criado, espere terminar para criar outro.");
  576.         return 1;
  577.     }
  578.     if(Proibido == 1)
  579.     {
  580.         Proibido = 0;
  581.     }
  582.     CorridaTextDraw = 1;
  583.     CorridaCriado = 1;
  584.     VagasNaCorrida = vagas;
  585.  
  586.     cX = eX,
  587.     cY = eY,
  588.     cZ = eZ,
  589.     interiorc = eI;
  590.  
  591.     guerra = GangZoneCreate(eX-100, eY-100, eX+100, eY+100);
  592.     GangZoneShowForAll(guerra, Branco);
  593.  
  594.     #if defined CorridaText
  595.     TextDrawShowForAll(Text_Corrida);
  596.     #endif
  597.  
  598.     timer = SetTimerEx("Nupdate", 900, 1, "d", playerid);
  599.     GameTextForAll("~y~Corrida ~g~Criado", 6000, 1);
  600.  
  601.     format(StringEV, sizeof(StringEV), "{FFFFFF} ~ {4682B4}O(A) Administrador(a) {FFFFFF}%s{4682B4} criou um Corrida. Nome: {FFFFFF}%s{4682B4} Vagas: {FFFFFF}%d.", GetPlayerNameEx(playerid), nome, vagas);
  602.     SendClientMessageToAll(Amarelo, StringEV);
  603.  
  604.     SendClientMessage(playerid, 0x008000AA, "Corrida criado com sucesso use: /comecarCorrida quando você for inicia-lo.");
  605.     SendClientMessage(playerid, 0x008000AA, "Caso você queira cancela-lo use: /cancelarCorrida");
  606.     return 1;
  607. }
  608.  
  609. stock GetPlayerNameEx(playerid) {
  610.     static Name[MAX_PLAYER_NAME];
  611.     GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
  612.     return Name;
  613. }
  614.  
  615. stock CreatePlayerCountdown(playerid, time, sound) {
  616.     if(IsPlayerCountdownStarted[playerid] == 0 && IsCountdownStarted == 0) {
  617.         PlayerCountdownTimer[playerid] = SetTimerEx("PlayerCountdown", 1000, 1, "id", playerid, sound);
  618.         PlayerCountdownCount[playerid] = time;
  619.         IsPlayerCountdownStarted[playerid] = 1;
  620.     }
  621. }
  622.  
  623. stock SetPlayerEventPos(playerid) {
  624.     if(E_Enum[PlayersCorrida] == E_Enum[VagasCorrida]) return SendClientMessage(playerid, Vermelho, "~ Não há mais vagas nesta corrida.");
  625.     SetPVarInt(playerid, "NoCorrida", 1);
  626.     E_Enum[PlayersCorrida] += 1;
  627.     ResetPlayerWeapons(playerid);
  628.     SetPlayerColor(playerid, 0x000000FF);
  629.     SetPlayerVirtualWorld(playerid, E_Enum[Virtual_World]);
  630.     SetPlayerInterior(playerid, E_Enum[Int_Corrida]);
  631.  
  632.     if(E_Enum[CorridaCongelado] == true || E_Enum[IsRace] == true) TogglePlayerControllable(playerid, false);
  633.     if(E_Enum[Corridakev] != 0) SetPlayerHealth(playerid, E_Enum[CorridaVida]);
  634.     else SetPlayerHealth(playerid, 100);
  635.  
  636.     if(E_Enum[Corridakev] != 0) SetPlayerArmour(playerid, E_Enum[Corridakev]);
  637.     else SetPlayerArmour(playerid, 0);
  638.  
  639.     if(E_Enum[IsRace] == true) SetarVeiculoCorrida(playerid);
  640.     else SetPlayerPos(playerid, E_Enum[PosCorrida][0], E_Enum[PosCorrida][1], E_Enum[PosCorrida][2]);
  641.  
  642.     SendClientMessage(playerid, LARANJA, "{5A9BC6}[!] Você entrou na corrida, aguarde ela começar.");
  643.     DisableRemoteVehicleCollisions(playerid, 1);
  644.  
  645.     format(StringEV, sizeof(StringEV), "{4682B4}| {FFFFFF}CORRIDA {4682B4}| {FFFFFF}%s foi para uma corrida, use: {4682B4}/ircorrida.", GetPlayerNameEx(playerid));
  646.     SendClientMessageToAll(-1, StringEV);
  647.  
  648.     new Td[60];
  649.     format(Td, sizeof(Td), "Vagas: %d/%d", E_Enum[PlayersCorrida], E_Enum[VagasCorrida]);
  650.     TextDrawSetString(E_Enum[TextDrawsCorrida][2], Td);
  651.  
  652.     if(!strcmp(E_Enum[Organizador], "Ninguem")) SendClientMessage(playerid, LARANJA, "{5A9BC6}[!] Esta corrida foi criada pelo BOT do servidor, aguarde alguns segundos para começar.");
  653.     return 0;
  654. }
  655.  
  656. stock DeletarCorrida(id) {
  657.     new Arq[90];
  658.     format(Arq, sizeof(Arq), PASTA_Corrida, id);
  659.     if(!DOF2_FileExists(Arq)) return printf("[SISTEMA] Erro ao deletar Corrida %d! Corrida inexistente.", id);
  660.  
  661.     foreach(Player, i) {
  662.         if(!GetPVarInt(i, "CriandoCorridaPersonalizado") || GetPVarInt(i, "CorridaID") != id) continue;
  663.         ResetPlayerCorrida(i);
  664.     }
  665.  
  666.     DOF2_RemoveFile(Arq);
  667.     return 1;
  668. }
  669.  
  670. ContarCorridas() {
  671.     new Arq[90], cont;
  672.     for(new e; e < MAX_CorridaS; e++) {
  673.         format(Arq, sizeof(Arq), PASTA_Corrida, e);
  674.         if(DOF2_FileExists(Arq)) cont++;
  675.     }
  676.     return cont;
  677. }
  678.  
  679. stock PlayerCloseEvent(playerid)
  680. {
  681.     if(CorridaCriado == 0)
  682.     {
  683.         SendClientMessage(playerid, Vermelho, "~ Não tem nenhum Corrida para fechar.");
  684.         return 1;
  685.     }
  686.     if(Proibido == 0)
  687.     {
  688.         Proibido = 1;
  689.     }
  690.     CorridaCriado = 0;
  691.     VagasNaCorrida = 0;
  692.     PlayersNaCorrida = 0;
  693.  
  694.     foreach(Player, i)
  695.     {
  696.         noCorrida[i] = 0;
  697.         ExpulsoCorrida[i] = 0;
  698.     }
  699.  
  700.     if(CorridaTextDraw == 1)
  701.     {
  702.         KillTimer(timer);
  703.  
  704.         #if defined CorridaText
  705.         TextDrawHideForAll(Text_Corrida);
  706.         #endif
  707.  
  708.         CorridaTextDraw = 0;
  709.     }
  710.  
  711.     GangZoneHideForAll(guerra);
  712.     GangZoneDestroy(guerra);
  713.  
  714.     GameTextForAll("~y~Corrida ~r~Fechado", 6000, 1);
  715.     format(StringEV, sizeof(StringEV), "O(a) Administrador %s fechou o Corrida.", GetPlayerNameEx(playerid));
  716.     SendClientMessageToAll(LARANJA, StringEV);
  717.     return 1;
  718. }
  719.  
  720. public IsNumeric(const string[])
  721. {
  722.     for (new i = 0, j = strlen(string); i < j; i++) if(string[i] > '9' || string[i] < '0') return 0;
  723.     return 1;
  724. }
  725.  
  726. stock PlayerExpulsePlayerEvent(playerid, plid, motivo[])
  727. {
  728.     if(CorridaCriado == 0)
  729.     {
  730.         SendClientMessage(playerid, Vermelho, "Não tem nenhum Corrida aberto.");
  731.         return 1;
  732.     }
  733.     if(!IsPlayerConnected(plid))
  734.     {
  735.         SendClientMessage(playerid, Vermelho, "Jogador não conectado.");
  736.         return 1;
  737.     }
  738.     if(noCorrida[plid] == 1)
  739.     {
  740.         PlayersNaCorrida--;
  741.         ExpulsoCorrida[plid] = 1;
  742.         noCorrida[plid] = 0;
  743.         SpawnPlayer(plid);
  744.         format(StringEV, sizeof(StringEV), "{436EEE}O(a) jogador(a) {FFFFFF}%s {436EEE}foi expulso do Corrida. Motivo: {FFFFFF}%s", GetPlayerNameEx(plid), motivo);
  745.         SendClientMessageToAll(Amarelo, StringEV);
  746.     }
  747.     else
  748.     {
  749.         format(StringEV, sizeof(StringEV), "%s não está em um Corrida.", GetPlayerNameEx(plid));
  750.         SendClientMessage(playerid, Vermelho, StringEV);
  751.     }
  752.     return 1;
  753. }
  754.  
  755. stock PlayerInitEvent(playerid)
  756. {
  757.     if(Proibido == 1)
  758.     {
  759.         SendClientMessage(playerid, Vermelho, "Corrida cancelado ou já começou.");
  760.         return 1;
  761.     }
  762.     if(CorridaCriado == 0)
  763.     {
  764.         SendClientMessage(playerid, Vermelho, "Não tem nenhum Corrida para começa-lo.");
  765.         return 1;
  766.     }
  767.     if(Proibido == 0)
  768.     {
  769.         Proibido = 1;
  770.     }
  771.     if(CorridaTextDraw == 1)
  772.     {
  773.         KillTimer(timer);
  774.  
  775.         #if defined CorridaText
  776.         TextDrawHideForAll(Text_Corrida);
  777.         #endif
  778.  
  779.         CorridaTextDraw = 0;
  780.     }
  781.  
  782.     foreach(Player, i)
  783.     {
  784.         if(noCorrida[i] == 1)
  785.         {
  786.             CreatePlayerCountdown(i, 5, 1);
  787.             if(IsPlayerInAnyVehicle(i))
  788.             {
  789.                 SetTimerEx("DestogglePlayerControllable", 6000, 0, "d", i);
  790.             }
  791.         }
  792.     }
  793.  
  794.     GameTextForAll("~y~Corrida ~b~Iniciado", 6000, 1);
  795.     format(StringEV, sizeof(StringEV), "O(a) Administrador %s começou o Corrida.", GetPlayerNameEx(playerid));
  796.     SendClientMessageToAll(LARANJA, StringEV);
  797.  
  798.     SendClientMessage(playerid, 0x008000AA, "O Corrida começou, quando terminar use: /fecharCorrida");
  799.     return 1;
  800. }
  801.  
  802.  
  803. forward DestogglePlayerControllable(playerid);
  804. public DestogglePlayerControllable(playerid) return TogglePlayerControllable(playerid, true);
  805.  
  806. forward CriarVeiculoCorrida(playerid, id, Float: x, Float: y, Float: z, Float: a);
  807. public CriarVeiculoCorrida(playerid, id, Float: x, Float: y, Float: z, Float: a) {
  808.     CarroCorrida[GetPVarInt(playerid, "VID")] = CreateVehicle(id, x, y, z, a, -1, -1, -1);
  809.  
  810.     new msg[50];
  811.     format(msg, sizeof(msg), "-> Veículo %d salvo com sucesso.", GetPVarInt(playerid, "VID"));
  812.     SendClientMessage(playerid, Verde, msg);
  813.     SendClientMessage(playerid, Verde, "-> Agora vá até a próxima posição e use: /veiculo para salvar os carros ou /finalizar para salvar os CP's.");
  814.     SetPVarInt(playerid, "VID", GetPVarInt(playerid, "VID") + 1);
  815.     return 0;
  816. }
  817.  
  818. stock CarregarCorrida(playerid, Corridaid) {
  819.     if(E_Enum[CorridaAtivo] == true) return SendClientMessage(playerid, Vermelho, "-> Uma corrida está em andamento.");
  820.  
  821.     new Arq[90];
  822.     format(Arq, sizeof(Arq), PASTA_Corrida, Corridaid);
  823.  
  824.     E_Enum[VagasCorrida] = DOF2_GetInt(Arq, "Vagas");
  825.     E_Enum[Int_Corrida] = DOF2_GetInt(Arq, "Interior");
  826.     E_Enum[Virtual_World] = VIRTUAL_WORLD;
  827.     E_Enum[CorridaAtivo] = true;
  828.     if(!strcmp(DOF2_GetString(Arq, "Tipo"), "Race")) {
  829.         CarregarCheckPoints(Corridaid);
  830.         E_Enum[TotalCP] = DOF2_GetInt(Arq, "TotalCPs");
  831.         E_Enum[IsRace] = true;
  832.         E_Enum[CPStyle] = DOF2_GetInt(Arq, "CheckStyle");
  833.     }
  834.  
  835.     if(playerid != INVALID_PLAYER_ID) format(E_Enum[Organizador], MAX_PLAYER_NAME, GetPlayerNameEx(playerid));
  836.     else format(E_Enum[Organizador], MAX_PLAYER_NAME, "Ninguem");
  837.     format(E_Enum[NomeCorrida], 30, DOF2_GetString(Arq, "Nome"));
  838.  
  839.     if(!strcmp(E_Enum[Organizador], "Ninguem")) format(StringEV, sizeof(StringEV), "{FF4500}O(A) Administrador(a) Bot criou uma corrida. Nome: %s Vagas: %d.", DOF2_GetString(Arq, "Nome"), DOF2_GetInt(Arq, "Vagas"), DOF2_GetString(Arq, "Tipo"), DOF2_GetString(Arq, "Criador"));
  840.     else format(StringEV, sizeof(StringEV), "{FF4500}O(A) Administrador(a) %s criou uma corrida. Nome: %s Vagas: %d.", GetPlayerNameEx(playerid), DOF2_GetString(Arq, "Nome"), DOF2_GetInt(Arq, "Vagas"), DOF2_GetString(Arq, "Tipo"), DOF2_GetString(Arq, "Criador"));
  841.     SendClientMessageToAll(-1, StringEV);
  842.  
  843.     for(new L; L < 3; L++) TextDrawShowForAll(E_Enum[TextDrawsCorrida][L]);
  844.  
  845.     new Td[60];
  846.     format(Td, sizeof(Td), "Vagas: 0/%d - %s", E_Enum[VagasCorrida], DOF2_GetString(Arq, "Nome"));
  847.     TextDrawSetString(E_Enum[TextDrawsCorrida][2], Td);
  848.  
  849.     ShowPlayerDialog(playerid, DIALOG_VIRTUAL_WORLD_Corrida, DIALOG_STYLE_MSGBOX, "{437FA7}Corrida", "{FFFFFF}Você deseja ir para o local da corrida?", "Sim", "Nao");
  850.     return 1;
  851. }
  852.  
  853. stock CarregarCheckPoints(eid) {
  854.     new Arq[90], line[90], Float: CPs[3], Float: Veh[4], model;
  855.     format(Arq, sizeof(Arq), PASTA_Corrida, eid);
  856.  
  857.     for(new C; C < DOF2_GetInt(Arq, "TotalCPs"); C++) {
  858.         format(line, sizeof(line), "CheckPoint%d", C);
  859.         if(!sscanf(DOF2_GetString(Arq, line), "p<,>fff", CPs[0], CPs[1], CPs[2])) {
  860.             CPCoord[C][0] = CPs[0];
  861.             CPCoord[C][1] = CPs[1];
  862.             CPCoord[C][2] = CPs[2];
  863.         }
  864.     }
  865.  
  866.     for(new V; V < DOF2_GetInt(Arq, "Vagas"); V++) {
  867.         format(line, sizeof(line), "Veiculo%d", V);
  868.         if(!sscanf(DOF2_GetString(Arq, line), "p<,>dffff", model, Veh[0], Veh[1], Veh[2], Veh[3])) {
  869.             VeiculoCoord[V][0] = Veh[0];
  870.             VeiculoCoord[V][1] = Veh[1];
  871.             VeiculoCoord[V][2] = Veh[2];
  872.             VeiculoCoord[V][3] = Veh[3];
  873.             VeiculoModel[V] = model;
  874.         }
  875.     }
  876.  
  877.     E_Enum[PosCorrida][0] = Veh[0], E_Enum[PosCorrida][1] = Veh[1], E_Enum[PosCorrida][2] = Veh[2];
  878.     return 1;
  879. }
  880.  
  881. stock SetarVeiculoCorrida(playerid) {
  882.     for(new V; V < E_Enum[VagasCorrida]; V++) {
  883.         if(E_Enum[VagasOcupadas][V] == true) continue;
  884.         if(VeiculoCorrida[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(VeiculoCorrida[playerid]);
  885.         if(IsPlayerInAnyVehicle(playerid)) SetVehicleToRespawn(GetPlayerVehicleID(playerid));
  886.         E_Enum[VagasOcupadas][V] = true;
  887.         SetPVarInt(playerid, "VagaID", V);
  888.         VeiculoCorrida[playerid] = AddStaticVehicleEx(VeiculoModel[V], VeiculoCoord[V][0], VeiculoCoord[V][1], VeiculoCoord[V][2], VeiculoCoord[V][3], -1, -1, false);
  889.         SetVehiclePos(VeiculoCorrida[playerid], VeiculoCoord[V][0], VeiculoCoord[V][1], VeiculoCoord[V][2]);
  890.         LinkVehicleToInterior(VeiculoCorrida[playerid], E_Enum[Int_Corrida]);
  891.         SetVehicleVirtualWorld(VeiculoCorrida[playerid], E_Enum[Virtual_World]);
  892.         PutPlayerInVehicle(playerid, VeiculoCorrida[playerid], 0);
  893.         return 1;
  894.     }
  895.     return 0;
  896. }
  897.  
  898. forward IniciarCorrida();
  899. public IniciarCorrida() {
  900.     foreach(Player, i) {
  901.         if(!GetPVarInt(i, "NoCorrida")) continue;
  902.  
  903.         if(E_Enum[CorridaVida] != 0) SetPlayerHealth(i, E_Enum[CorridaVida]);
  904.         else SetPlayerHealth(i, 100);
  905.  
  906.         if(E_Enum[Corridakev] != 0) SetPlayerArmour(i, E_Enum[Corridakev]);
  907.         else SetPlayerArmour(i, 0);
  908.  
  909.         E_Enum[Vencedores] = 0;
  910.  
  911.         DeletePVar(i, "ProximoCP");
  912.         TogglePlayerControllable(i, true);
  913.         E_Enum[CorridaIniciado] = true;
  914.         DisablePlayerRaceCheckpoint(i);
  915.         if(E_Enum[IsRace] == true) SetPlayerRaceCheckpoint(i, E_Enum[CPStyle], CPCoord[0][0], CPCoord[0][1], CPCoord[0][2], CPCoord[1][0], CPCoord[1][1], CPCoord[1][2], 9.0);
  916.     }
  917.     KillTimer(E_Enum[TimerIniciar]);
  918.     KillTimer(E_Enum[InicioRandomico]);
  919.     E_Enum[InicioRandomico] = SetTimer("FecharCorrida", 800000, 0);
  920.     for(new L; L < 3; L++) TextDrawHideForAll(E_Enum[TextDrawsCorrida][L]);
  921.     return 0;
  922. }
  923.  
  924. forward RandomEvent();
  925. public RandomEvent() {
  926.     KillTimer(E_Enum[TimerRandom]);
  927.  
  928.     if(E_Enum[CorridaAtivo] == true) {
  929.         print("[SISTEMA] Corrida randômico não criado por haver outro Corrida em andamento!");
  930.         E_Enum[TimerRandom] = SetTimer("RandomEvent", 1800000, 0);
  931.         return 1;
  932.     }
  933.  
  934.     if(Online < 5) {
  935.         print("[SISTEMA] Corrida randômico não criado por haver poucos jogadores online!");
  936.         E_Enum[TimerRandom] = SetTimer("RandomEvent", 1800000, 0);
  937.         return 1;
  938.     }
  939.  
  940.     if(!ContarCorridas()) return E_Enum[TimerRandom] = SetTimer("RandomEvent", 3600000, 0);
  941.  
  942.     new rand = random(ContarCorridas()), Arq[90];
  943.     format(Arq, sizeof(Arq), PASTA_Corrida, rand);
  944.     if(!DOF2_FileExists(Arq)) return RandomEvent();
  945.     CarregarCorrida(INVALID_PLAYER_ID, rand);
  946.  
  947.     KillTimer(E_Enum[TimerIniciar]);
  948.     E_Enum[TimerIniciar] = SetTimer("IniciarCorridaRandomico", 40000, 0);
  949.     E_Enum[TimerRandom] = SetTimer("RandomEvent", 3600000, 0);
  950.     return 0;
  951. }
  952.  
  953. public OnGameModeInit() {
  954.     E_Enum[TimerRandom] = SetTimer("RandomEvent", 3600000, true);
  955.     return 1;
  956. }
  957.  
  958. public OnPlayerEnterRaceCheckpoint(playerid)
  959. {
  960.     if(GetPVarInt(playerid, "NoCorrida"))
  961.     {
  962.         new id = GetPVarInt(playerid, "ProximoCP");
  963.         if(id < E_Enum[TotalCP])
  964.         {
  965.             SetPVarInt(playerid, "ProximoCP", id + 1);
  966.             id = GetPVarInt(playerid, "ProximoCP");
  967.             RemovePlayerMapIcon(playerid, 20);
  968.             DisablePlayerRaceCheckpoint(playerid);
  969.  
  970.             if(id == E_Enum[TotalCP] - 1) {
  971.                 if(E_Enum[CPStyle] != 3) SetPlayerRaceCheckpoint(playerid, 1, CPCoord[id][0], CPCoord[id][1], CPCoord[id][2], 0.0, 0.0, 0.0, 9.9);
  972.                 else SetPlayerRaceCheckpoint(playerid, E_Enum[CPStyle], CPCoord[id][0], CPCoord[id][1], CPCoord[id][2], 0.0, 0.0, 0.0, 9.9);
  973.             }
  974.             else if(id <= E_Enum[TotalCP] - 2) {
  975.                 SetPlayerRaceCheckpoint(playerid, E_Enum[CPStyle], CPCoord[id][0], CPCoord[id][1], CPCoord[id][2], CPCoord[id+1][0], CPCoord[id+1][1], CPCoord[id+1][2], 9.9);
  976.                 SetPlayerMapIcon(playerid, 20, CPCoord[id+1][0], CPCoord[id+1][1], CPCoord[id+1][2], 53, -1);
  977.             }
  978.             new msg[50];
  979.             if(id != E_Enum[TotalCP])format(msg, sizeof(msg), "~r~CP: ~w~%d~y~/~w~%d", GetPVarInt(playerid, "ProximoCP"), E_Enum[TotalCP]);
  980.             else format(msg, sizeof(msg), "Corrida terminada!");
  981.             GameTextForPlayer(playerid, msg, 750, 1);
  982.             PlayerPlaySound(playerid, 1150,0.0,0.0,0.0);
  983.         }
  984.         if(id == E_Enum[TotalCP]) {
  985.             new msg[128];
  986.             if(E_Enum[Vencedores] == 0)
  987.             {
  988.                 format(msg, sizeof(msg), "%s[%d] venceu a corrida %s em primeiro lugar!", GetPlayerNameEx(playerid), playerid, E_Enum[NomeCorrida]);
  989.                 SendClientMessageToAll(Azul, msg);
  990.                 format(msg, sizeof(msg), "~y~~h~]] ~w~%s Venceu ~y~~h~]]", GetPlayerNameEx(playerid));
  991.                 GameTextForAll(msg, 6000, 3);
  992.                 SetPlayerScore(playerid, GetPlayerScore(playerid) + 5);
  993.                 GivePlayerMoney(playerid, 25000);
  994.                 SendClientMessage(playerid, Azul, "-> Você recebeu 5 leveis e R$25000 como prêmio.");
  995.             }
  996.             else if(E_Enum[Vencedores] == 1)
  997.             {
  998.                 format(msg, sizeof(msg), "%s[%d] venceu a corrida %s em segundo lugar!", GetPlayerNameEx(playerid), playerid, E_Enum[NomeCorrida]);
  999.                 SendClientMessageToAll(Amarelo, msg);
  1000.                 GivePlayerMoney(playerid, 50000);
  1001.                 SendClientMessage(playerid, Amarelo, "-> Você recebeu R$50 mil como prêmio.");
  1002.             }
  1003.             else if(E_Enum[Vencedores] == 2)
  1004.             {
  1005.                 format(msg, sizeof(msg), "%s[%d] venceu a corrida %s em terceiro lugar!", GetPlayerNameEx(playerid), playerid, E_Enum[NomeCorrida]);
  1006.                 SendClientMessageToAll(Verde, msg);
  1007.                 GivePlayerMoney(playerid, 10000);
  1008.                 SendClientMessage(playerid, Verde, "-> Você recebeu 10 mil como prêmio.");
  1009.  
  1010.                 SendClientMessageToAll(Vermelho, "{5A9BC6}[!] O Admin Bot fechou a corrida.");
  1011.                 ResetAllCorrida(0);
  1012.                 KillTimer(E_Enum[InicioRandomico]);
  1013.             }
  1014.  
  1015.             E_Enum[Vencedores] ++;
  1016.             DisablePlayerRaceCheckpoint(playerid);
  1017.             DestroyVehicle(GetPlayerVehicleID(playerid));
  1018.             SpawnPlayer(playerid);
  1019.             return 1;
  1020.         }
  1021.     }
  1022.     return 1;
  1023. }
  1024.  
  1025. stock SetPlayerEventPosCorrida(playerid)
  1026. {
  1027.     if(ExpulsoCorrida[playerid] == 1)
  1028.     {
  1029.         SendClientMessage(playerid, Vermelho, "Você foi expulso do Corrida.");
  1030.         return 1;
  1031.     }
  1032.     if(noCorrida[playerid] == 1)
  1033.     {
  1034.         SendClientMessage(playerid, Vermelho, "Você já está no Corrida.");
  1035.         return 1;
  1036.     }
  1037.     if(Proibido == 1)
  1038.     {
  1039.         SendClientMessage(playerid, Vermelho, "Corrida cancelado ou já começou.");
  1040.         return 1;
  1041.     }
  1042.     if(CorridaCriado == 1)
  1043.     {
  1044.         if(PlayersNaCorrida == VagasNaCorrida)
  1045.         {
  1046.             SendClientMessage(playerid, Amarelo, "Acabaram-se as vagas no Corrida, tente no próximo.");
  1047.         }
  1048.         else
  1049.         {
  1050.             PlayersNaCorrida++;
  1051.             noCorrida[playerid] = 1;
  1052.             ResetPlayerWeapons(playerid);
  1053.             SetPlayerInterior(playerid, interiorc);
  1054.             SetPlayerPos(playerid, cX, cY, cZ);
  1055.  
  1056.             TogglePlayerControllable(playerid, false);
  1057.             SetTimerEx("DestogglePlayerControllable", 1000, 0, "d", playerid);
  1058.  
  1059.             format(StringEV, sizeof(StringEV), "{4682B4} [ {FFFFFF}Corrida{4682B4} ] O(A) Jogador(a) %s foi para o Corrida. Vagas: {FFFFFF}%d/%d", GetPlayerNameEx(playerid), PlayersNaCorrida, VagasNaCorrida);
  1060.             SendClientMessageToAll(Vermelho, StringEV);
  1061.         }
  1062.     }
  1063.     return 1;
  1064. }
  1065.  
  1066. main(){printf("Init'");}
  1067.  
  1068. stock SetPlayerEventExit(playerid)
  1069. {
  1070.     if(noCorrida[playerid] == 1)
  1071.     {
  1072.         PlayersNaCorrida--;
  1073.         noCorrida[playerid] = 0;
  1074.         SpawnPlayer(playerid);
  1075.         format(StringEV, sizeof(StringEV), "{4682B4}[ {FFFFFF}Corrida{4682B4} ] O(A) jogador(a) {FFFFFF}%s {4682B4}saiu do Corrida.", GetPlayerNameEx(playerid));
  1076.         SendClientMessageToAll(Amarelo, StringEV);
  1077.     }
  1078.     else
  1079.     {
  1080.         SendClientMessage(playerid, Amarelo, "Você não está em um Corrida.");
  1081.     }
  1082.     return 1;
  1083. }
  1084.  
  1085. public RaceTextUpdate(playerid)
  1086. {
  1087.     #if defined CorridaText
  1088.     static Number = 0;
  1089.     if(Text_Corrida != Text:INVALID_TEXT_DRAW) TextDrawSetString(Text_Corrida, NewsLine[Number++]);
  1090.     if(Number == sizeof(NewsLine)) Number = 0;
  1091.     #endif
  1092.     return 1;
  1093. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement