Help with open/close gate with 'Y'
#1

I made 2 gate to open with 'Y' or 'KEY_YES'
I add this under OnPlayerKeyStateChange
Код:
	if(newkeys == KEY_YES)
	{
   		if(IsPlayerInRangeOfPoint(playerid, 4.0, 1583.25732, -1638.13708, 13.66108))
    	{
			if(PDvratao == 0)
			{
				if(PlayerInfo[playerid][pLider]==1||PlayerInfo[playerid][pClen]==1)
				{
					PDvratao = 1;
					MoveObject(PDporta2, 1583.25732, -1638.13708, 5.66108, 3.0);
					SendClientMessage(playerid,BELA,"{00FFFF}(DWIG){FF5300} You open the gate!");
				}
			}
   			if(PDvratao == 1)
			{
				if(PlayerInfo[playerid][pLider]==1||PlayerInfo[playerid][pClen]==1)
				{
					PDvratao = 0;
					MoveObject(PDporta2, 1583.25732, -1638.13708, 13.66108, 3.0);
					SendClientMessage(playerid,BELA,"{00FFFF}(DWIG){FF5300} You close the gate!");
				}
			}
		}
		if(IsPlayerInRangeOfPoint(playerid, 8.0, 1544.67786, -1630.77185, 12.88390))
    	{
			if(PDrampao == 0)
			{
				if(PlayerInfo[playerid][pLider]==1||PlayerInfo[playerid][pClen]==1)
				{
					PDrampao = 1;
					MoveObject(PDporta3,1544.69995117,-1630.80004883,13.10000038,0.5,0.00000000,357.74978638,270.25003052);
					SendClientMessage(playerid,BELA,"{00FFFF}(DWIG){FF5300} You open the gate!");
				}
			}
   			if(PDrampao == 1)
			{
				if(PlayerInfo[playerid][pLider]==1||PlayerInfo[playerid][pClen]==1)
				{
					PDrampao = 0;
					MoveObject(PDporta3,1544.69995117,-1630.80004883,13.10000038,0.5,0.00000000,269.74978638,270.25000000);
					SendClientMessage(playerid,BELA,"{00FFFF}(DWIG){FF5300} You close the gate!");
				}
			}
		}
	}
But this doesn't work correct ingame. Here some images:
http://i.imgur.com/EfbWxAv.png
http://i.imgur.com/PisZ2Oe.png
Reply
#2

Well at first:
Quote:

How to check for a key

So, if the variable can contain multiple keys at once, how do you check for just a single one? The answer is bit masking. Each key has its own bit in the variable (some keys have the same bit, but they are onfoot/incar keys, so can never be pressed at the same time anyway) and you need to check for just that single bit:
if (newkeys & KEY_FIRE)
Note that the single "&" is correct - this is a bitwise AND, not a logical AND, which is what the two ampersands are called.
Now if you test this code it will work whether you are crouching or standing when you press the fire key. However there is still one slight problem - it will fire as long as you are holding the key. OnPlayerKeyStateChange is called every time a key changes and that code is true whenever the the fire key is held down. If you press fire the code will fire, if that key is held and you press crouch - that code will fire again because a key (crouch) has changed and fire is still held down How do you detect when a key is first pressed, but not trigger again when it's still held and another key changes?

And you will solve your problem probably by adding return 1; after moveobject and scm
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)