Hello, Well this is my first tutorial. And i will try to make it as good as possible .
Well, We are going to create a door in the LSPD interior.

First, Put this on top of your script:
Code:
new pddoor1;
That is the name of your door. And will be used later.

Then you need to create your object. Put this OnGameModeInit:

Code:
pddoor1 = CreateObject(OBJECTID, X,Y,Z,RX,RY,RZ,DRAWDISTANCE); //Your probably wondering what RX,RY,RZ. Its the rotation coordinates for your object
Then goto your script and search for: OnPlayerKeyStateChange. If you cant find it. Then you dont have it in your script. But thats alright. Add this to the bottom of your script.
Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}

Well, Now you need to go ingame. And go into your interior where you placed the door. And do /save to get your coordinates. After you have done that. Goto My Documents>Gta San andreas user files>SAMP>Savedpositions.txt and get your cordinates.

Example:
Code:
AddPlayerClass(0,1485.8622,-1565.8378,23.5469,273.8373,0,0,0,0,0,0); // The numbers marked with colour black is your coordinates.
Well now open your script, and add this to your OnPlayerKeyStateChange code:

Code:
if(newkeys & 16)
This is the key ENTER or F. Its the key to enter vehicles. This is the key that will open your door.

Now add this to your code:
Code:
if(newkeys & 16)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, YOUR CORDINATES))
The IsPlayerInRangeOfPoint part shows if you are near the door. The 2.0 numbers are how long you can be from the keypad. I would recommend 2.0. Its close enough.

Now when that part is done. You would normally only want police officers to open it. So now lets add this to your command. This is the most used function in the scripts. And i think every RP script uses it.

Code:
if(newkeys & 16)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, YOUR CORDINATES))
{
if (PlayerInfo[playerid][pLeader] == 1 || PlayerInfo[playerid][pMember] == 1)

This check if you are a member or the leader of LSPD. And it will only be openable if you are in LSPD.

Now lets continue with the command.
We are now going to make the door movable.
Code:
if(newkeys & 16)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, YOUR CORDINATES))
{
if (PlayerInfo[playerid][pLeader] == 1 || PlayerInfo[playerid][pMember] == 1)
{
MoveObject(pddoor1,CORDS,SPEED);

Alright, Now add your coordinates at the CORDS place.
The speed is how fast you want the door to move. I would recommend 2.0 again.

Now you got the door moving, But now you want it closed right?
Well lets use a timer for that.

First go to the top of your script. And add:
Code:
forward doorclose1(playerid);
This will forward your timer. Now goto anywhere of your script, and add this:

Code:
public doorclose1(playerid)
{
MoveObject(pddoor,CORDS,SPEED);
return 1;
}

This is the timer that will close your gate. Well now go back to OnPlayerKeyStateChange. Just hit CTRL + F and search for it.

Now add this to your code:
Code:
if(newkeys & 16)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, YOUR CORDINATES))
{
if (PlayerInfo[playerid][pLeader] == 1 || PlayerInfo[playerid][pMember] == 1)
{
MoveObject(pddoor1,CORDS,SPEED);
SetTimerEx("doorclose1", 5000, false, "i", playerid);
SetTimerEx will add the timer to your command. So when you open it. It will automaticly close. In 5 seconds. The seconds are in milliseconds. To count that out, just goto ****** and type for an example:
Code:
10 seconds in milliseconds
And it will count it out.

Now lets add a Animation when you open the door.

Code:
if(newkeys & 16)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, YOUR CORDINATES))
{
if (PlayerInfo[playerid][pLeader] == 1 || PlayerInfo[playerid][pMember] == 1)
{
MoveObject(pddoor1,CORDS,SPEED);
SetTimerEx("doorclose1", 5000, false, "i", playerid);
ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);

This will make it look like you are swiping a card when you press ENTER / F.

Now we are almost done.

We just need to close the command. Just add three closing brackets to the end. Like this:
Code:
if(newkeys & 16)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, YOUR CORDINATES))
{
if (PlayerInfo[playerid][pLeader] == 1 || PlayerInfo[playerid][pMember] == 1)
{
MoveObject(pddoor1,CORDS,SPEED);
SetTimerEx("doorclose1", 5000, false, "i", playerid);
ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
}
}
}

And now we are finished! Congratulations!. This is how it should look:

[ame]http://www.youtube.com/watch?v=sxf3iEIObAA[/ame]

Please reply what you think about my first tutorial