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;
}
stock GetClosestVehicle(playerid) { new vehicleid = INVALID_VEHICLE_ID; new Float:distance = 99999.0; new Float:X, Float:Y, Float:Z; GetPlayerPos(playerid, X, Y, Z); for(i = 0; i < MAX_VEHICLES; i++) { if(GetVehicleDistanceFromPoint(i, X, Y, Z) < distance && distance < 8.0) //you can change this value { vehicleid = i; distance = GetVehicleDistanceFromPoint(i, X, Y, Z); } } return vehicleid; }
new PCar = GetClosestVehicle(playerid);
if(PCar == 0)
if(PCar != INVALID_VEHICLE_ID)
pawn Код:
If you use now TheStreetsRP's stock, I think you should change the if statement to: pawn Код:
|
stock GetClosestVehicle(playerid)
{
new
Float:fPos[3],
Float:distance = 30,
Float:curdistance,
currentVehicle;
for(new v = 0; v < MAX_VEHICLES; v++)
{
GetVehiclePos(v, fPos[0], fPos[1], fPos[2]);
curdistance = GetPlayerDistanceFromPoint(playerid, fPos[0], fPos[1], fPos[2]);
if(curdistance < distance)
{
currentVehicle = v;
distance = curdistance;
}
}
return currentVehicle;
}
Try
Код:
stock GetClosestVehicle(playerid) { new vehicleid = INVALID_VEHICLE_ID; new Float:distance = 99999.0; new Float:X, Float:Y, Float:Z; GetPlayerPos(playerid, X, Y, Z); for(i = 0; i < MAX_VEHICLES; i++) { if(GetVehicleDistanceFromPoint(i, X, Y, Z) < distance && distance < 8.0) //you can change this value { vehicleid = i; distance = GetVehicleDistanceFromPoint(i, X, Y, Z); } } return vehicleid; } |
It's untested, but it should work fine...
pawn Код:
|