[Include] Extended vehicle functions
#1

Extended vehicle functions

Introduction

This is a useful set of vehicle functions that I've made recently. Some functions allow you to retrieve the offset of certain parts of a vehicle, and some are just for ordinary useful things.

Functions

A list of functions:

pawn Code:
// Returns the specified vehicle parameter.
stock GetVehicleParams(vehicleid, type);

// Sets the specified vehicle parameter to the specified status.
stock SetVehicleParams(vehicleid, type, status, time = 0);

// Get the position of the vehicle's boot.
stock GetVehicleBoot(vehicleid, &Float:x, &Float:y, &Float:z);

// Get the position of the vehicle's hood.
stock GetVehicleHood(vehicleid, &Float:x, &Float:y, &Float:z);

// Get the position of the vehicle's roof.
stock GetVehicleRoof(vehicleid, &Float:x, &Float:y, &Float:z);

// Returns two random colors for the specified model ID. Based on data from carcols.dat.
stock GetVehicleRandomColors(modelid, &color1, &color2);

// Returns a vehicle's colors.
stock GetVehicleColor(vehicleid, &color1, &color2);

// Returns a vehicle's paintjob. Returns INVALID_PAINTJOB_ID if there isn't any paintjob set.
stock GetVehiclePaintjob(vehicleid);

// Returns the vehicle's interior ID.
stock GetVehicleInterior(vehicleid);

// Returns the nearest vehicle ID.
stock GetNearestVehicle(playerid);

// Returns the player ID of the driver.
stock GetVehicleDriver(vehicleid);

// Returns the vehicle's top speed.
stock Float:GetVehicleTopSpeed(vehicleid);

// Returns the next available seat (or INVALID_SEAT_ID if there's none).
stock GetVehicleNextSeat(vehicleid, passenger = 1);

// Returns the maximum amount of seats for the vehicle.
stock GetVehicleSeats(vehicleid);

// Returns the maximum amount of seats for the vehicle model.
stock GetVehicleModelSeats(modelid);

// Returns 1 if the specified seat is taken.
stock IsVehicleSeatOccupied(vehicleid, seatid);


A list of callbacks:

pawn Code:
public OnVehicleCreated(vehicleid)
{
    return 1;
}

public OnVehicleDestroy(vehicleid)
{
    // Returning 0 in this callback will not destroy the vehicle.
    return 1;
}

public OnPlayerShootVehicle(playerid, vehicleid, weaponid)
{
    return 1;
}

public OnTrailerHooked(playerid, vehicleid, trailerid)
{
    return 1;
}

public OnTrailerUnhooked(playerid, vehicleid, trailerid)
{
    return 1;
}
List of types

These types are to be used with GetVehicleParams and SetVehicleParams.

pawn Code:
enum e_ParamTypes {
    VEHICLE_TYPE_ENGINE,
    VEHICLE_TYPE_LIGHTS,
    VEHICLE_TYPE_ALARM,
    VEHICLE_TYPE_DOORS,
    VEHICLE_TYPE_BONNET,
    VEHICLE_TYPE_BOOT,
    VEHICLE_TYPE_OBJECTIVE
};
How do I use it?

Simply download the include below and add it to your script.

pawn Code:
#include <EVF>


An example of use:

pawn Code:
new
    vehicleid = GetNearestVehicle(playerid),
    Float:x,
    Float:y,
    Float:z;

