16.04.2012, 20:45
(
Last edited by Plastic; 16/04/2012 at 09:21 PM.
)
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
SECOND STEP
THIRD STEP
FOURTH STEP
FIFTH STEP
SIXTH STEP
Well there you have it, a simple automatic gate tutorial, this is suitable for anyone
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
pawn Code:
forward GatesOpen();
forward GatesClose(); //put these with other forwards or under the variables
pawn Code:
SetTimer("GatesOpen",1000,1); //This is the timer, put this under Public OnGameModeInIt
pawn Code:
Gate = CreateObject(objectid,x,y,z,rotX,rotY,rotZ); //This is where you define which object you want to be moved
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;
}
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;
}