[Tutorial] Simple Automatic Gate Tutorial
#1

In this tutorial you will how to create gates and how they will move when a player is close to the gate.

PS : This works with any object and some parts of the script may only be understood by professional scripters

FIRST STEP

pawn Code:
new Gate;
new GateOpen =0; //put this at the top of the script
SECOND STEP
pawn Code:
forward GatesOpen();
forward GatesClose(); //put these with other forwards or under the variables
THIRD STEP
pawn Code:
SetTimer("GatesOpen",1000,1); //This is the timer, put this under Public OnGameModeInIt
FOURTH STEP
pawn Code:
Gate = CreateObject(objectid,x,y,z,rotX,rotY,rotZ); //This is where you define which object you want to be moved
FIFTH STEP
pawn Code:
//put this anywhere in the script
public GatesOpen()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(PlayerToPoint(10.0, i, x,y,z) && GateOpen == 0) //replace x,y,z with the gate coords
        {
            //if(gTeam[i] == TEAM_NOOBS) //use this if you wish to set this for a specific class
            {
                MoveObject(Gate, x,y,z, 5); //replace x,y,z with new coords for the object to be placed
                GateOpen =1;
                SetTimer("GatesClose",7000,0);
        }
        }
    }
}

public GatesClose()
{
     MoveObject(Gate, x,y,z, 5); //put the original x,y,z coords of the original gate coords
     GateOpen =0;
}
SIXTH STEP
pawn Code:
//the following is a function to get the current position of the player
//place the following code at the end of the script
PlayerToPoint(Float:radius, playerid, Float:X, Float:Y, Float:Z)
{
    new Float:oldpos[3], Float:temppos[3];
    GetPlayerPos(playerid, oldpos[0], oldpos[1], oldpos[2]);
    temppos[0] = (oldpos[0] -X);
    temppos[1] = (oldpos[1] -Y);
    temppos[2] = (oldpos[2] -Z);
    if(((temppos[0] < radius) && (temppos[0] > -radius)) && ((temppos[1] < radius) && (temppos[1] > -radius)) && ((temppos[2] < radius) && (temppos[2] > -radius)))
    {
        return true;
    }
    return false;
}
Well there you have it, a simple automatic gate tutorial, this is suitable for anyone
Reply


Messages In This Thread
Simple Automatic Gate Tutorial - by Plastic - 16.04.2012, 20:45
Re: Simple Automatic Gate Tutorial - by Jonny5 - 16.04.2012, 20:56
Re: Simple Automatic Gate Tutorial - by Plastic - 16.04.2012, 20:59
Re: Simple Automatic Gate Tutorial - by Jonny5 - 16.04.2012, 21:05
Re: Simple Automatic Gate Tutorial - by Plastic - 16.04.2012, 21:15
Re: Simple Automatic Gate Tutorial - by Wickeed - 16.04.2012, 21:39
Re: Simple Automatic Gate Tutorial - by Plastic - 16.04.2012, 21:48
Re: Simple Automatic Gate Tutorial - by Facerafter - 27.04.2012, 13:12
Re: Simple Automatic Gate Tutorial - by System64 - 27.04.2012, 13:42
Re: Simple Automatic Gate Tutorial - by ReneG - 27.04.2012, 18:51

Forum Jump:


Users browsing this thread: 1 Guest(s)