Start Car Engine with Hotkey [PLEASE HELP]
#1

Hey please help me, in my server we use /car engine to start the engine.

i want adding methods to turn the engine on with pressing any Key like (SHIFT) but still can use /car engine

can you help me, i will show the code. thanks

Код:
CMD:car(playerid, params[])
{
    new rand = random(2);
	if(isnull(params))
	{
		SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /car [name]");
		SendClientMessageEx(playerid, COLOR_GREY, "Available names: Status, Engine, Lights, Trunk, Hood, Fuel");
		return 1;
	}
	if(strcmp(params, "engine", true) == 0 && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		new engine,lights,alarm,doors,bonnet,boot,objective,vehicleid;
		new string[128];
		vehicleid = GetPlayerVehicleID(playerid);
		if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
		GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
		if(engine == VEHICLE_PARAMS_ON)
		{
			SetVehicleEngine(vehicleid, playerid);
		}
		else if((engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
		{
/*			SendClientMessageEx(playerid, COLOR_WHITE, "Vehicle engine starting, please wait...");
			SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);*/
           if(rand == 0)
		   {
			   SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
			   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine started");
		       format(string, sizeof(string), "* %s has started his vehicle's engine",  GetPlayerNameEx(playerid));
       		   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
		   }
		   if(rand == 1)
		   {
			   SendClientMessage(playerid, COLOR_TWYELLOW, "Vehicle engine failed to start");
			   format(string, sizeof(string), "* %s struggles to start the engine but fails",  GetPlayerNameEx(playerid));
    		   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
		   }
		}
	}
Reply
#2

On top:
Код:
#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
OnPlayerKeyStateChange function:
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if (PRESSED(KEY_JUMP))
	{
	  new engine,lights,alarm,doors,bonnet,boot,objective,vehicleid;
	  vehicleid = GetPlayerVehicleID(playerid);
	  if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
		GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
		if(engine == VEHICLE_PARAMS_ON)
		{
			SetVehicleEngine(vehicleid, playerid);
		}
		else if((engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
		{
			SendClientMessageEx(playerid, COLOR_WHITE, "Mesin mobil sedang dinyalakan, mohon tunggu...");
			SetTimerEx("SetVehicleEngine", 1000, 0, "dd",  vehicleid, playerid);
		}
	}	
	return 1;
}
Reply
#3

thank you all worked fine. But how to make enter building with keys like that. is it the same ?

look my code in this thread. https://sampforum.blast.hk/showthread.php?tid=609124 please help thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)