Using TAB to open my gate.
#1

Well i tryed to use OnPlayerKeyStateChange.

Heres my code

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PlayerInfo[playerid][pFaction] != 255 && DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 2)
    {
      if (newkeys & KEY_FIRE)
      {
        MoveObject(modoor, 351.7448,165.5032,1026.3500, 3.5000);//open
        }
        else if (newkeys & KEY_FIRE)
        {
          MoveObject(modoor, 353.2448,165.5032,1026.3500, 3.5000);//close
        }
    }
   
    return 1;
}

I tryed to use TAB to open and close the gate, but i can only open it, cant close it, anyone knows why?

Waiting an aswer

Thanks
Shellegg
Reply
#2

[font=courier new] maybe this :

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PlayerInfo[playerid][pFaction] != 255 && DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 2)
{
if (newkeys & KEY_FIRE)
{
MoveObject(modoor, 351.7448,165.5032,1026.3500, 3.5000);//open
}
else // (newkeys & KEY_FIRE)
{
MoveObject(modoor, 353.2448,165.5032,1026.3500, 3.5000);//close
}
}

return 1;
}
Reply
#3

Get the door status.
Reply
#4

You need a variable to check if the gate is open or close like this:

Код:
On top of the script:
new bool:GateOpen;

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PlayerInfo[playerid][pFaction] != 255 && DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 2)
	{
	  if (newkeys & KEY_FIRE)
	  {
        if(GateOpen == true)
        {
          MoveObject(modoor, 353.2448,165.5032,1026.3500, 3.5000);//close
          GateOpen = false;
        }
        else
        {
          MoveObject(modoor, 351.7448,165.5032,1026.3500, 3.5000);//open
          GateOpen = true;
        }
      }
	
	return 1;
}
Reply
#5

Now it only close, dont open
Reply
#6

Should open too..
Reply
#7

Quote:
Originally Posted by dre$tA
Should open too..
Nope, you forgot a bracket.
Reply
#8

Quote:
Originally Posted by иєσz
Quote:
Originally Posted by dre$tA
Should open too..
Nope, you forgot a bracket.
bracket
Reply
#9

Код:
On top of the script:
new bool:GateOpen;

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PlayerInfo[playerid][pFaction] != 255 && DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 2)
	{
	  if (newkeys & KEY_FIRE)
	  {
        if(GateOpen == true)
        {
          MoveObject(modoor, 353.2448,165.5032,1026.3500, 3.5000);//close
          GateOpen = false;
        }
        else
        {
          MoveObject(modoor, 351.7448,165.5032,1026.3500, 3.5000);//open
          GateOpen = true;
        }
      }
	}
	return 1;
}
That bracket. And this should work 100%
Reply
#10

KEY_FIRE is attack (LMB) and KEY_ACTION is tab?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)