22.02.2014, 19:55
Introduction:
Hey everyone, today I'll show you and explain how to make "gates" in samp
In case you are wondering what I mean by that, it is a gate that opens or closes when the user interacts
I will show you guys several different ways for different results, you pick whatever you want
In this tutorial I will be using Zeex's include zcmd
Content Table:
Hey everyone, today I'll show you and explain how to make "gates" in samp
In case you are wondering what I mean by that, it is a gate that opens or closes when the user interacts
I will show you guys several different ways for different results, you pick whatever you want
In this tutorial I will be using Zeex's include zcmd
Content Table:
- Gate activated by command
- Gate activated by key
- Gate with automatic closing
- Gate activated by proximity
¤ Gate activated by command:
Well first of all, we will define the position of the gate open - closed, and declare the following variables:
Once the variables are declared, we will continue to assign the id to the object, while creating it:pawn Code:new GateGrove; //Id to be assigned to the gate
new isOpen[MAX_OBJECTS]; //Variable to check if the object is open
#define XYZ_Open 2464.6001000,-1668.8000500,14.0000000
#define XYZ_Closed 2464.6999500,-1659.3000500,14.0000000
//Note: They are necessary for the tutorial, and I recommend using them since they'll make your life much easier
Finally, we create the command "/gate" to open or close the door, depending of it's state:pawn Code:GateGrove = CreateObject(975,2464.6999500,-1659.3000500,14.0000000,0.0000000,0.0000000,88.0000000);
//Make sure that it's either on "OnGameModeInit" or "OnFilterScriptInit" due that it needs to be created when the server starts running
pawn Code:command(gate,playerid,params[])
{
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //If it is in range of the player
{
if(isOpen[GateGrove] == 0) //If the variable is equal to 0 (gate is closed)..
{
MoveObject(GateGrove, XYZ_Open, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 1; //Set the variable to 1 (gate is now open)
}
else if(isOpen[GateGrove] == 1) //If the variable is equal to 1 (gate is open)..
{
MoveObject(GateGrove, XYZ_Closed, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 0; //Set the variable to 0 (gate is now closed)
}
}
return 1;
}
¤ Gate activated by key:
Well first of all, we will define the position of the gate open - closed, and declare the following variables:
Once the variables are declared, we will continue to assign the id to the object, while creating it:pawn Code:new GateGrove; //Id to be assigned to the gate
new isOpen[MAX_OBJECTS]; //Variable to check if the object is open
#define XYZ_Open 2464.6001000,-1668.8000500,14.0000000
#define XYZ_Closed 2464.6999500,-1659.3000500,14.0000000
//Note: They are necessary for the tutorial, and I recommend using them since they'll make your life much easier
Finally, we add the open-close code on callback "OnPlayerKeyStateChange":pawn Code:GateGrove = CreateObject(975,2464.6999500,-1659.3000500,14.0000000,0.0000000,0.0000000,88.0000000);
//Make sure that it's either on "OnGameModeInit" or "OnFilterScriptInit" due that it needs to be created when the server starts running
pawn Code:public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((newkeys & KEY_YES) && !(oldkeys & KEY_YES)) //If key "Y" is pressed..
{
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //Player is in range of gate..
{
if(isOpen[GateGrove] == 0) //If the variable is equal to 0 (gate is closed)..
{
MoveObject(GateGrove, XYZ_Open, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 1; //Set the variable to 1 (gate is now open)
}
else if(isOpen[GateGrove] == 1) //If the variable is equal to 1 (gate is open)..
{
MoveObject(GateGrove, XYZ_Closed, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 0; //Set the variable to 0 (gate is now closed)
}
}
}
return 1;
}
¤ Gate with automatic closing:
Well first of all, we will define the position of the gate open - closed, and declare the following variables:
Once the variables are declared, we will continue to assign the id to the object, while creating it:pawn Code:new GateGrove; //Id to be assigned to the gate
new isOpen[MAX_OBJECTS]; //Variable to check if the object is open
new isAutomatic[MAX_OBJECTS]; //Variable to check if the gate is automatic closing type
new isIndpendent[MAX_OBJECTS]; //Variable to check if the gate is triggered by proximity
#define XYZ_Open 2464.6001000,-1668.8000500,14.0000000
#define XYZ_Closed 2464.6999500,-1659.3000500,14.0000000
//Note: They are necessary for the tutorial, and I recommend using them since they'll make your life much easier
Now we create the command that will only open the gate:pawn Code:GateGrove = CreateObject(975,2464.6999500,-1659.3000500,14.0000000,0.0000000,0.0000000,88.0000000);
isAutomatic[GateGrove] = 1; //Set it to automatic
//Make sure that it's either on "OnGameModeInit" or "OnFilterScriptInit" due that it needs to be created when the server starts running
Finally, we add the code for callback "OnObjectMoved":pawn Code:command(autogate,playerid,params[])
{
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //If player is in range of gate..
{
if(isOpen[GateGrove] == 0) //If the variable is equal to 0 (gate is closed)..
{
MoveObject(GateGrove, XYZ_Open, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 1; //Set the variable to 1 (gate is now open)
}
}
return 1;
}
pawn Code:public OnObjectMoved(objectid)
{
if(objectid == GateGrove) //If the object that moved was our gate
{
if(isAutomatic[GateGrove] == 1 || isIndependent[GateGrove]) //If it is either automatic closing or independent
{
MoveObject(GateGrove, XYZ_Closed, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 0; //Set the variable to 0 (gate is now closed)
}
}
return 1;
}
¤ Gate activated by proximity:
Well first of all, we will define the position of the gate open - closed, and declare the following variables:
Once the variables are declared, we will continue to assign the id to the object, while creating it:pawn Code:new GateGrove; //Id to be assigned to the gate
new isOpen[MAX_OBJECTS]; //Variable to check if the object is open
new isAutomatic[MAX_OBJECTS]; //Variable to check if the gate is automatic closing type
new isIndpendent[MAX_OBJECTS]; //Variable to check if the gate is triggered by proximity
#define XYZ_Open 2464.6001000,-1668.8000500,14.0000000
#define XYZ_Closed 2464.6999500,-1659.3000500,14.0000000
//Note: They are necessary for the tutorial, and I recommend using them since they'll make your life much easier
Now we create the public and the forward for the checking function:pawn Code:GateGrove = CreateObject(975,2464.6999500,-1659.3000500,14.0000000,0.0000000,0.0000000,88.0000000);
isIndependent[GateGrove] = 1; //Set it to independent
for(new i; i < MAX_PLAYERS; i++) //Loop for every player
{
SetTimerEx("NearGate", 2000, true, "i", i); //Check every 2 seconds if player is near a gate
}
//Make sure that it's either on "OnGameModeInit" or "OnFilterScriptInit" due that it needs to be created when the server starts running
Finally, we add the code for callback "OnObjectMoved":pawn Code:forward NearGate(playerid);
public NearGate(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //If player is in range of gate..
{
if(isIndependent[GateGrove] == 1) // If it is independent..
{
if(isOpen[GateGrove] == 0) //If the variable is equal to 0 (gate is closed)..
{
MoveObject(GateGrove, XYZ_Open, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 1; //Set the variable to 1 (gate is now open)
}
}
}
return 1;
}
pawn Code:public OnObjectMoved(objectid)
{
if(objectid == GateGrove) //If the object that moved was our gate
{
if(isAutomatic[GateGrove] == 1 || isIndependent[GateGrove]) //If it is either automatic closing or independent
{
MoveObject(GateGrove, XYZ_Closed, 2.00); //Move the gate to the appropriate coords
isOpen[GateGrove] = 0; //Set the variable to 0 (gate is now closed)
}
}
return 1;
}