GetClosestVehicle(...) is not working
#1

I found this cool stock that lets you get the ID of any vehicle that is within a radius of the player

Код:
stock GetClosestVehicle(playerid, Float: fRadius) // by RyDeR`
{
    new
        iClosestID = INVALID_VEHICLE_ID,
        Float: fFinalDistance,
        Float: fDistance,
        Float: fX,
        Float: fY,
        Float: fZ;
    GetPlayerPos(playerid, fX, fY, fZ);
    fFinalDistance = fRadius;
 
    for(new i; i != MAX_VEHICLES; i++)
    {
        if((fDistance = GetVehicleDistanceFromPoint(i, fX, fY, fZ)) < fFinalDistance)
        {
            fFinalDistance = fDistance;
            iClosestID = i;
        }
    }
    return iClosestID;
}
Now I have some rental cars that I want the players to be able to lock:

Код:
CMD:lockrent(playerid, params[])
{
	new str[128];
	new vehicle = GetClosestVehicle(playerid, 20);
	format(str, sizeof(str), "VehicleID: %d   RentedCarId: %d ",vehicle, PlayerInfo[playerid][rentCarNo]);
	SendClientMessage(playerid, COLOR_DARKCORAL, str);//THIS IS FOR TESTING




	if(PlayerInfo[playerid][rentCarNo] != vehicle)
	{
		SendClientMessage(playerid, COLOR_DARKCORAL,"[BS] {AFAFAF}You don't have any vehicles nearby.");
	}
	else if(PlayerInfo[playerid][lockedRentCar] == 0 && PlayerInfo[playerid][rentCarNo] == vehicle)
	{
	    SetVehicleParamsForPlayer(vehicle, playerid, 0, 1);
	    SendClientMessage(playerid, COLOR_DARKCORAL,"[BS] {AFAFAF}You've locked your rental car.");
	}
	else if(PlayerInfo[playerid][lockedRentCar] == 1 && PlayerInfo[playerid][rentCarNo] == vehicle)
	{
		SetVehicleParamsForPlayer(vehicle, playerid, 0, 0);
		SendClientMessage(playerid, COLOR_DARKCORAL,"[BS] {AFAFAF}You've unlocked your rental car.");
	}
	
	return 1;
}
My code is working fine, but the stock code always gives me vehicle IDs of 0. I have a problem when I use the /lockrent and at RentedCarID I get the correct value, but at Vehicle I always get 0. So the closest vehicle is always with ID: 0, whereas It should be 7 at my testing case.

RentCarNo is the vehicle ID of the car that is being rented (is working correctly)
lockedRentCar - 0=unlocked 1=locked
vehicle - the vehicle ID of the closest car (not worknig correctly, always shows ID: 0)
Reply


Messages In This Thread
[SOLVED]GetClosestVehicle(...) is not working - by Sibuscus - 29.06.2018, 18:20
Re: GetClosestVehicle(...) is not working - by Calisthenics - 29.06.2018, 18:25
Re: GetClosestVehicle(...) is not working - by Uvais - 29.06.2018, 18:29
Re: GetClosestVehicle(...) is not working - by Sibuscus - 29.06.2018, 18:33
Re: GetClosestVehicle(...) is not working - by Calisthenics - 29.06.2018, 18:36
Re: GetClosestVehicle(...) is not working - by Lokii - 29.06.2018, 18:56

Forum Jump:


Users browsing this thread: 1 Guest(s)