[Tutorial] How to create a door with a keypads
#1

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:
Код:
new pddoor1;
That is the name of your door. And will be used later.

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

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

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

pawn Код:
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.
pawn Код:
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:
Код:
forward doorclose1(playerid);
This will forward your timer. Now goto anywhere of your script, and add this:

pawn Код:
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:
pawn Код:
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:
Код:
10 seconds in milliseconds
And it will count it out.

Now lets add a Animation when you open the door.

pawn Код:
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:
pawn Код:
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
Reply
#2

Thank you
Reply
#3

LOl easy, but nice tutorial for the newbies out there needing miscellanous things like this.
Reply
#4

Quote:
Originally Posted by ToPhrESH
Посмотреть сообщение
LOl easy, but nice tutorial for the newbies out there needing miscellanous things like this.
Haha yea i know its easy. I just made it for fun :P

Thanks
Reply
#5

Good tutorial Alex, well yeah, as most RP servers use/based on GF GM this will be so useful for many people hhaha.
Reply
#6

Quote:
Originally Posted by [BKR]LUCAGRABACR
Посмотреть сообщение
Good tutorial Alex, well yeah, as most RP servers use/based on GF GM this will be so useful for many people hhaha.
Thanks haha yea i know :P
Reply
#7

Do i add this stuff on my actual GM or in a new pwn file?
Reply
#8

Quote:
Originally Posted by Adam420
Посмотреть сообщение
Do i add this stuff on my actual GM or in a new pwn file?
You can add it as a FilterScript or you can add it to your GameMode.. your choose
Reply
#9

Does anyone know what the animation is called where your character presses the button? IT would be nice to have the animation in on this.

EDIT:

ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
Reply
#10

I don't have these variables, you would have them if your script was a GF edit
Reply
#11

Quote:

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:
pdoor1 = CreateObject(OBJECTID, X,Y,Z,RX,RY,RZ,DRAWDISTANCE); //Your probably wondering what RX,RY,RZ. Its

Do you see the problem?
Reply
#12

What is the problem lol

EDIT: Oh! Now i see it haha thanks

EDIT2: Fixed it :P Thank you xD
Reply
#13

No problem xd. Next time check you're code before posting.
Reply
#14

nice
Reply
#15

Thanks man it's a great tutorial
Reply
#16

Thank you

EDIT:
Quote:
Originally Posted by alpha500delta
View Post
No problem xd. Next time check you're code before posting.
Haha Yea, but it was a such small mistake. Couldnt even notice it lol :P
Reply
#17

Lol that's awesome I might use it on my server
Reply
#18

really nice ;>D
Reply
#19

Pls I need the ObjectID or the name of these keypads.
would be nice if someone will post them
Reply
#20

Quote:
Originally Posted by [MF]FACE
View Post
Pls I need the ObjectID or the name of these keypads.
would be nice if someone will post them
The object id is: 2886

Thanks everyone for your comments
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)