09.05.2013, 18:33
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;
}