Engine & Lights system?
#1

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:

Код:
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;
}
Reply
#2

Bump. Maybe i'm asking too much.
At least some tips or links would be nice.
Reply
#3

https://sampwiki.blast.hk/wiki/ManualVehicleEngineAndLights
Reply
#4

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.

https://sampwiki.blast.hk/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().
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange

Then when you have made so the script detects when a player hits a key, use GetVehicleParamsEx().
https://sampwiki.blast.hk/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 Код:
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.
Reply
#5

Quote:
Originally Posted by OsteeN
Посмотреть сообщение
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.

https://sampwiki.blast.hk/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().
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange

Then when you have made so the script detects when a player hits a key, use GetVehicleParamsEx().
https://sampwiki.blast.hk/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 Код:
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)