if (IsValidVehicle(vehicleid))
{
    GetVehicleBoot(vehicleid, x, y, z);

    if (IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
    {
        SendClientMessage(playerid, COLOR_WHITE, "You are standing near the trunk!");
    }
    return 1;
}


An engine command without any variables:

pawn Code:
CMD:engine(playerid, params[])
{
    new
        vehicleid = GetPlayerVehicleID(playerid);

    if (!GetVehicleParams(vehicleid, VEHICLE_TYPE_ENGINE))
    {
        SetVehicleParams(vehicleid, VEHICLE_TYPE_ENGINE, true);
    }
    else
    {
        SetVehicleParams(vehicleid, VEHICLE_TYPE_ENGINE, false);
    }
    return 1;
}
Other resources
GetVehicleColor by RyDeR`
Extended Vehicle Information by Vince

Download
Pastebin
Reply
#2

Woooaah .

Good work my shaggy friend.


PS: Pastebin.
Reply
#3

Quote:
Originally Posted by EnzoMetlc
View Post
Woooaah .


Good work my shaggy friend.


PS: Pastebin.
I almost forgot!

http://pastebin.com/bapPNrnT
Reply
#4

Another good release. But, what about camera positions? I don't know if it's released earlier or not, but would improve the include much more in case if there's GetVehicleRimPos(modelid, &Float:X, &Float:Y, &Float:Z) and so using it as camera positions. Like on NFS, when we're tuning, we could focus on the rims. (In case if tuning without the gta sa's default garages).
Reply
#5

I'm going to suggest implementing GetVehicleTopSpeed(vehicleid) so speedometers can be dynamically scaled you can read all about that here.

http://gtaforums.com/topic/216347-gt.../#entry3209126
Reply
#6

Nice man.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
View Post
I'm going to suggest implementing GetVehicleTopSpeed(vehicleid) so speedometers can be dynamically scaled you can read all about that here.

http://gtaforums.com/topic/216347-gt.../#entry3209126
Thanks a bunch!


I was thinking about a "kmh" parameter too. When false, it'll return the mph speed.
Reply
#8

Looks nice, good work.
Reply
#9

Suggestion: Add engine to start/stop with timer
Reply
#10

This is very usefull thanks
Reply
#11

I love you!!!! Player surfing are more acurate! Ty
Reply
#12

A really tiny suggestion:

pawn Код:
#if !defined SetVehicleInterior
 #define SetVehicleInterior EVF_LinkVehicleToInterior
#endif
Then it looks similar with SetPlayerInterior and GetVehicleInterior.
Reply
#13

Updated:

- Added GetVehicleDriver(vehicleid).
- Added SetVehicleInterior(vehicleid).
- Added GetVehicleTopSpeed(vehicleid, kmh = true);
- Added a "time" parameter to SetVehicleParams.

I will upload the script shortly.
Reply
#14

Updated:

- Added IsSeatOccupied(vehicleid, seatid).
- Added GetVehicleNextSeat(vehicleid).
- Added GetVehicleSeats(vehicleid).
- Added 2 new callbacks:

pawn Код:
public OnTrailerHooked(playerid, vehicleid, trailerid)
{
    return 1;
}

public OnTrailerUnhooked(playerid, vehicleid, trailerid)
{
    return 1;
}
Reply
#15

Hey nice glad to see my idea made it in!

@DobbysGamertag

Make sure you use the correct velocity calculation and don't directly ban only warn admins.
Reply
#16

I'll be making use of this, nice include!

I presume:

pawn Код:
stock Float:GetVehicleTopSpeed(vehicleid, bool:kmh = true);
can be used in anti-speed hacks?

Small suggestion:

I know you can "Destroy" single lights with encode_lights. Maybe a callback/function or two can be added

pawn Код:
ToggleVehicleIndicators(vehicleid,bool:toggle,indicator);
//toggle on/off
//indicator left / indicator right.
Reply
#17

@[uL]Pottus: No problem! I think it was a great idea for my speedometer script.

@DobbysGamertag: Great idea! I'll probably add a function for lights as well as something similar for tires: "SetVehicleTireState(vehicleid, tireid, bool:popped)".
Reply
#18

Updated:

- Added OnVehicleCreated(vehicleid).
- Added IsTirePopped(vehicleid, tireid).

I'll be adding "ToggleVehicleLight" as soon as I get home.
Reply
#19

You probably should also add a GetPositionFromOffset too, nice work !
Reply
#20

i think you forgot GetVehicleBonnet
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)