[HELP] OnPlayerKeyStateChange
#1

Good Morning,
First, I'm a beginner in Pawno Scripting, so, I have troubles in Making a Specific KEY to ' /enter ' & ' /exit '
And Also to Turn On/Off Engine on a vehicle ...
I tried a Lot, and I've read lots of tutorials, however, whenever I try to make 'em, I find myself trapped in errors..
Please I really need your help, Don't worry I will REP+ who ever will help me !

My Engine command is ' /Car engine '
Here is the code of the Engine Command if you ever need it :
Код:
CMD:car(playerid, params[])
{
	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;
		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);
		}
	}
	else if(strcmp(params, "lights", true) == 0 && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		new 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.");
		SetVehicleLights(vehicleid, playerid);
	}
	else if(strcmp(params, "hood", true) == 0 && IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			new vehicleid = GetPlayerVehicleID(playerid);
			if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510 || IsAPlane(vehicleid) || IsABike(vehicleid))
			{
				return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used in this vehicle.");
			}
			SetVehicleHood(vehicleid, playerid);
		}
		else if(!IsPlayerInAnyVehicle(playerid))
		{
			new closestcar = GetClosestCar(playerid);
			if(IsPlayerInRangeOfVehicle(playerid, closestcar, 5.0))
			{
				if(GetVehicleModel(closestcar) == 481 || GetVehicleModel(closestcar) == 509 || GetVehicleModel(closestcar) == 510 || IsAPlane(closestcar) || IsABike(closestcar))
				{
					return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used on this vehicle.");
				}
				SetVehicleHood(closestcar, playerid);
			}
		}
	}
	else if(strcmp(params, "trunk", true) == 0)
  	{
		if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			new 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.");
			}
			SetVehicleTrunk(vehicleid, playerid);
		}
		else if(!IsPlayerInAnyVehicle(playerid))
		{
			new closestcar = GetClosestCar(playerid);
			if(IsPlayerInRangeOfVehicle(playerid, closestcar, 5.0))
			{
				if(GetVehicleModel(closestcar) == 481 || GetVehicleModel(closestcar) == 509 || GetVehicleModel(closestcar) == 510)
				{
					return SendClientMessageEx(playerid,COLOR_WHITE,"This command can't be used on this vehicle.");
				}
				SetVehicleTrunk(closestcar, playerid);
			}
		}
	}
	else if(strcmp(params, "fuel", true) == 0 && IsPlayerInAnyVehicle(playerid))
	{
		if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 481 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
		if(GetPVarInt(playerid, "fuelonoff") == 0)
		{
			SendClientMessageEx(playerid, COLOR_WHITE, "You have turned on the fuel indicator (green bar).");
			SetPVarInt(playerid, "fuelonoff", 1);
			FuelBar[playerid] = CreateProgressBar(548.00, 26.00, 57.50, 3.20, 866792447, 100.0);
			textdrawscount++;
			SetProgressBarValue(FuelBar[playerid], VehicleFuel[GetPlayerVehicleID(playerid)]);
			ShowProgressBarForPlayer(playerid, FuelBar[playerid]);
		}
		else
		{
			SendClientMessageEx(playerid, COLOR_WHITE, "You have turned off the fuel indicator (green bar).");
			SetPVarInt(playerid, "fuelonoff", 0);
			DestroyProgressBar(FuelBar[playerid]);
			textdrawscount--;
			FuelBar[playerid] = INVALID_BAR_ID;
		}
	}
	else if(strcmp(params, "status", true) == 0)
	{
		if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			new vehicleid = GetPlayerVehicleID(playerid);
			new engine,lights,alarm,doors,bonnet,boot,objective,enginestatus[4],lightstatus[4], string[48];
			GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
			if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) return SendClientMessageEx(playerid,COLOR_RED,"This vehicle doesn't need fuel.");
			if(engine != VEHICLE_PARAMS_ON) format(enginestatus, sizeof(enginestatus), "OFF");
			else format(enginestatus, sizeof(enginestatus), "ON");
			if(lights != VEHICLE_PARAMS_ON) format(lightstatus, sizeof(lightstatus), "OFF");
			else format(lightstatus, sizeof(lightstatus), "ON");
			format(string, sizeof(string), "Engine: %s | Lights: %s | Fuel: %.2f.",enginestatus,lightstatus,VehicleFuel[vehicleid]);
			SendClientMessageEx(playerid, COLOR_WHITE, string);
		}
	}
	return 1;
}
And for the Enter/Exit Commands, They're ordinary.

Please, I need your help as fast as you can, And Thanks in Advance.
Reply
#2

tell me errors ? how the hell can i know :/ ?
Reply
#3

There is no errors..
I couldn't Create the Commands ...
I Wish someone could make it for me or just .. Can you tell me how I can make the Keys to /Enter and /Exit and the command /car engine with a Key ?
Reply
#4

For /car command:-
1. This and
2. This

For enter/exit command:-
1. This and
2. This and
3. This
Reply
#5

PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    {
        if (
newkeys KEY_FIRE)
        {
            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(vehicleidplayerid);
            }
            else if((
engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
            {
                
SendClientMessageEx(playeridCOLOR_WHITE"Vehicle engine starting, please wait...");
                
SetTimerEx("SetVehicleEngine"10000"dd"vehicleidplayerid);
            }
        }
    }
    return 
1;

And just like that with all.
Reply
#6

thats not his problem, he wants some kind of vehicle owner system, at least thats what i understood
Reply
#7

Quote:
Originally Posted by Whillyrez
Посмотреть сообщение
PHP код:
if (newkeys KEY_FIRE
And just like that with all.
Every time you activate NOS it will turn off and on the engine...
Reply
#8

Okey thanks everybody.. Whillyrez I'll try the code out now ..
Reply
#9

Off topic: Contact me on TS.
On topic: If you want a system, try this fs: https://sampforum.blast.hk/showthread.php?tid=197115 ,
It's good , tested.
Reply
#10

English please... Seriously though he's scripting, no need to show him a script to make him not learn and rely on others work...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)