Extended vehicle functions - Emmet_ - 06.01.2014
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.
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
Respuesta: Extended vehicle functions -
Swedky - 06.01.2014
Woooaah .
Good work my shaggy friend.
PS: Pastebin.
Re: Respuesta: Extended vehicle functions - Emmet_ - 07.01.2014
I almost forgot!
http://pastebin.com/bapPNrnT
Re: Extended vehicle functions -
Lordzy - 07.01.2014
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).
Re: Extended vehicle functions -
Pottus - 07.01.2014
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
Re: Extended vehicle functions -
EiresJason - 07.01.2014
Nice man.
Re: Extended vehicle functions - Emmet_ - 07.01.2014
Quote:
Originally Posted by [uL]Pottus
|
Thanks a bunch!
I was thinking about a "kmh" parameter too. When false, it'll return the mph speed.
Re: Extended vehicle functions -
iZN - 07.01.2014
Looks nice, good work.
Re: Extended vehicle functions -
RenSoprano - 07.01.2014
Suggestion: Add engine to start/stop with timer
Re: Extended vehicle functions -
PT - 07.01.2014
This is very usefull thanks
Re: Extended vehicle functions -
TheArcher - 07.01.2014
I love you!!!! Player surfing are more acurate!
Ty
Re: Extended vehicle functions -
kristo - 08.01.2014
A really tiny suggestion:
pawn Код:
#if !defined SetVehicleInterior
#define SetVehicleInterior EVF_LinkVehicleToInterior
#endif
Then it looks similar with SetPlayerInterior and GetVehicleInterior.
Re: Extended vehicle functions - Emmet_ - 09.01.2014
Updated:
- Added GetVehicleDriver(vehicleid).
- Added SetVehicleInterior(vehicleid).
- Added GetVehicleTopSpeed(vehicleid, kmh = true);
- Added a "time" parameter to SetVehicleParams.
I will upload the script shortly.
Re: Extended vehicle functions - Emmet_ - 18.01.2014
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;
}
Re: Extended vehicle functions -
Pottus - 18.01.2014
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.
Re: Extended vehicle functions -
DobbysGamertag - 18.01.2014
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.
Re: Extended vehicle functions - Emmet_ - 20.01.2014
@[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)".
Re: Extended vehicle functions - Emmet_ - 22.01.2014
Updated:
- Added OnVehicleCreated(vehicleid).
- Added IsTirePopped(vehicleid, tireid).
I'll be adding "ToggleVehicleLight" as soon as I get home.
Re: Extended vehicle functions -
RajatPawar - 22.01.2014
You probably should also add a GetPositionFromOffset too, nice work !
Re: Extended vehicle functions -
DeathKing - 30.01.2014
i think you forgot GetVehicleBonnet