Engine On/Off
#1

ok, the problem is that it wont turn off the engine, why?


Код:
  new string[256];
	new pveh = GetVehicleModel(GetPlayerVehicleID(playerid));
	new newcar = GetPlayerVehicleID(playerid);
	
  if(newkeys & KEY_WALK)
  {
    if(IsPlayerInAnyVehicle(playerid))
    {
			if(IsPlayerConnected(playerid))
			{
				if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) {
				return 1; }
				if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) {
				return 1; }
        if(!engineOn[GetPlayerVehicleID(playerid)])
				{
					PutPlayerInVehicle(playerid, newcar, 0);
					GetPlayerName(playerid, sendername, sizeof(sendername));
					format(string, sizeof(string), "* %s tries to start the engine.", sendername);
					ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
					SetTimerEx("StartingTheVehicle",3500,0,"i",playerid);
					gEngine[playerid] = 1;
					return 1;
			  }
        else if(gEngine[playerid] == 1)
	  	  {
					engineOn[GetPlayerVehicleID(playerid)] = false;
					//RemovePlayerFromVehicle(playerid);
					TogglePlayerControllable(playerid, 0);
					GetPlayerName(playerid, sendername, sizeof(sendername));
					format(string, sizeof(string), "* %s turns off the engine.", sendername);
					ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
					gEngine[playerid] = 0;
					return 1;
				}
			}
		}
  }
Reply
#2

anyone?
Reply
#3

Here are two errors:

Код:
if(newkeys == KEY_WALK)
Firstly, you are checking for newkeys with &, not with ==.

And at the other hand, I dont think there is a key like "KEY_WALK" - go to wiki.sa-mp.com, search for "GetPlayerKeys" and grab the key definition of your desired key.

Corrected version, using the Mouse LMB for the engine:

Код:
if(newkeys & KEY_FIRE)
Reply
#4

Quote:
Originally Posted by Mo3
Here are two errors:

Код:
if(newkeys == KEY_WALK)
Firstly, you are checking for newkeys with &, not with ==.

And at the other hand, I dont think there is a key like "KEY_WALK" - go to wiki.sa-mp.com, search for "GetPlayerKeys" and grab the key definition of your desired key.

Corrected version, using the Mouse LMB for the engine:

Код:
if(newkeys & KEY_FIRE)
== works and the KEY_WALK also work(ALT) but when i turn the engine on it won't turn off the engine thats the prob.
Reply
#5

Quote:
Originally Posted by Samp wiki ;)
How NOT to check for a key

Lets presume that you want to detect when a player presses their FIRE button, the obvious code would be:

if (newkeys == KEY_FIRE)

This code may even work in your testing, but it is wrong and your testing is insufficient. Try crouching and pressing fire - your code will instantly stop working. Why? Because "newkeys" is no longer the same as "KEY_FIRE", it is the same as "KEY_FIRE" COMBINED WITH "KEY_CROUCH".
Reply
#6

Quote:
Originally Posted by [HiC
TheKiller ]
Quote:
Originally Posted by Samp wiki ;)
How NOT to check for a key

Lets presume that you want to detect when a player presses their FIRE button, the obvious code would be:

if (newkeys == KEY_FIRE)

This code may even work in your testing, but it is wrong and your testing is insufficient. Try crouching and pressing fire - your code will instantly stop working. Why? Because "newkeys" is no longer the same as "KEY_FIRE", it is the same as "KEY_FIRE" COMBINED WITH "KEY_CROUCH".
fair enough, i changed to & BUT it didn't solve my problem
Код:
                    else if(gEngine[playerid] == 1)
                    {
					engineOn[GetPlayerVehicleID(playerid)] = false;
					//RemovePlayerFromVehicle(playerid);
					TogglePlayerControllable(playerid, 0);
					GetPlayerName(playerid, sendername, sizeof(sendername));
					format(string, sizeof(string), "* %s turns off the engine.", sendername);
					ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
					gEngine[playerid] = 0;
					return 1;
				}
i need this command to work but it dosen't why? when i turn the engine on it works, but when i want to turn the engine off it wont ...
Reply
#7

http://forum.sa-mp.com/index.php?topic=148530.0
Reply
#8

Your supposed to have at least 12 hours before bumping your post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)