[Include] Simple Vehicle Functions
#1

Introductions
This script is mainly focused on begginer scripters as it gives you only small advantage and thats is time you would need to do this stuff.
I never planned to release this on SA:MP forums but since I seen some people struggle with getting vehicle parameters and such, I have decided to release it



Functions
PHP Code:
//Engines
ToggleVehicleEngine(vehiclestatus); //Set STATUS to 1 to turn it on or 0 to turn it off
GetVehicleEngineStatusString(vehicle); //returns string such as "On" or "Off" depending on engine status
GetVehicleEngineStatus(vehicle);  //Same as GetVehicleEngineStatusString but returns intergrer
AutomaticEngineSwitch(vehicle); //It will automaticly switch car engine on/off
//lights
ToggleVehicleLights(vehiclestatus); //Set STATUS to 1 to turn it on or 0 to turn it off
GetVehicleLightsStatusString(vehicle); //returns string such as "On" or "Off" depending on light status
GetVehicleLightsStatus(vehicle); //Same as GetVehicleLightsStatusString but returns intergrer
AutomaticLightSwitch(vehicle); //It will automaticly switch car lights on/off
//Trunks
ToggleVehicleTrunk(vehiclestatus); //Set STATUS to 1 to open it on or 0 to close it
GetVehicleTrunkStatusString(vehicle//returns string such as "Open" or "Closed" depending on trunk status
GetVehicleTrunkStatus(vehicle); //Same as GetVehicleTrunkStatusString but returns intergrer
ToggleNearestPlayerTrunk(playerid,status); //Set STATUS to 1 to open or 0 to close. It will open/close nearest vehicle trunk thats in range of 10 meters
ToggleAutomaticNearestTrunk(playerid); //It will automaticly open/close nearest vehicles trunk thats in range of 10 meters.
//Locks
ToggleVehicleLock(vehicle,status); //Set STATUS to 1 to lock car or 0 to unlock
GetVehicleLockStatusString(vehicle//returns string such as "Locked" or "Unlocked" depending on trunk status
GetVehicleLockStatus(vehicle//Same as GetVehicleLockStatusString but returns intergrer
ToggleNarestVehicleLock(playerid//this will lock/unlock narest player vehicle automaticly
GetNearCarLockString(playerid//this will get status of vehicle locks that is nearest to the player (10 meters) and return in a string "Locked" or "Unlocked"
GetNearCarLock(playerid//this will get status of vehicle lock that is nearest to the player (10 meters) and return it as an int. 0 as unlocked, 1 as locked 

Callbacks
PHP Code:
public OnVehicleStart(vehicleid)
public 
OnVehicleStop(vehicleid)
public 
OnVehicleLock(vehicleid)
public 
OnVehicleUnlock(vehicleid
Example script
Example MANUAL scripts. These are commands that require of player to type in for example /engine on to start it etc.
ZCMD + SSCANF (Manual system with ON and OFF) http://pastebin.com/udbZggS2

Example AUTOMATIC script. These commands are the ones that dont require any sort of player parameter setting. Automatic engine etc.
ZCMD http://pastebin.com/t9hbvh1w



Credits
Special credits to SA:MP dev team
Special credits & thanks to Xalphox for teaching me how to script
Special credits to ***** for SSCANF https://sampforum.blast.hk/showthread.php?tid=570927
Special credits to Zeex for ZCMD https://sampforum.blast.hk/showthread.php?tid=91354
Special credits to Jeff for getting closest vehicle
Special credits to Crayder for all the help and support



Download
v.1.1 http://pastebin.com/BMAbCgv6
v.1.0 http://pastebin.com/U8Qz1D4U



Bugs
None found yet



Updates
v.1.1
  • Added callback public OnVehicleStart(vehicleid)
  • Added callback public OnVehicleStop(vehicleid)
  • Added lock functionality
  • Example code for v1.1: http://pastebin.com/zLyibUuE
  • Added if defined (Thanks to Crayder) so there wont be any errors or warnings with this


v.1.0 http://pastebin.com/U8Qz1D4U



Plan
This is not 100% finished, im still working on some parts for it. For now its just a basic include but I plan to expand it a lot more for better vehicle detection




NOTE
FOR SOME PARTS OF THIS CODE TO WORK MAKE SURE YOU HAVE ManualVehicleEngineAndLights(); SET ONGAMEMODEINIT !!
Reply
#2

I suggest adding part fixing.

Check this out:
http://forum.sa-mp.com/showpost.php?&p=3646664

You could use the code from any of those lines. Like a FixWindshield function:
pawn Code:
stock FixWindshield(vehicleid) {
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    return UpdateVehicleDamageStatus(vehicleid, panels & 0xFFFF00FFFFFFFF, doors, lights, tires);
}
About about this:
Quote:

Script saying "error 017: undefined symbol "COLOR_RED". Add to top of your script #define COLOR_RED 0xAA3333AA
Script saying "error 021: symbol already defined: "IsValidVehicle". Remove native IsValidVehicle(vehicleid); from the script

You can easily use #if's here.
pawn Code:
#if !defined COLOR_RED
//#define it
#endif

#if !defined IsValidVehicle
//Put the native here
#endif
Reply
#3

Quote:
Originally Posted by Crayder
View Post
I suggest adding part fixing.

Check this out:
http://forum.sa-mp.com/showpost.php?&p=3646664

You could use the code from any of those lines. Like a FixWindshield function:
pawn Code:
stock FixWindshield(vehicleid) {
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    return UpdateVehicleDamageStatus(vehicleid, panels & 0xFFFF00FFFFFFFF, doors, lights, tires);
}
Yeah thanks for reminding me, I do plan to add this, just I gotta go over all basics first, my plan is to finish off the list with all SetVehicleParamsEx first and then move onto some more advanced stuff, but thanks still, I plan to add it



UPDATE:
Quote:

Updates
v.1.1
Added callback public OnVehicleStart(vehicleid)
Added callback public OnVehicleStop(vehicleid)
Added lock functionality
Example code for v1.1: http://pastebin.com/zLyibUuE
Added if defined (Thanks to Crayder) so there wont be any errors or warnings with this

Reply
#4

PHP Code:
stock GetVehicleEngineStatusString(vehicle
{
    new 
StatusString[4];
    return 
v_EngineStatus[vehicle] == ? (StatusString "Off") : (StatusString "On");

Reply
#5

Quote:
Originally Posted by PT
View Post
PHP Code:
stock GetVehicleEngineStatusString(vehicle
{
    new 
StatusString[4];
    return 
v_EngineStatus[vehicle] == ? (StatusString "Off") : (StatusString "On");

Yeah I get you but I preffer switch way, kinda easier for me to track down etc.
Might not be the best way, but its the best way for me to keep a track of it, tho thanks for the feedback
Reply
#6

Very usefull, thank you!
Reply
#7

Quote:
Originally Posted by PT
View Post
PHP Code:
stock GetVehicleEngineStatusString(vehicle
{
    new 
StatusString[4];
    return 
v_EngineStatus[vehicle] == ? (StatusString "Off") : (StatusString "On");

Why use a variable at all? If it was to get around the compiler's string problem all you gotta do is wrap it in parenthesis.

pawn Code:
#define GetVehicleEngineStatusString(%0) (v_EngineStatus[%0] == 0 ? ("Off") : ("On"))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)