[Include] mGates (Easily create automatic gates with one function!)
#21

I been meaning to get around to using this,
and finally have and must say this makes adding gates extremely simple,

thanks.
Reply
#22

That's the idea

TBH I expected this to be a lot more popular, the amount of people that post in scripting discussion about gates is a lot, and this takes away all the headaches of making automatic gates. Oh well. I made it for my own server and then decided to release it.
Reply
#23

very cool, makes it so much more easier, rep+
Reply
#24

Quote:
Originally Posted by MP2
View Post
Using OnGateOpenClose and OnPlayerTriggerGate

These two functions are useful for many things. In this example we will create the gates at LS airport, and add 'clang' sounds when they open/close using OnGateOpenClose. We will also play the 'This area is restricted to pilots only.' voice from single-player on OnPlayerRequestGate if entrance is denied, as we only want pilots (skin 61) to enter.

First we need to create the gate, and store its ID in a global variable to handle it later. Two gates are required at the LS airport, but we will only handle one for the sounds, but still need to provide an ID for it for the permissions:

pawn Code:
new GATE_LSAP[2];

public OnGameModeInit()
{
    // LS airport gates
    GATE_LSAP[0] = CreateAutomaticGate(988, 1958.742797, -2189.757324, 13.586877, 0.000000, 0.000000, 180.000000, 1954.142822, -2189.757324, 13.586876, -1000, -1000, -1000, 1961.5413,-2189.3660,13.5469, 15, 4, 1);
    GATE_LSAP[1] = CreateAutomaticGate(988, 1964.242919, -2189.757324, 13.586877, 0.000000, 0.000000, 180.000000, 1968.842895, -2189.757324, 13.586876, -1000, -1000, -1000, 1961.5413,-2189.3660,13.5469, 15, 4, 1);
    return 1;
}
Now, when OnGateOpenClose is called, we want to play the sound of the gate opening to players that are in range:

pawn Code:
public OnGateOpenClose(gateid, openclose, Float:gatex, Float:gatey, Float:gatez)
{
    if(gateid == GATE_LSAP[0])
    {
        if(openclose == GATE_STATUS_OPENING || openclose == GATE_STATUS_CLOSING)
        {
            foreach(new i : Player)
            {
                if(IsPlayerInRangeOfPoint(i, 30, gatex, gatey, gatez)) PlayerPlaySound(i, 1100, gatex, gatey, gatez);
            }
        }
        else
        {
            foreach(new i : Player)
            {
                if(IsPlayerInRangeOfPoint(i, 30, gatex, gatey, gatez)) PlayerPlaySound(i, 1101, gatex, gatey, gatez);
            }
        }
    }
    return 1;
}
When a player triggers the gate, we need to play the 'They'll give a pilot's license to anybody these days!' sound:

pawn Code:
public OnPlayerTriggerGate(playerid, gateid)
{
    if(gateid == GATE_LSAP[0]) SetTimerEx("pilot_speech", 321, 0, "i", playerid);
    return 1;
}

forward pilot_speech(playerid);
public pilot_speech(playerid)
{
    PlayerPlaySound(playerid, 16802+random(2), 0, 0, 0);
    return 1;
}
The reason we have to delay it is so that it does not over-ride the 'clang' sound of the game opening. ~300 miliseconds is good.

Finally we must set the conditions for players to pass, which in this case, they must be using skin ID 61 which is a pilot:

pawn Code:
new pGateTick[MAX_PLAYERS];
public OnPlayerRequestGate(playerid, gateid)
{
    if((gateid == GATE_LSAP[0] || gateid == GATE_LSAP[1]) && GetPlayerSkin(playerid) != 61)
    {
        if(gettime()-pGateTick[playerid] > 10) // If 10 seconds have passed since the last trigger (to prevent spam)
        {
            PlayerPlaySound(playerid, 16800+random(2), 0, 0, 0);
            pGateTick[playerid] = gettime();
        }
        return 0;
    }
    return 1;
}
If they are not using skin 61, entry is denied (return 0 and the 'This area is restricted to pilots only' sound is played. The pGateTick and gettime() stuff is an 'antispam' as this function would be called once a second for a player standing in the trigger zone, so we don't want to 'spam' the sound.

Here's that code in action:

http://www.youtube.com/watch?v=PoJ4qhdoA2U
that is amazing what is your server ip pm me
Reply
#25

I do not have a server at this moment in time. I am developing one.
Reply
#26

Usefull Good Work !
Reply
#27

Definately will try this. Cheers MP2!
Reply
#28

How to get trigger x, y ,z i know they are range of points but how to get the range of point. I mean how to get trigg x, y and z ? HELP!
Reply
#29

Just do /save <description> it will save your current coordinates to file
Reply
#30

Just want I'm in need of thank you.
Reply
#31

Wait I need to clear it. we need to do /save little far away from the gate and we get x y z in savedpositions. Then we need to increase trigg range to about 20~30 Am i right?
Reply
#32

Код:
public OnGameModeInit()
{
	// Don't use these lines if it's a filterscript
	SetGameModeText("Blank Script");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
        CreateAutomaticGate(2963, 2500.0000000, -1671.5000000, 14.4, 0.0000000, 0.0000000, 0.0000000, 2500.0000000, -1669.5000000, 14.3999996, 0.0000000, 0.0000000, 0.0000000, 2498.6000976563, -1671.8000488281, 13.3, 30, 0.003, 0);
	return 1;
}
I did this code correctly but I am not sure about the trigg x, y and z positions. because when I do /save there are 4 co-ordinates not 3. So I placed a object infront of the gate and got the objects position when I came near the gate it dont open. WANT I NEED TO DO ?
Reply
#33

Why none help me?
Reply
#34

The fourth coordinate is the angle - which you don't need. Use the first three. The range should be about 30.
Reply
#35

v2.1 released - added height checks. I think I also changed some minor stuff since the last release, but haven't tested it. Report any problems please.
Reply
#36

Good job MP2! +Rape (° ͜ʖ ͡°)
Reply
#37

To many error :3 please help

Код:
D:\Data Server\pawno\include\mGates.inc(329) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(332) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(333) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(336) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(339) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(340) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(343) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(346) : error 021: symbol already defined: "KillTimer"
D:\Data Server\pawno\include\mGates.inc(347) : error 010: invalid function or declaration
D:\Data Server\pawno\include\mGates.inc(403) : warning 203: symbol is never used: "mgate_trigger_TIMERID"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


9 Errors.
Reply
#38

I keep getting tag mismatch warnings when making the gate but it's being written exactly as it should.

Код:
GATE_INDIA1 = CreateAutomaticGate(971, 2720.1001000,-2405.3999000,16.1000000,0.0000000,0.0000000,270.0000000, 2720.1001000,-2413.8999023438,16.1000000, 0.000000, 0.0000000, 270.000000, 2720.1001000,-2405.3999000,16.1000000, 20.0, 3, 1);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)