GetClosestCar problem -
C0oL3r - 22.02.2018
hey, i got a GetClosestCar stock and when i try to respawn the car it's say that is respawning car 1999 every time.
GetClosestCar:
Код:
stock GetClosestVehicle(playerid, Float:range)
{
new Float:p_X;
new Float:p_Y;
new Float:p_Z;
new Float:Distance;
new Float:PretendentDistance = range +1;
new Pretendent;
GetPlayerPos(playerid, p_X, p_Y, p_Z);
for(new vehicleid=1; vehicleid < MAX_VEHICLES; vehicleid++)
{
Distance = GetVehicleDistanceFromPoint(vehicleid, p_X, p_Y, p_Z);
if(Distance <= range && Distance <= PretendentDistance)
{
Pretendent = vehicleid;
PretendentDistance = Distance;
}
}
return Pretendent;
}
Command:
Код:
CMD:closestcar(playerid, params[])
{
if(pInfo[playerid][pLogged] == 0) return SCM(playerid, COLOR_GREY, ConnectFirst);
if(pInfo[playerid][pAdmin] > 0)
{
new vehid, str[255];
vehid = GetClosestVehicle(playerid, 5);
SetVehicleToRespawn(vehid);
format(str, sizeof(str), ""w"( "dr"Admin Info "w") Admin %s has respawned vehicle %d.", pInfo[playerid][pName], vehid);
ABroadCast(COLOR_WHITE, str, 1);
format(str, sizeof(str), "Vehicle %d has been respawned.", vehid);
SCM(playerid, COLOR_WHITE, str);
}
return 1;
}
Re: GetClosestCar problem -
Pottus - 22.02.2018
You didn't check if the vehicle actually exists.
Re: GetClosestCar problem -
C0oL3r - 22.02.2018
and if not exist what to do, because id 1999 not exists
Re: GetClosestCar problem -
C0oL3r - 22.02.2018
Код:
CMD:closestcar(playerid, params[])
{
if(pInfo[playerid][pLogged] == 0) return SCM(playerid, COLOR_GREY, ConnectFirst);
if(pInfo[playerid][pAdmin] > 0)
{
new vehid, str[255];
vehid = GetClosestVehicle(playerid, 20);
if(vehid != INVALID_VEHICLE_ID)
{
SetVehicleToRespawn(vehid);
format(str, sizeof(str), ""w"( "dr"Admin Info "w") Admin %s has respawned vehicle %d.", pInfo[playerid][pName], vehid);
ABroadCast(COLOR_WHITE, str, 1);
format(str, sizeof(str), "Vehicle %d has been respawned.", vehid);
SCM(playerid, COLOR_WHITE, str);
}
}
return 1;
}
still not working
Re: GetClosestCar problem -
David (Sabljak) - 22.02.2018
Код:
//Somewhere on top
native IsValidVehicle(vehicleid); //According to the wiki, it doesn't exist in the default sa-mp includes, so you have to add it.
stock GetClosestVehicle(playerid, Float: range)
{
new vehicleid = -1, Float: last = range, Float: current, Float: x, Float: y, Float: z;
GetPlayerPos(playerid, x, y, z);
for (new i = 1, j = GetVehiclePoolSize(); i <= j; i++)
{
if(!IsValidVehicle(i)) continue;
current = GetVehicleDistanceFromPoint(i, x, y, z);
if(current < last)
{
vehicleid = i;
last = current;
}
}
return vehicleid;
}
Re: GetClosestCar problem -
C0oL3r - 22.02.2018
623:error 001: expected token: "-identifier-", but found "-string-"
624:error 035: argument type mismatch (argument 3)
628:error 035: argument type mismatch (argument 3)
Код:
stock GetClosestVehicle(playerid, Float:range)
{
623:new vehicleid = -1, Float:last = range, Float:current, Float: x, Float: y, Float: z;
624:GetPlayerPos(playerid, x, y, z);
for (new i = 1, j = GetVehiclePoolSize(); i <= j; i++)
{
if(!IsValidVehicle(i)) continue;
628: current = GetVehicleDistanceFromPoint(i, x, y, z);
if(current < last)
{
vehicleid = i;
last = current;
}
}
return vehicleid;
}
Re: GetClosestCar problem -
C0oL3r - 22.02.2018
Solved, Thx!!