[Tutorial] Moving gate with a command.
#1

Moving gates - with commands.

I've seen certian people asking for that, so I thought making a little tutorial.
Functions used :
MoveObject
IsPlayerInRangeOfPoint
CreateObject

Step 1:
Let's get some coordinations for our gate, shall we ?
Let's go in-game [ debug or any server ], go to the desired spot for the gate and simply /rs [comment].
Now, go to My Documents \ GTA SA User Files \ SAMP and open a text file named rawpositions.
In there, you'll see this :
pawn Код:
X,Y,Z ;
All you need is the numbers. [ X,Y,Z ]
Step 2:
I'd rather defining my gate with a name, instead those messy object ID's.
I'd go to top of my script, under my includes, and write this :
pawn Код:
new gate1;
We have defined a gate, but the script doesn't know it's a gate yet.
Under OnGameModeInIt, make the object with the coordinations you got in the start.
pawn Код:
public OnGameModeInit()
{
    gate1 = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance) //Creating the object
    return 1;
}
Now we defined our gate and will be easier to use it on our command.
Step 3 :
Now let's go to
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}
Now let's script out /open & /close command.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{//opening bracket
    if (strcmp("/open", cmdtext, true, 5) == 0) // The /open command
    {//opening bracket
        if(IsPlayerInRangeOfPoint(playerid, radius, X, Y,Z))//Checking if the player in the range of the gate
           {//opening bracket
        MoveObject(name, X,Y, Z, speed);// Opening the gate
                SendClientMessage(playerid, 0xEF994300, "The gate has opened."); //Sending a message that gate opened
        }//closing bracket
        return 1;
    }//closing bracket
        if (strcmp("/close", cmdtext, true, 6) == 0)// The /close command
    {//opening bracket
        if(IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z))//Checking if the player in the range of the gate
        {//opening bracket
                  MoveObject(name, X, Y, Z, speed);// Moving the gate
              SendClientMessage(playerid, 0xEF994300, "The gate has closed.");//Sending a message to the one used the command
                }//closing bracket
        return 1;
    }//closing bracket
    return 0;
}//closing bracket
On our MoveObject line, we'll put the coordinations of the gate that is closed & opened, and insted of 'name' we write the name of the gate, which in this case is gate1 and speed is the speed of how fast the object would move.
Ex. :
Код:
 MoveObject(gate1, X, Y, Z, speed);
Now you have a gate that will move with /open & /close, enjoy.
Reply
#2

Nice, about time you made a tutorial!
Reply
#3

Thanks .
I'm not that good of a scripter anyway, lol.
Reply
#4

No, your good

10/10 for this tutorial, explains each function
Reply
#5

Thanks .
Reply
#6

Thus, I prefer you to use ' /rs ' instead of ' /save ' to get positions.
save = whole AddPlayerClass
rs = rawposition ( X,Y,Z,A )

Saves at rawpositions.txt, same folder as /save

And :
pawn Код:
MoveObject(name, X, Y, Z, speed);// Moving the gate
at the close command, good explaining

at the open command,
pawn Код:
MoveObject(name, X,Y, Z, 1);// Opening the gate
What's 1 =P

Nice tutorial.
Reply
#7

Fixing, thanks.
Reply
#8

pawn Код:
if (strcmp("/open", cmdtext, true, 10) == 0)
/open is not 10 characters long >.<
Reply
#9

Well, 5 characters long .
Reply
#10

Very simple, but nice tutorial and teaching.
i suggest you to make
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/gate", cmdtext, true, 5) == 0) // The /open command
    {
        if(IsPlayerInRangeOfPoint(playerid, radius, X, Y,Z))//Checking if the player in the range of the gate
        {
        MoveObject(name, X,Y, Z, speed);// Opening the gate
        SendClientMessage(playerid, 0xEF994300, "The gate has opened."); //Sending a message that gate opened
        }
        return 1;
    }
    else
    {

        MoveObject(name, X, Y, Z, speed);// Moving the gate
        SendClientMessage(playerid, 0xEF994300, "The gate has closed.");//Sending a message to the one used the command
        return 1;
    }
    return 0;
}
So 1 command can make 2 jobs in the same time
Reply
#11

Dude your amazing I will give that a try later

Now all you need to do it sort out your server 28% up time :P
Reply
#12

Lol starting on that now xD
Reply
#13

Fixed Updated my topic to 0.3d aswell
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)