SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 07/12/2014, 07:51 AM   #1
MrBlake
Big Clucker
 
Join Date: Jan 2011
Posts: 120
Reputation: 0
Default Engine & Lights system?

I have a RPG gamemode and I need an engine & lights system for vehicles.
I didn't find a well explained tutorial, so if anyone could help, it would be great.

What I want?
- When server starts, all engines should be turned OFF
- While turned off, the vehicle shouldn't use FUEL (I have a fuel system)
- Lights should turn on/off using a KEY (maybe CTRL??)
- Engine could have an /engine command, but a key would be also good.


Fuel:

Code:
public CheckGas()
{
	new string[256];
	for(new i=0;i<MAX_PLAYERS;i++)
	{
    	if(IsPlayerConnected(i))
       	{
       	    if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
       	    {
	       		new vehicle = GetPlayerVehicleID(i);
	        	if(Gas[vehicle] >= 1)
		   		{
		   		    if(Gas[vehicle] <= 10) { PlayerPlaySound(i, 1085, 0.0, 0.0, 0.0); }
		   		    if(gGas[i] == 1) {
		   		    if(IsAPlane(vehicle) || IsABoat(vehicle) || IsABike(vehicle) || IsASC(vehicle))
		   		    {
		      			format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~Fuel: ~g~None");
					}
					else
		      		format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~Fuel: ~g~%d%",Gas[vehicle]);
		      		GameTextForPlayer(i,string,15500,3); }
					if(IsAPlane(vehicle) || IsABoat(vehicle) || IsABike(vehicle) || IsASC(vehicle)) { Gas[vehicle]++; }
	              	Gas[vehicle]--;
		   		}
	   			else
	           	{
	              	NoFuel[i] = 1;
	              	TogglePlayerControllable(i, 0);
		        	GameTextForPlayer(i,"~n~~n~~n~~n~~n~~n~~n~~w~NO FUEL ~n~ USE /EXIT",1500,3);
				}
			}
    	}
	}
	return 1;
}
MrBlake is offline   Reply With Quote
Old 07/12/2014, 11:44 AM   #2
MrBlake
Big Clucker
 
Join Date: Jan 2011
Posts: 120
Reputation: 0
Default Re: Engine & Lights system?

Bump. Maybe i'm asking too much.
At least some tips or links would be nice.
MrBlake is offline   Reply With Quote
Old 07/12/2014, 01:31 PM   #3
Vukilore
Huge Clucker
 
Vukilore's Avatar
 
Join Date: Jan 2011
Location: http://forum.sa-mp-fr.com/index.php
Posts: 300
Reputation: 110
Default Re : Engine & Lights system?

http://wiki.sa-mp.com/wiki/ManualVehicleEngineAndLights
__________________
http://forum.sa-mp-fr.com/index.php. << here rest the french forum, in piece.
Vukilore is offline   Reply With Quote
Old 07/12/2014, 02:29 PM   #4
OsteeN
Big Clucker
 
Join Date: Dec 2012
Location: Sweden
Posts: 91
Reputation: 14
Default Re: Re : Engine & Lights system?

OP, I will not script it for you, however I'll (hopefully) point you in the right directions.

Quote:
Originally Posted by Vukilore View Post
Use this to allow the script to manually handle the engine & lights of vehicles.

http://wiki.sa-mp.com/wiki/SetVehicleParamsEx
I use this under the OnVehicleSpawn() callback (to set engine & lights to 0) & under my '/engine' & '/lights' commands. (to toggle them)

However, you want to toggle it by a key press, so you would use the callback OnPlayerKeyStateChange().
http://wiki.sa-mp.com/wiki/OnPlayerKeyStateChange

Then when you have made so the script detects when a player hits a key, use GetVehicleParamsEx().
http://wiki.sa-mp.com/wiki/GetVehicleParamsEx
Use it to take the information from the vehicle that the player currently is in. (if he is, use IsPlayerInAnyVehicle() to check this, perhaps? )

Then you could just do something like:
pawn Code:
if(engine)
{
      // Set the engine of the vehicle to 0 using SetVehicleParamsEx().
} else {
     // Set the engine of the vehicle to 1 using SetVehicleParamsEx().
}
Now do the same thing for lights.
About the fuel; you could have a timer that will run every X milliseconds, I.E every 10 seconds, and check each vehicle if the engine is on; deduct fuel of the vehicle. (for this you would have to declare a Fuel[MAX_VEHICLES] of some sort, and OnVehicleSpawn(), set it to like.. 100. (this is all up to you)

Of course you could have a WAY more complicated system, but this is a very, very basic one you could create, then once you feel comfortable with those things, you could expand it.

Feel free to post again if you have more questions.
Sorry if I'm posting a clusterfuck of stuff that might make no sense; I'm tired.
OsteeN is offline   Reply With Quote
Old 07/12/2014, 03:36 PM   #5
MrBlake
Big Clucker
 
Join Date: Jan 2011
Posts: 120
Reputation: 0
Default Re: Re : Engine & Lights system?

Quote:
Originally Posted by OsteeN View Post
OP, I will not script it for you, however I'll (hopefully) point you in the right directions.


Use this to allow the script to manually handle the engine & lights of vehicles.

http://wiki.sa-mp.com/wiki/SetVehicleParamsEx
I use this under the OnVehicleSpawn() callback (to set engine & lights to 0) & under my '/engine' & '/lights' commands. (to toggle them)

However, you want to toggle it by a key press, so you would use the callback OnPlayerKeyStateChange().
http://wiki.sa-mp.com/wiki/OnPlayerKeyStateChange

Then when you have made so the script detects when a player hits a key, use GetVehicleParamsEx().
http://wiki.sa-mp.com/wiki/GetVehicleParamsEx
Use it to take the information from the vehicle that the player currently is in. (if he is, use IsPlayerInAnyVehicle() to check this, perhaps? )

Then you could just do something like:
pawn Code:
if(engine)
{
      // Set the engine of the vehicle to 0 using SetVehicleParamsEx().
} else {
     // Set the engine of the vehicle to 1 using SetVehicleParamsEx().
}
Now do the same thing for lights.
About the fuel; you could have a timer that will run every X milliseconds, I.E every 10 seconds, and check each vehicle if the engine is on; deduct fuel of the vehicle. (for this you would have to declare a Fuel[MAX_VEHICLES] of some sort, and OnVehicleSpawn(), set it to like.. 100. (this is all up to you)

Of course you could have a WAY more complicated system, but this is a very, very basic one you could create, then once you feel comfortable with those things, you could expand it.

Feel free to post again if you have more questions.
Sorry if I'm posting a clusterfuck of stuff that might make no sense; I'm tired.
Rep+

I'll work on that, thanks.
MrBlake 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
[Tutorial] Vehicle System "Engine & Lights". Gogeta Tutorials 8 27/08/2020 12:08 PM
Engine & Lights with 2 Rudiz Scripting Help 4 06/02/2014 06:37 PM
Car Lights and Engine System Uberanwar Scripting Help 3 14/08/2013 11:00 AM
[HELP] with /engine and /lights Stefand Scripting Help 1 03/06/2012 03:11 PM
[FilterScript] PFuel & Engine & Lights system Phanto90 Filterscripts 68 07/09/2011 12:30 AM


All times are GMT. The time now is 01:11 AM.


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