[HELP] /tow
#1

So I create a system to /tow, however the problem is it isn't attaching the vehicle to the trailer. Here is the code.

pawn Код:
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;
}
The prints call, and everything works perfectly except the attachtrailertovehicle.

So when I /tow the first time, it says "calledtow", and when I /tow again it says "calleduntow" which is really weird seeming that its most likely a problem with the function AttachTrailerToVehicle

Help REP+
Reply
#2

Quote:

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
Reply
#3

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
Also check if "IsTrailerAttachedToVehicle" when you detach them.

Also have you tried different vehicle? might be a bugged one
Yes, and I just figured out the issue via printf.
Getting the closest vehicle just gets the vehicle I'm in, not the vehicle I'm wanting to tow.

Here's the stock:

pawn Код:
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;
}
EDIT: I've fixed it. Adding 'Vehicle' to the exception fixed it. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)