command(tow, playerid, params[])
{
if(Groups[Player[playerid][Group]][CommandTypes] == 1 || Groups[Player[playerid][Group]][CommandTypes] == 4)
{
if(IsPlayerInAnyVehicle(playerid))
{
new Vehicle = GetPlayerVehicleID(playerid);
if(GetVehicleModel(Vehicle) == 525)
{
new VehicleToTow = GetClosestCar(playerid);
if(IsPlayerInRangeOfVehicle(playerid, VehicleToTow, 9.0))
{
print("calledbeforetow");
if(Player[playerid][TowingVehicle] == -1)
{
if(IsAPlane(VehicleToTow) || IsABike(VehicleToTow) || IsATrain(VehicleToTow) || IsAHelicopter(VehicleToTow))) return SendClientMessage(playerid, WHITE, "You can not tow this type of vehicle.");
AttachTrailerToVehicle(VehicleToTow, GetPlayerVehicleID(playerid));
Player[playerid][TowingVehicle] = VehicleToTow;
print("calledtow");
}
else
{
DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
Player[playerid][TowingVehicle] = -1;
print("calleduntow");
}
}
else
{
SendClientMessage(playerid, WHITE, "You are not near a vehicle!");
return 1;
}
}
else
{
SendClientMessage(playerid, WHITE, "You are not in a tow truck!");
return 1;
}
}
else
{
SendClientMessage(playerid, WHITE, "You are not in a tow truck!");
return 1;
}
}
return 1;
}
This will only work if both vehicles are streamed in for a player (check IsVehicleStreamedIn) |
Also check if "IsTrailerAttachedToVehicle" when you detach them.
Also have you tried different vehicle? might be a bugged one |
stock GetClosestCar(iPlayer, iException = INVALID_VEHICLE_ID, Float: fRange = Float: 0x7F800000) {
new
iReturnID = INVALID_VEHICLE_ID,
Float: fVehiclePos[4];
for(new i = 1; i <= MAX_VEHICLES; ++i) if(GetVehicleModel(i) && i != iException) {
GetVehiclePos(i, fVehiclePos[0], fVehiclePos[1], fVehiclePos[2]);
if((fVehiclePos[3] = GetPlayerDistanceFromPoint(iPlayer, fVehiclePos[0], fVehiclePos[1], fVehiclePos[2])) < fRange) {
fRange = fVehiclePos[3];
iReturnID = i;
}
}
return iReturnID;
}