Making Gate Movable for Horn
#1

As the Topic says,I want to make my Gate system movable when Horning from a Vehicle.Currently it's moving when typing /gate,But i don't want to delete it,keep it too and make my gate moving for Horn of the vehicle,

Код:
new LSPDGate;
Код:
  {
			if(!GateInfo[h][gStatus])
			{
            MoveObject(LSPDGate,1544.7018,-1630.9528,13.2196,0.0000,00.0000,90.0000);
			SetObjectRot(LSPDGate, 0.0000, 0.0000, 90.0000 );
			Action(playerid, "opens up the gate.");
  			GateInfo[h][gStatus]=1;
  			}
			else if(PlayerToPoint(9.0,playerid,1544.6943, -1630.7305, 13.2796))
			{
         	MoveObject(LSPDGate,1544.7018,-1630.9528,13.2196,0.0000,90.0000,90.0000);
         	SetObjectRot(LSPDGate, 0.0000, 90.0000, 90.0000 );
   			GateInfo[h][gStatus]=0;
   			Action(playerid, "closes up the gate.");
			}
  }
There you see my Code,Please tell me Which code do i have to apply and where do i need to apply the new codes without changing the above codes to the new codes please,Thanks!
Reply
#2

This should work I suppose:

pawn Код:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
   
   
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) // Detects player key state changes
{
    if(PRESSED(2)) // If the horn key was pressed
    {
        if(IsPlayerInAnyVehicle(playerid)) // If this player is in a vehicle (seems legit?)
        {
            // Well, they pressed the horn key and they're in a vehicle, so let's process the gate script
            if(!GateInfo[h][gStatus])
            {
                MoveObject(LSPDGate,1544.7018,-1630.9528,13.2196,0.0000,00.0000,90.0000);
                SetObjectRot(LSPDGate, 0.0000, 0.0000, 90.0000 );
                Action(playerid, "opens up the gate.");
                GateInfo[h][gStatus]=1;
            }
            else if(PlayerToPoint(9.0,playerid,1544.6943, -1630.7305, 13.2796))
            {
                MoveObject(LSPDGate,1544.7018,-1630.9528,13.2196,0.0000,90.0000,90.0000);
                SetObjectRot(LSPDGate, 0.0000, 90.0000, 90.0000 );
                GateInfo[h][gStatus]=0;
                Action(playerid, "closes up the gate.");
            }
        }
    }
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
https://sampwiki.blast.hk/wiki/Keys

P.S. why don't you check distance on opening a gate like you do when closing one?
Reply
#3

"h" isn't even defined. That example won't work at all, and isn't the most efficient either even if it did compile. I assume that code is inside of a loop, can you show the rest of the code?
Reply
#4

Quote:
Originally Posted by Abagail
Посмотреть сообщение
"h" isn't even defined. That example won't work at all, and isn't the most efficient either even if it did compile. I assume that code is inside of a loop, can you show the rest of the code?
What are you talking about? The 'horn' key is detectable and well I've just tested my code and it works very well.


Reply
#5

I will check it when I'm back at home
Reply
#6

pawn Код:
if(!GateInfo[h][gStatus])
Using your example, I don't see "h" being defined anywhere. I am not talking about the horn key, but the "h" variable used here.
Reply
#7

Yeah you're right that's got to be tweaked; I just copied and pasted his posted code, that's why.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)