22/10/2023 19:46
(Esta mensagem foi modificada pela última vez a: 22/10/2023 20:28 por L10motos.)
Do jeito que está quando eu entro no servidor cria um veiculo, depois cria mais outro e se eu entrar 5 vezes cria 5 veiculo do mesmo modelo....
Codigo inteiro
Se quiser detalhar mais.
Codigo inteiro
Código PHP:
#define PLAYER_CAR_DESTROY_TIME 7200000
new car_player_destroytimer[MAX_VEHICLES];
new car_player_owned[MAX_VEHICLES];
new car_player_owner[MAX_VEHICLES][MAX_PLAYER_NAME];
forward OnPlayerLogin(playerid, password[]);
public OnPlayerLogin(playerid, password[])
{
player_cars_create(playerid);
}
public OnPlayerDisconnect(playerid, reason)
{
player_cars_destroy(playerid);
}
forward player_cars_create(playerid);
public player_cars_create(playerid)
{
for(new slot = 0; slot < MAX_PLAYER_VEH; ++slot)
{
player_car_vehicle[playerid][slot] = 0;
for(new carid = sizeof(CarInfo); carid < MAX_VEHICLES; ++carid)
{
if(!strcmp("AhjffgUio", car_player_owner[carid], false)) format(car_player_owner[carid], MAX_PLAYER_NAME, "nenhum");
if(car_player_owned[carid] == slot && !strcmp(Name(playerid), car_player_owner[carid], false))
{
new modelid = player_car_model[playerid][slot];
if(400 <= modelid <= 611)
{
if(car_player_destroytimer[carid] != -1) { KillTimer(car_player_destroytimer[carid]); car_player_destroytimer[carid] = -1; }
player_car_vehicle[playerid][slot] = carid;
}
else
{
DestroyVehicle(carid);
player_car_vehicle[playerid][slot] = 0;
KillTimer(car_player_destroytimer[carid]);
car_player_destroytimer[carid] = -1;
format(car_player_owner[carid], MAX_PLAYER_NAME, "nenhum");
car_player_owned[carid] = -1;
}
}
}
if(player_car_vehicle[playerid][slot] == 0)
{
new modelid = player_car_model[playerid][slot];
if(400 <= modelid <= 611)
{
new c = slot;
player_car_vehicle[playerid][slot] = CreateVehicleEx(modelid, player_car_pos[playerid][c][0], player_car_pos[playerid][c][1], player_car_pos[playerid][c][2], player_car_pos[playerid][c][3], player_car_color1[playerid][c], player_car_color2[playerid][c], -1);
new carid = player_car_vehicle[playerid][c];
car_player_owned[carid] = slot; format(car_player_owner[carid], MAX_PLAYER_NAME, "%s", Name(playerid));
if(car_player_destroytimer[carid] != -1) { KillTimer(car_player_destroytimer[carid]); car_player_destroytimer[carid] = -1; } // anti bug
LinkVehicleToInterior(carid, player_car_interior[playerid][slot]);
SetVehicleVirtualWorld(carid, player_car_world[playerid][slot]);
if(player_car_health[playerid][c] < 299) player_car_health[playerid][c] = 299;
SetVehicleHealth(carid, player_car_health[playerid][c]);
Alarme[carid] = 1; AlarmTriggered[carid] = 0;
LockVehicle(carid);
if(player_car_forsale[playerid][c] > 0)
{
SetTimerEx("CreateForSaleText", 2000, false, "i", carid);
Alarme[carid] = 0;
}
else RemoveForSaleText(carid);
SetGVarInt("Gasolina", carid, 100);
LoadingTuning(carid);
SetVehicleToRespawn(carid);
}
}
}
return 1;
}
forward player_cars_destroy(playerid);
public player_cars_destroy(playerid)
{
for(new c = 0; c < MAX_PLAYER_CAR; ++c)
{
new modelid = player_car_model[playerid][c];
if(400 <= modelid <= 611)
{
new carid = player_car_vehicle[playerid][c];
if(player_car_forsale[playerid][c] == 0)
{
car_player_destroytimer[carid] = SetTimerEx("player_car_destroy", PLAYER_CAR_DESTROY_TIME, false, "i", carid);
}
}
}
return 1;
}
forward player_car_destroy(carid);
public player_car_destroy(carid)
{
if(car_player_destroytimer[carid] != -1) KillTimer(car_player_destroytimer[carid]);
car_player_destroytimer[carid] = -1;
car_player_owned[carid] = -1;
format(car_player_owner[carid], MAX_PLAYER_NAME, "nenhum");
DestroyVehicle(carid);
}
Se quiser detalhar mais.