12.04.2011, 09:42
Button Controllable Gates
I got the idea from Raven's Roleplay, some of the gates there can be controlled using a button (thanks to CuervO for
the idea). Today, we will create our very own gates, that can be simply controlled by a button!
We will be making a simple Police gate (for beginners creating RP modes).
Put this at the top of your script:
Then, put this under OnGameModeInit or OnFilterScriptInit:
What does that do? That creates an object (971) and sets the variable of 'pdgate' to the id of the object (CreateObject returns the ID of the object, not the model) at the following co-ordinates:
And with the following rotation co-ordinates:
Easy, almost done, now, put this under OnPlayerKeyStateChange:
What does that code do?
OnPlayerKeyStateChange is a server-sided callback, this is only called when a player presses a key detected by the client. We are checking if the player's current key (newkeys) is 'KEY_LOOK_BEHIND' (which is MMB, middle mouse button), the '&' character is the same thing as '==' but different (no time to explain), then this will check if the player is near the co-ordinates of our gate, then checks if 'pdgateopened' is 0 (false), if so, move the object and set 'pdgateopened' to 1 (true). If the gate is opened (else), move the object back to their old co-ordinates and set 'pdgateopened' back to 0 (false).
And that's it!
Enjoy your gate!
I got the idea from Raven's Roleplay, some of the gates there can be controlled using a button (thanks to CuervO for
the idea). Today, we will create our very own gates, that can be simply controlled by a button!
We will be making a simple Police gate (for beginners creating RP modes).
Put this at the top of your script:
pawn Код:
new pdgate; // Creates a new variable 'pdgate'.
new bool:pdgateopened; // A boolean to check if 'pdgate' is opened.
pawn Код:
pdgate = CreateObject(971, 1588.965698, -1637.882690, 15.260185, 0.0000, 0.0000, 180.0000);
Код:
1588.965698, -1637.882690, 15.260185
Код:
0.0000, 0.0000, 180.0000
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_LOOK_BEHIND) // KEY_LOOK_BEHIND is MMB (middle mouse button).
{
if(IsPlayerInRangeOfPoint(playerid, 8.0, 1588.965698, -1637.882690, 15.260185)) // Checks if the player is in the area of the gate.
{
if(pdgateopened == false) // if pdgateopened is 'false'.
{
MoveObject(pdgate, 1588.965698, -1637.882690, 9.260185); // Moves the object.
pdgateopened = true; // Sets the 'pdgateopened' variable to 'true' which is equivalent to 1.
return 1;
}
else // If pdgateopened is 'true'.
{
MoveObject(pdgate, 1588.965698, -1637.882690, 15.260185); // Move the object back to their old co-ordinates.
pdgateopened = false; // Sets the 'pdgateopened' variable to 'false' which is 0.
return 1;
}
}
}
return 1;
}
OnPlayerKeyStateChange is a server-sided callback, this is only called when a player presses a key detected by the client. We are checking if the player's current key (newkeys) is 'KEY_LOOK_BEHIND' (which is MMB, middle mouse button), the '&' character is the same thing as '==' but different (no time to explain), then this will check if the player is near the co-ordinates of our gate, then checks if 'pdgateopened' is 0 (false), if so, move the object and set 'pdgateopened' to 1 (true). If the gate is opened (else), move the object back to their old co-ordinates and set 'pdgateopened' back to 0 (false).
And that's it!
Enjoy your gate!