SA-MP Forums Archive
[Help] OnPlayerKeyStateChange I need a help please - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help] OnPlayerKeyStateChange I need a help please (/showthread.php?tid=328950)



[Help] OnPlayerKeyStateChange I need a help please - Emil123 - 26.03.2012

so i have this filterscript http://www.fileden.com/files/2008/9/...peedometer.rar and i will to make when i press the key ,,2'' to start engine and when i press ,,2'' again to engine off ...now i must type /engine on and /engine off can someone help me and type what i exactly to do...

btw... sory im from Macedonia sorry for my mistakes

the script:




ah...and can someone say me why when i have 17 or more filterscripts it loads only 16 filterscript what can i do? :unhappy:


Re: [Help] OnPlayerKeyStateChange I need a help please - The DeLuca - 26.03.2012

Here's a real basic system that will start/stop the engine when you press the submission key, or "2".

Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SUBMISSION))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
        	new vehid;
	        vehid = GetPlayerVehicleID(playerid);
	        new
			iEngine, iLights, iAlarm,
			iDoors, iBonnet, iBoot,
			iObjective;
			GetVehicleParamsEx(vehid, iEngine, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
			if(iEngine == 1) // Engine is on
			{
				SetVehicleParamsEx(vehid, 0, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective); // Turn it off
				return 1;
			}
			else // Engine is off
			{
			    SetVehicleParamsEx(vehid, 1, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective); // Turn it on
			    return 1;
			}
		}
	}
	return 1;
}



Re: [Help] OnPlayerKeyStateChange I need a help please - Emil123 - 26.03.2012

hey tnx very man but....
so when i press ,,2''' it is good but when i press ,,2'' it turn off the engine yes but I want to be the same like /engine on or /engine off i will to show on the screen the engine turned on... engine turned off... and i will to must be waiting 2-3 seconds to the engine starts on like /engine on and /engine off


Can you make this for me please im a noob i know


And why when i enter in the vehicle i must first type /engine on and then i can pressing ,,2'' ... why must i type first /engine on ?


Re: [Help] OnPlayerKeyStateChange I need a help please - The DeLuca - 26.03.2012

Alright here you go. With this, you just have to press "2" and then it'll say "Starting vehicle..." and after three seconds the engine will either start or fail with a 50/50 chance rate.

Code:
// Put this at the top of your script
forward StartEngine(playerid);

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SUBMISSION))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
        	new vehid;
	        vehid = GetPlayerVehicleID(playerid);
	        new
			iEngine, iLights, iAlarm,
			iDoors, iBonnet, iBoot,
			iObjective;
			GetVehicleParamsEx(vehid, iEngine, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
			new name[MAX_PLAYER_NAME];
   			GetPlayerName(playerid, name, sizeof(name));
   			new string[200];
			if(iEngine == 1) // Engine is on
			{
			    SetTimerEx("StartEngine", 3000, 0, "i", playerid);
	            SendClientMessage(playerid, COLOR_GREEN, "** [Hint]: Vehicle engine starting");
	            format(string, sizeof(string), "* %s turns the key of the vehicle attempting to start it", name);
				ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				return 1;
			}
			else // Engine is off
			{
			    SetVehicleParamsEx(vehid, 0, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
	            SendClientMessage(playerid, COLOR_GOLD, "** [Hint]: Vehicle engine stopped");
	            SendClientMessage(playerid, COLOR_GOLD, "** To re-start the vehicle's engine press '2'");
	            format(string, sizeof(string), "* %s turns the key of the vehicle shutting it {FF0000}[OFF]", name);
				ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			    return 1;
			}
		}
	}
	return 1;
}

public StartEngine(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new rand = random(2);
    new
	iEngine, iLights, iAlarm,
	iDoors, iBonnet, iBoot,
	iObjective;
	GetVehicleParamsEx(vehicleid, iEngine, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
    if(IsPlayerInAnyVehicle(playerid))
    {
    	if(iEngine == 0) // Engine is off
    	{
	    	new vmodel[128];
		    new string[240];
			GetVehicleName(vehicleid,vmodel,sizeof(vmodel));
			if(rand == 0)
			{
   				SetVehicleParamsEx(vehicleid, 1, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
			    SetTimerEx("DamagedEngine", 1000, 1, "i", playerid);
			    format(string, sizeof(string), "* The engine of the %s succeeds and turns{37DB45} [ON]",vmodel);
				ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
 			}
 			if(rand == 1)
 			{
    			SetVehicleParamsEx(vehicleid, 0, iLights, iAlarm, iDoors, iBonnet, iBoot, iObjective);
			    format(string, sizeof(string), "* The engine of the %s fails and remains{FF0000} [OFF]",vmodel);
				ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
 			}
    	}
    }
    return 1;
}



Re: [Help] OnPlayerKeyStateChange I need a help please - Emil123 - 26.03.2012

oohh... im not lucky i've got 5 errors http://pic.mk/images/bHMOK.png
i puted the forward StartEngine(playerid); at the top and then the other at the end...
i downloaded the script from here http://www.fileden.com/files/2008/9/...peedometer.rar (mine is just translated....)
what can i do please help me if you help me you are the best


Re: [Help] OnPlayerKeyStateChange I need a help please - The DeLuca - 26.03.2012

Ah alrighty lets fix those.

Code:
// Put this at the top of your script as well
forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);

//Put this somewhere in your script
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
	if(IsPlayerConnected(playerid))
	{
		new Float:posx, Float:posy, Float:posz;
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		GetPlayerPos(playerid, oldposx, oldposy, oldposz);
		//radi = 2.0; //Trigger Radius
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
			{
				if(!BigEar[i])
				{
					GetPlayerPos(i, posx, posy, posz);
					tempposx = (oldposx -posx);
					tempposy = (oldposy -posy);
					tempposz = (oldposz -posz);
					//printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
					if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
					{
						SendClientMessage(i, col1, string);
					}
					else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
					{
						SendClientMessage(i, col2, string);
					}
					else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
					{
						SendClientMessage(i, col3, string);
					}
					else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
					{
						SendClientMessage(i, col4, string);
					}
					else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
					{
						SendClientMessage(i, col5, string);
					}
				}
				else
				{
					SendClientMessage(i, col1, string);
				}
			}
		}
	}//not connected
	return 1;
}



Re: [Help] OnPlayerKeyStateChange I need a help please - Emil123 - 26.03.2012

i've got 4 errors now http://pic.mk/images/Lmen0.png oh noo im not lucky aaa please help mee i want when i press ,,2'' to be start so with /engine on and /engine on just with pressing ,,2'' '(


Re: [Help] OnPlayerKeyStateChange I need a help please - The DeLuca - 26.03.2012

Just put
Code:
new BigEar[MAX_PLAYERS];
somewhere on the top of your script for now to fix it.


Re: [Help] OnPlayerKeyStateChange I need a help please - Emil123 - 27.03.2012

Hey Tnx Tnx very muchhh butt... sorry if I bother you but I have another problem...Now its all good i have not erroars but only wants to engine off and not to /engine on pic: http://pic.mk/images/dJoKM.png
why?

please i need your help please

and sorry if i make mistakes..


Re: [Help] OnPlayerKeyStateChange I need a help please - [ABK]Antonio - 27.03.2012

that's because he has it backwards for turning on / off & turning on doesn't set the engine to 1