SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 25/01/2016, 06:46 PM   #1
TwinkiDaBoss
Gangsta
 
Join Date: Jul 2014
Posts: 822
Reputation: 51
Default Simple Vehicle Functions

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 YLess for SSCANF http://forum.sa-mp.com/showthread.php?t=570927
Special credits to Zeex for ZCMD http://forum.sa-mp.com/showthread.php?t=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 !!

Last edited by TwinkiDaBoss; 25/01/2016 at 07:55 PM. Reason: Wrong tittle...
TwinkiDaBoss is offline   Reply With Quote
Old 25/01/2016, 07:10 PM   #2
Crayder
High-roller
 
Crayder's Avatar
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,867
Reputation: 570
Default Re: Simple Vehicle Functions

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:
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.
Code:
#if !defined COLOR_RED
//#define it
#endif

#if !defined IsValidVehicle
//Put the native here
#endif
__________________
Those who deserve reputation, do not need to beg for it.
Also, don't expect the help you need when offering reputation, you'll just be attracting Rep Hunters.
Join SA-MP Discord!
Crayder is offline   Reply With Quote
Old 25/01/2016, 07:15 PM   #3
TwinkiDaBoss
Gangsta
 
Join Date: Jul 2014
Posts: 822
Reputation: 51
Default Re: Simple Vehicle Functions

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:
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

Last edited by TwinkiDaBoss; 25/01/2016 at 07:56 PM.
TwinkiDaBoss is offline   Reply With Quote
Old 25/01/2016, 10:03 PM   #4
PT
Godfather
 
PT's Avatar
 
Join Date: Nov 2012
Location: Portugal
Posts: 7,092
Reputation: 736
Default Re: Simple Vehicle Functions

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

__________________
"Quem caiu e se levantou honrado era e honrado ficou..."


http://steamcommunity.com/id/pt_player/
PT is offline   Reply With Quote
Old 25/01/2016, 10:05 PM   #5
TwinkiDaBoss
Gangsta
 
Join Date: Jul 2014
Posts: 822
Reputation: 51
Default Re: Simple Vehicle Functions

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
TwinkiDaBoss is offline   Reply With Quote
Old 18/02/2016, 05:56 PM   #6
Spydah
High-roller
 
Spydah's Avatar
 
Join Date: Jan 2010
Location: The Netherlands
Posts: 1,424
Reputation: 741
Default Re: Simple Vehicle Functions

Very usefull, thank you!
__________________

Sexy isn't she?
I don't like +REP askers.
Spydah is offline   Reply With Quote
Old 18/02/2016, 09:19 PM   #7
Crayder
High-roller
 
Crayder's Avatar
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,867
Reputation: 570
Default Re: Simple Vehicle Functions

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.

Code:
#define GetVehicleEngineStatusString(%0) (v_EngineStatus[%0] == 0 ? ("Off") : ("On"))
__________________
Those who deserve reputation, do not need to beg for it.
Also, don't expect the help you need when offering reputation, you'll just be attracting Rep Hunters.
Join SA-MP Discord!
Crayder 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
[HELP] /engine 2 functions Stefand Scripting Help 2 03/06/2012 04:48 PM
[Include] Func - Simple Functions SmiT Includes 1 16/10/2011 10:12 AM
New Veh-Functions: Detect Engine Stas92 Help Archive 7 01/01/2011 03:19 PM
[Include] [INC] LSF - Lorenc's Simple Functions (w/ gang/clan functions) Lorenc_ Includes 11 03/05/2010 10:47 PM
[FilterScript] [FS] Vehicle Functions (Engine, Fuel, Car Names) Homerman Filterscripts 120 03/01/2010 11:22 AM


All times are GMT. The time now is 08:29 PM.


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