SA-MP Forums Archive
Problem AttachTrailerToVehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem AttachTrailerToVehicle (/showthread.php?tid=559592)



Problem AttachTrailerToVehicle - Johnny_Ionut - 24.01.2015

Hello!

pawn Код:
CMD:attach(playerid, params[])
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
        for(new v=0;v<MAX_VEHICLES; v++) {
            GetVehiclePos(v,X,Y,Z);
            if(IsPlayerInRangeOfPoint(playerid, 6.0, X,Y,Z)) {
                if(!IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid))) AttachTrailerToVehicle(v,GetPlayerVehicleID(playerid));
                else DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
            } else SendClientMessage(playerid, -1, "No caravan at your finger");
        }
        return 1;
    }
How can I order it to attach only ID 607 vehicle (trailer)?


Re: Problem AttachTrailerToVehicle - Threshold - 24.01.2015

pawn Код:
CMD:attach(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(!vehicleid) return 1; //Player is not in a vehicle
    if(IsTrailerAttachedToVehicle(vehicleid)) DetachTrailerFromVehicle(vehicleid);
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    for(new v = 1; v <= MAX_VEHICLES; v++)
    {
        if(GetVehicleModel(v) != 607) continue;
        GetVehiclePos(v, X, Y, Z);
        if(!IsPlayerInRangeOfPoint(playerid, 6.0, X, Y, Z)) continue;
        AttachTrailerToVehicle(v, vehicleid);
        return 1;
    }
    SendClientMessage(playerid, -1, "No caravan at your finger");
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/GetVehicleModel
https://sampwiki.blast.hk/wiki/Control_Structures#continue


Re: Problem AttachTrailerToVehicle - Johnny_Ionut - 24.01.2015

Quote:
Originally Posted by Threshold
Посмотреть сообщение
pawn Код:
CMD:attach(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(!vehicleid) return 1; //Player is not in a vehicle
    if(IsTrailerAttachedToVehicle(vehicleid)) DetachTrailerFromVehicle(vehicleid);
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    for(new v = 1; v <= MAX_VEHICLES; v++)
    {
        if(GetVehicleModel(v) != 607) continue;
        GetVehiclePos(v, X, Y, Z);
        if(!IsPlayerInRangeOfPoint(playerid, 6.0, X, Y, Z)) continue;
        AttachTrailerToVehicle(v, vehicleid);
        return 1;
    }
    SendClientMessage(playerid, -1, "No caravan at your finger");
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/GetVehicleModel
https://sampwiki.blast.hk/wiki/Control_Structures#continue
Not unlinked trailer but was resolved. Thanks +1.