[Tutorial] Gates and how they work
#1

What do you need:
Basic Knowledge
Mapping Skills

Alright, so I will be explaining how the gates work, and how to make them slide open, it's a really basic MoveDynamicObject Code

Let's get started shall we.

I will paste in the /gate command as example, and then explain what does what.

/gate command:

pawn Code:
CMD:gate(playerid, params[]) {
    if(groupVariables[playerVariables[playerid][pGroup]][gGroupType] == 1) {
        if(IsPlayerInRangeOfPoint(playerid, 15.0, 1543.59997559,-1628.19995117,14.80000019)) switch(LSPDGates[0][1]) {
            case 0: {
                MoveDynamicObject(LSPDGates[0][0] ,1543.59997559,-1628.19995117,7.7, 1.0);
                LSPDGates[0][1] = 1;
            }
            case 1: {
                MoveDynamicObject(LSPDGates[0][0] ,1543.59997559,-1628.19995117,14.80000019, 1.0);
                LSPDGates[0][1] = 0;
            }
        }
        else if(IsPlayerInRangeOfPoint(playerid, 15.0, 1588.59997559,-1638.00000000,14.60000038)) switch (LSPDGates[1][1]) {
            case 0: {
                MoveDynamicObject(LSPDGates[1][0] ,1588.59997559,-1638.00000000,7.7, 1.0);
                LSPDGates[1][1] = 1;
                //PlayerPlaySoundEx(1035, 1588.59997559,-1638.00000000,14.60000038);
            }
            case 1: {
                MoveDynamicObject(LSPDGates[1][0] ,1588.59997559,-1638.00000000,14.60000038, 1.0);
                LSPDGates[1][1] = 0;
                //PlayerPlaySoundEx(1035, 1588.59997559,-1638.00000000,14.60000038);
            }
        }
    }
    return 1;
}
These codes are for sound, if you wish to use it I temporary removed them from my script, because personally, they are annoying as hell.
pawn Code:
PlayerPlaySoundEx(1035, 1588.59997559,-1638.00000000,14.60000038);
As you can see these are LSPD Gates, which been defined as DynamicObject, you would have to Define them also if you want to use the gates as LSPD gates.
Here is a quick breakdown.
pawn Code:
new         LSPDGates[2][2];
The First "[2]" is the amount of gates you want to define, this number can be changed to what ever you want, personally LSPD doesn't need more than two gates in my opinion.
The Second "[2]" is the status, 2 means they are closed, 1 means they are open, so it's best to keep them at 2.

So, now the main things that make the gates open, such as coords, at what speed they open, and the angles.

This code tells the server, from where the /gate command can be activated, you need to set it up right beside the gate, so just use the gate's coordinates, you don't want to clusterf*ck anything, and make a huge mess.

so this is the position from where you type /gate to open the specific gate.
pawn Code:
if(IsPlayerInRangeOfPoint(playerid, 15.0, 1543.59997559,-1628.19995117,14.80000019))
Now the gates it self, as I mentioned in the beginning, you need some mapping knowledge, this is to get the Open and Closed Gate's Coords, so that you can tell the script where the gates would open, and how far, I will not be going through it in this tutorial because there is lots and lots of them out there.

Here is the code, that tells the gates how much to close and how much to open after using /gate command.
pawn Code:
case 0: {
                MoveDynamicObject(LSPDGates[0][0] ,1543.59997559,-1628.19995117,7.7, 1.0);
                LSPDGates[0][1] = 1;
            }
            case 1: {
                MoveDynamicObject(LSPDGates[0][0] ,1543.59997559,-1628.19995117,14.80000019, 1.0);
                LSPDGates[0][1] = 0;
"case 0" Is the Open position of the gates.
"Case 1" Is the Closed position of the gates.
As you can see, there is extra numbers from the Z Position behind it;
pawn Code:
1.0);
This is the speed at which gates open/close, again you can changed that to your own liking.
For the Open position I would suggest to set the Z Position to 7.7, it's just below the ground and it doesn't get in the way when you drive through the open gates.

I hope it explained and helped you guys.
To the senior scripters; I'm new at scripting, and I had a difficult time figuring out the gates system, and how it works, I thought I'd explain it, so other new people don't have the same problem.

Feedback is more than welcome, this is my first Tutorial ever Made, so go easy on it :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)