SA-MP Forums Archive
Using TAB to open my gate. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Using TAB to open my gate. (/showthread.php?tid=71849)



Using TAB to open my gate. - Shellegg - 04.04.2009

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


Re: Using TAB to open my gate. - Lastman - 04.04.2009

[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;
}


Re: Using TAB to open my gate. - MenaceX^ - 04.04.2009

Get the door status.


Re: Using TAB to open my gate. - dre$tA - 04.04.2009

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;
}



Re: Using TAB to open my gate. - Shellegg - 04.04.2009

Now it only close, dont open


Re: Using TAB to open my gate. - dre$tA - 04.04.2009

Should open too..


Re: Using TAB to open my gate. - HB - 04.04.2009

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


Re: Using TAB to open my gate. - kevinsoftware - 04.04.2009

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


Re: Using TAB to open my gate. - Lastman - 04.04.2009

Код:
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%


Re: Using TAB to open my gate. - Basssss - 04.04.2009

KEY_FIRE is attack (LMB) and KEY_ACTION is tab?