trailer attached to truck
#1

Hello, i have a question, how can i check if player attached a petrol trailer to their truck?
Reply
#2

Attach them using this:
https://sampwiki.blast.hk/wiki/AttachTrailerToVehicle

Figure out the trailer using:
https://sampwiki.blast.hk/wiki/IsTrailerAttachedToVehicle
https://sampwiki.blast.hk/wiki/GetVehicleTrailer

You basically define the petrol trailer to a variable and then attach said variable to your vehicle. You can then use that variable to check the attached vehicle trailer.

EDIT: Something like this (as an example, it's done very uneffectively so I suggest you to re-write it):

pawn Code:
#include <a_samp>
#include <zcmd>

new truck;
new oiltrailer;
new petroltrailer;

public OnGameModeInit()
{
    truck = CreateVehicle(0, 0.00, 0.00, 0.00, 0.00, 0, 0, -1); // truck ID

    oiltrailer = CreateVehicle(0, 0.00, 0.00, 0.00, 0.00, 0, 0, -1); // trailer ID
    petroltrailer = CreateVehicle(0, 0.00, 0.00, 0.00, 0.00, 0, 0, -1); // trailer ID
}

CMD:attachtrailer(playerid, params[])
{
    new Float: aX, Float: aY, Float: aZ, Float: bX, Float: bY, Float: bZ;
    GetVehiclePos(oiltrailer, aX, aY, aZ), GetVehiclePos(petroltrailer, bX, bY, bZ);

    if(IsPlayerInVehicle(playerid, truck)) return SendClientMessage(playerid, -1, "You need to be in a truck!");

    if(IsPlayerInRangeOfPoint(playerid, 5.0, aX, aY, aZ)) AttachTrailerToVehicle(oiltrailer, truck);
    if(IsPlayerInRangeOfPoint(playerid, 5.0, bX, bY, bZ)) AttachTrailerToVehicle(petroltrailer, truck);

    SendClientMessage(playerid, -1, "You've attached the trailer to your truck!");

    return 1;
}

CMD:checktrailer(playerid, params[])
{
    if(IsPlayerInVehicle(playerid, truck)) return SendClientMessage(playerid, -1, "You need to be in a truck!");

    if(GetVehicleTrailer(GetPlayerVehicleID(playerid)) == oiltrailer)
    {
        SendClientMessage(playerid, -1, "You're transporting the oil trailer!");
    }
   
    else if(GetVehicleTrailer(GetPlayerVehicleID(playerid)) == petroltrailer)
    {
        SendClientMessage(playerid, -1, "You're transporting the petrol trailer!");
    }

    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)