GetClosestCar
#1

When I try to refill my car it keeps saying you are not near a vehicle, Has someone a better GetClosestCar solution?

pawn Код:
command(refill, playerid, params[])
{
    #pragma unused params
    if(IsAtGasStation(playerid))
    {
        new PCar = GetClosestVehicle(playerid);
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(PCar,engine,lights,alarm,doors,bonnet,boot,objective);
        if(IsPlayerConnected(playerid))
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                if(PCar == 0)
                {
                    if(engine == 0)
                    {
                        if(Vehicles[PCar][Fuel] != 100)
                        {
                            TogglePlayerControllable(playerid,0);
                            ShowMenuForPlayer(Menu:Gas, playerid);
                        }
                        else
                        {
                            SCM(playerid, ADMINBLUE, "Your car is already full!");
                        }
                    }
                    else
                    {
                        SCM(playerid, YELLOW,"Your vehicle engine is still on!");
                    }
                }
                else
                {
                    SCM(playerid, YELLOW,"You are not near a vehicle!");
                }
            }
            else
            {
                SCM(playerid, YELLOW,"You are still in a vehicle!");
            }
        }
    }
    else
    {
       SCM(playerid,0xFFFF00AA,".:: [ERROR]: You are not at a Gas Station! ::.");
    }
    return 1;
}

//found on SAMP forums
stock GetClosestVehicle(playerid)
{
    new Float:DefaultDistance = 99999999999.9;
    new Float:Distance,VehID;
    new Float:X,Float:Y,Float:Z;
    for(new d=1; d < MAX_VEHICLES; d++)
    {
        if(GetVehicleModel(d))
        {
            GetPlayerPos(playerid,X,Y,Z);
            Distance = GetVehicleDistanceFromPoint(d,X,Y,Z);
            if(Distance < DefaultDistance)
            {
                VehID = d;
                DefaultDistance = Distance;
            }
        }
    }
    return VehID;
}
Reply


Messages In This Thread
GetClosestCar - by Stefand - 09.05.2013, 18:33
Re: GetClosestCar - by TheStreetsRP - 09.05.2013, 18:48
Re: GetClosestCar - by Stefand - 09.05.2013, 20:11
Re: GetClosestCar - by zxc1 - 09.05.2013, 20:16
Re: GetClosestCar - by Stefand - 09.05.2013, 20:29
Re: GetClosestCar - by Scenario - 09.05.2013, 20:38
Re: GetClosestCar - by cessil - 09.05.2013, 21:34
Re: GetClosestCar - by Stefand - 09.05.2013, 21:40

Forum Jump:


Users browsing this thread: 7 Guest(s)