Código:
#include <YSI-Includes\YSI_Coding\y_hooks>
// /desalugarveiculo
// /localizaalugado
new PlayerIDWasRented[MAX_VEHICLES];
new PlayerWasRentedAnVehicle[MAX_PLAYERS];
new VehicleWillRented[19];
new bool:CheckpointCarRented[MAX_PLAYERS];
hook OnGameModeInit()
{
VehicleWillRented[0] = AddStaticVehicle(560,2148.6123,-1133.9445,25.2727,267.8926,1,1); // carro aluguel
VehicleWillRented[1] = AddStaticVehicle(560,2149.1438,-1143.5524,24.6387,268.4871,1,1); // carro aluguel
VehicleWillRented[3] = AddStaticVehicle(560,2148.0435,-1152.5242,23.6652,269.1633,1,1); // carro aluguel
VehicleWillRented[4] = AddStaticVehicle(560,2147.7788,-1161.5854,23.5286,271.3410,1,1); // carro aluguel
VehicleWillRented[5] = AddStaticVehicle(560,2147.8853,-1171.0149,23.5282,269.4885,1,1); // carro aluguel
VehicleWillRented[6] = AddStaticVehicle(562,2147.5798,-1180.4103,23.4798,269.2659,1,1); // carro aluguel
VehicleWillRented[7] = AddStaticVehicle(562,2147.6924,-1189.2474,23.4795,268.2058,1,1); // carro aluguel
VehicleWillRented[8] = AddStaticVehicle(562,2147.2498,-1198.7405,23.5452,267.2416,1,1); // carro aluguel
VehicleWillRented[9] = AddStaticVehicle(522,2162.4565,-1192.6393,23.3898,88.8190,1,1); // carro aluguel
VehicleWillRented[10] = AddStaticVehicle(522,2162.5291,-1187.4667,23.3929,92.4732,1,1); // carro aluguel
VehicleWillRented[11] = AddStaticVehicle(522,2162.3823,-1182.5447,23.3880,88.0137,1,1); // carro aluguel
VehicleWillRented[12] = AddStaticVehicle(522,2162.3328,-1178.2426,23.3868,87.0074,1,1); // carro aluguel
VehicleWillRented[13] = AddStaticVehicle(521,2162.5552,-1172.5199,23.3774,86.3175,1,1); // carro aluguel
VehicleWillRented[14] = AddStaticVehicle(521,2162.4070,-1168.3434,23.3747,86.4990,1,1); // carro aluguel
VehicleWillRented[15] = AddStaticVehicle(521,2162.7319,-1163.6655,23.3801,86.6132,1,1); // carro aluguel
VehicleWillRented[16] = AddStaticVehicle(521,2162.4192,-1158.1007,23.4222,91.8925,1,1); // carro aluguel
VehicleWillRented[17] = AddStaticVehicle(521,2162.4280,-1152.6804,23.4998,92.0281,1,1); // carro aluguel
VehicleWillRented[18] = AddStaticVehicle(521,2162.2300,-1148.0912,23.9674,94.8319,1,1); // carro aluguel
for(new i; i < 19; i++)
{
GasolinaV[VehicleWillRented[i]] = 100;
PlayerIDWasRented[VehicleWillRented[i]] = SemVar;
}
return 1;
}
hook OnPlayerConnect(playerid)
{
PlayerWasRentedAnVehicle[playerid] = SemVar;
CheckpointCarRented[playerid] = false;
return 1;
}
hook OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid);
for(new i; i < 19; i++)
{
if(VehicleWillRented[i] == vehicleid)//Verificar se está em um veiculo de aluguel
{
if(PlayerIDWasRented[vehicleid] == SemVar)//caso não esteja alugado
{
if(PlayerWasRentedAnVehicle[playerid] != SemVar) return SendClientMessage(playerid, COR_LIGHTRED,"Você já tem um veiculo alugado, /desalugarveiculo"), RemovePlayerFromVehicleEx(playerid);
ShowPlayerDialog(playerid, AluguelDVeiculos, DIALOG_STYLE_MSGBOX, "{B40404}Aluguel de veiculo paulista", "Desejá aluguar este veiculo por R$800.", "Sim", "Nao");
return 0;
}
else if(PlayerIDWasRented[vehicleid] == Player[playerid][pIDFIXO])//caso sejá quem alugou
{
SendClientMessage(playerid, COLOR_LIGHTBLUE, "Ligue e Desligue seu Veiculo apertando 'Y'");
SendClientMessage(playerid, COLOR_LIGHTBLUE, "Digite /desalugarveiculo para desalugaro veiculo.");
SendClientMessage(playerid, COLOR_LIGHTBLUE, "Digite /localizaalugado para localizar veiculo alugado.");
return 0;
}
else //if(PlayerIDWasRented[vehicleid] != SemVar)//caso esteja alugado
{
SendClientMessage(playerid, COLOR_GREY, "Veiculo já alugado, vá até o centro de alugueis para alugar um veiculo!");
RemovePlayerFromVehicleEx(playerid);
return 0;
}
}
}
}
return 1; // Permite o jogador entrar no veículo se não estiver trancado
}
hook OnPlayerDisconnect(playerid, reason)
{
SetVehicleToRespawn(VehicleWillRented[PlayerWasRentedAnVehicle[playerid]]);
PlayerIDWasRented[VehicleWillRented[PlayerWasRentedAnVehicle[playerid]]] = SemVar;
GasolinaV[VehicleWillRented[PlayerWasRentedAnVehicle[playerid]]] = 100;
return 1;
}
hook OnPlayerEnterCheckpoint(playerid)
{
if(CheckpointCarRented[playerid] == true)
{
CheckpointCarRented[playerid] = false;
DisablePlayerCheckpoint(playerid);
}
return 1;
}
hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case AluguelDVeiculos:
{
new Escolha[MAX_PLAYERS];
Escolha[playerid] = (response ? 1 : 2);
if(!response)
{
RemovePlayerFromVehicleEx(playerid);
return true;
}
if(Escolha[playerid] == 1){//Sim
if(GetPlayerMoney(playerid) >= 800)//caso tenha dinheiro suficiente
{
GivePlayerMoney(playerid, -800);
SalvarPlayer(playerid);
new vehicleid = GetPlayerVehicleID(playerid);
for(new i; i < 19; i++)
{
if(VehicleWillRented[i] == vehicleid)//Verificar se está em um veiculo de aluguel
{
PlayerIDWasRented[vehicleid] = Player[playerid][pIDFIXO];
PlayerWasRentedAnVehicle[playerid] = VehicleWillRented[vehicleid];
}
}
return 1;
}
else if(GetPlayerMoney(playerid) < 800)//caso não tenha dinheiro suficiente
{
RemovePlayerFromVehicleEx(playerid);
return 1;
}
return true;
}
else if(Escolha[playerid] == 2){//Nao
RemovePlayerFromVehicleEx(playerid);
return true;
}
}
}
return 1;
}
CMD:desalugarveiculo(playerid)
{
if(PlayerWasRentedAnVehicle[playerid] != SemVar)
{
SendClientMessage(playerid, COLOR_LIGHTGREEN, "Você desalugou um veiculo!");
SetVehicleToRespawn(VehicleWillRented[PlayerWasRentedAnVehicle[playerid]]);
PlayerIDWasRented[VehicleWillRented[PlayerWasRentedAnVehicle[playerid]]] = SemVar;
GasolinaV[VehicleWillRented[PlayerWasRentedAnVehicle[playerid]]] = 100;
PlayerWasRentedAnVehicle[playerid] = SemVar;
return 1;
}
else if(PlayerWasRentedAnVehicle[playerid] == SemVar)
{
SendClientMessage(playerid, COLOR_GREY, "Você não alugou nenhum veiculo para desalugar!");
return 1;
}
return true;
}
CMD:localizaalugado(playerid)
{
if(PlayerWasRentedAnVehicle[playerid] != SemVar)
{
new Float:vehX, Float:vehY, Float:vehZ;
GetVehiclePos(VehicleWillRented[PlayerWasRentedAnVehicle[playerid]], vehX, vehY, vehZ);
SetPlayerCheckpoint(playerid, vehX, vehY, vehZ, 4.0);
CheckpointCarRented[playerid] = true;
return 1;
}
else if(PlayerWasRentedAnVehicle[playerid] == SemVar)
{
SendClientMessage(playerid, COLOR_GREY, "Você não alugou nenhum veiculo para localizar!");
return 1;
}
return true;
}