SA-MP Forums Archive
Horn key to open 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)
+--- Thread: Horn key to open gate (/showthread.php?tid=614409)



Horn key to open gate - jimdo - 08.08.2016

How to make Horn Button to open the gate?


Re: Horn key to open gate - Micko123 - 08.08.2016

Just make like this
if is player near the gate and if he press H move that object


Re: Horn key to open gate - Ahmed21 - 08.08.2016

PHP код:
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
      if((
newkeys KEY_CTRL_BACK) && !(oldkeys KEY_CTRL_BACK))  //If the player uses the horn "clicks H"
      
{
              new 
pState GetPlayerState(playerid);
              if(
IsPlayerInAnyVehicle(playerid) && pState == PLAYER_STATE_DRIVER//If the player is driving a car
              
{
                      new 
Float:GatePosXFloat:GatePosYFloat:GatePosZ;
                      
GetObjectPos(GateObjectIDGatePosXGatePosYGatePosZ); //Replace the GateObjectID with your gate object id.
                      
if(IsPlayerInRangeOfPoint(playerid5.0GatePosXGatePosYGatePosZ)) //If the player is near the gate.
                      
{
                             
MoveObject(GateObjectIDNewPosXNewPosYNewPosZ5.0NewPosRotationXNewPosRotationYNewPosRotationZ);
                             
//5.0 = Moving Speed
                      
}
               }
       }
       return 
1;




Re: Horn key to open gate - Viggo - 08.08.2016

Quote:
Originally Posted by Ahmed21
Посмотреть сообщение
PHP код:
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
      if((
newkeys KEY_CTRL_BACK) && !(oldkeys KEY_CTRL_BACK))  //If the player uses the horn "clicks H"
      
{
              new 
pState GetPlayerState(playerid);
              if(
IsPlayerInAnyVehicle(playerid) && pState == PLAYER_STATE_DRIVER//If the player is driving a car
              
{
                      new 
Float:GatePosXFloat:GatePosYFloat:GatePosZ;
                      
GetObjectPos(GateObjectIDGatePosXGatePosYGatePosZ); //Replace the GateObjectID with your gate object id.
                      
if(IsPlayerInRangeOfPoint(playerid5.0GatePosXGatePosYGatePosZ)) //If the player is near the gate.
                      
{
                             
MoveObject(GateObjectIDNewPosXNewPosYNewPosZ5.0NewPosRotationXNewPosRotationYNewPosRotationZ);
                             
//5.0 = Moving Speed
                      
}
               }
       }
       return 
1;

Wow thank you.


Re: Horn key to open gate - jimdo - 08.08.2016

Thanks mate.


Re: Horn key to open gate - Ahmed21 - 08.08.2016

And if the gate is a dynamic object, then replace the "MoveObject" with "MoveDynamicObject".