¤ 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;
}
¤ Exclusive to a faction/team:
Well, what you want to do here is to add the following line:
pawn Code:// Command depending on the type of gate
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //If player is in range of the gate..
{
if(PlayerInfo[playerid][pFaccion] == x) //If player belongs to faction "x" - Change for your team/faction variable -..
{
//Rest of code
}
}
return 1;
}
¤ Exclusive to any vehicle:
Well, what you want to do here is to add the following line:
pawn Code:// Command depending on the type of gate
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //If player is in range of the gate..
{
if(IsPlayerInAnyVehicle(playerid)) //If player is in any vehicle..
{
//Rest of code
}
}
return 1;
}
¤ Exclusive to a specific vehicle:
Well, what you want to do here is to add the following line:
pawn Code:// Command depending on the type of gate
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //If player is in range of the gate..
{
if(IsPlayerInVehicle(playerid, x)) //If the player is in vehicle "x" - Change x for the vehicle id -..
{
//Rest of code
}
}
return 1;
}
¤ Exclusive to a specific score:
Well, what you want to do here is to add the following line:
pawn Code:// Command depending on the type of gate
if(IsPlayerInRangeOfPoint(playerid, 15.0, XYZ_Closed)) //Si esta en rango de la puerta..
{
if(GetPlayerScore(playerid) >= x) //If player has a bigger or equal value of "x" score - Change x for the score -..
{
//Rest of code
}
}
return 1;
}
I have not read all of it, I skipped through it. However, by looks it's a great tutorial and I'm sure that people will find it useful. Keep up!
|