SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/04/2014, 01:34 PM   #1
WardenCS
Gangsta
 
WardenCS's Avatar
 
Join Date: Feb 2009
Posts: 899
Reputation: 14
Default trailer attached to truck

Hello, i have a question, how can i check if player attached a petrol trailer to their truck?
WardenCS is offline   Reply With Quote
Old 28/04/2014, 01:40 PM   #2
Dignity
High-roller
 
Dignity's Avatar
 
Join Date: May 2013
Location: Belgium
Posts: 1,616
Reputation: 1163
Default Re: trailer attached to truck

Attach them using this:
http://wiki.sa-mp.com/wiki/AttachTrailerToVehicle

Figure out the trailer using:
http://wiki.sa-mp.com/wiki/IsTrailerAttachedToVehicle
http://wiki.sa-mp.com/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;
}

Last edited by Dignity; 28/04/2014 at 02:17 PM.
Dignity is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
After detaching trailer from vehicle sometimes other users see trailer attached to vehicle diclofoss Bug Reports 0 26/03/2014 02:35 PM
Getting Trailer model id when attached to truck Tom1412 Scripting Help 2 06/05/2012 03:58 PM
If trailer is attached milanosie Scripting Help 3 11/01/2012 03:39 PM
Trailer is not being attached. WooTFTW Help Archive 3 08/08/2011 11:55 AM
truck to trailer Ky_Bob Help Archive 3 06/09/2010 02:35 PM


All times are GMT. The time now is 07:28 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.