new Gate,//To store the gate-objectid
bool:Open;//Boolean if you want to use one command instead 2 for close and open
/*
Note:
Using boolean is (a little) slower instead make two command and take (a little) file size*/
//Multi-dimensional variable
new Gate[3],
bool:Open[3 char];//For more information about char: https://sampforum.blast.hk/showthread.php?tid=216730
//--------------------------
//Multiple variable
new Gate1,Gate2,Gate3,
bool:Open1,bool:Open2,bool:Open3;
//--------------------------
//Single gate
public OnFilterScriptInit()
{
Gate = CreateObject(modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:DrawDistance = 0.0);
return 1;
}
//--------------------------
//Multiple gate
public OnFilterScriptInit()
{
Gate[0] = CreateObject(modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:DrawDistance = 0.0);
Gate[1] = CreateObject(modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:DrawDistance = 0.0);
Gate[2] = CreateObject(modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:DrawDistance = 0.0);
return 1;
}
//--------------------------
new Float:GatePos[3][6] =
{
{xxx,yyy,zzz,rx,ry,rz,x1,y1,z1},
{xxx,yyy,zzz,rx,ry,rz,x1,y1,z1},
{xxx,yyy,zzz,rx,ry,rz,x1,y1,z1}
};
/*
xxx, yyy, and zzz are the original coordinate of the objectid
rx, ry, and rz are the rotation of the objectid
x1, y1, and z1 are the second coordinate after the object moved/opened
*/
public OnFilterScriptInit()
{
for(new a;a<sizeof(GatePos);a++)
{
Gate[a] = CreateObject(modelid,GatePos[a][0],GatePos[a][1],GatePos[a][2],GatePos[a][3],GatePos[a][4],GatePos[a][5],Float:DrawDistance = 0.0);
}
return 1;
}
new OnGate[MAX_PLAYERS char];
stock IsNearGate(playerid)
{
for(new a;a<sizeof(GatePos);a++)
{
if(IsPlayerInRangeOfPoint(playerid,10,GatePos[a][0],GatePos[a][1],GatePos[a][2])
{
OnGate{playerid} = a;
return 1;
}
}
return 0;
}
CMD:gateopen(playerid,params[])
{
if(!IsNearGate(playerid)) return SendClientMessage(playerid,color,"There's no gate nearby.");
MoveObject(Gate[OnGate{playerid}],GatePos[OnGate{playerid}][6],GatePos[OnGate{playerid}][7],GatePos[OnGate{playerid}][8],Float:Speed);
return 1;
}
CMD:gateclose(playerid,params[])
{
if(!IsNearGate(playerid)) return SendClientMessage(playerid,color,"There's no gate nearby.");
MoveObject(Gate[OnGate{playerid}],GatePos[OnGate{playerid}][0],GatePos[OnGate{playerid}][1],GatePos[OnGate{playerid}][2],Float:Speed);
return 1;
}
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
//For more information about PRESSED: https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
switch(PRESSED)//Always use switch
{
case KEY_HANDBRAKE://(Hand Brake/aim)
{
if(IsPlayerInRangeOfPoint(playerid,10,xxx,yyy,zzz)//Gate 1
{
switch(Open{0})//Check whether the gate opened or closed
{
case true://If the gate opened
{
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate
Open{0} == false;//false for closed
}
case false://If the gate closed
{
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{0} == true;//true for opened
}
}
}
else if(IsPlayerInRangeOfPoint(playerid,10,xxx,yyy,zzz)//Gate 2
{
switch(Open{1})//Check whether the gate opened or closed
{
case true://If the gate opened
{
MoveObject(Gate[1],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate
Open{1} == false;//false for closed
}
case false://If the gate closed
{
MoveObject(Gate[2],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{1} == true;//true for opened
}
}
}
else if(IsPlayerInRangeOfPoint(playerid,10,xxx,yyy,zzz)//Gate 3
{
switch(Open{2})//Check whether the gate opened or closed
{
case true://If the gate opened
{
MoveObject(Gate[3],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate
Open{2} == false;//false for closed
}
case false://If the gate closed
{
MoveObject(Gate[3],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{2} == true;//true for opened
}
}
}
}
}
return 1;
}
CMD:gate(playerid,params[])
{
if(IsPlayerInRangeOfPoint(playerid,10,xxx,yyy,zzz)//Gate 1
{
switch(Open{0})//Check whether the gate opened or closed
{
case true://If the gate opened
{
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate
Open{0} == false;//false for closed
}
case false://If the gate closed
{
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{0} == true;//true for opened
}
}
return 1;
}
if(IsPlayerInRangeOfPoint(playerid,10,xxx,yyy,zzz)//Gate 2
{
switch(Open{1})//Check whether the gate opened or closed
{
case true://If the gate opened
{
MoveObject(Gate[1],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate
Open{1} == false;//false for closed
}
case false://If the gate closed
{
MoveObject(Gate[1],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{1} == true;//true for opened
}
}
return 1;
}
if(IsPlayerInRangeOfPoint(playerid,10,xxx,yyy,zzz)//Gate 3
{
switch(Open{2})//Check whether the gate opened or closed
{
case true://If the gate opened
{
MoveObject(Gate[2],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate
Open{2} == false;//false for closed
}
case false://If the gate closed
{
MoveObject(Gate[2],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{2} == true;//true for opened
}
}
return 1;
}
SendClientMessage(playerid,color,"You're not close enough to any gate.");//Send error message if player isn't near any gate
return 1;
}
//On top of your script
new GateTimer[MAX_GATES];//Change MAX_GATES to How much gate you have
forward GateMovement1();
forward GateMovement2();
forward GateMovement3();
public OnFilterScriptInit()
{
//blahblahblah you create the gate and stuff.........
GateTimer[0] = SetTimer("GateMovement1",5000,1)//Start the timer
GateTimer[1] = SetTimer("GateMovement2",5000,1)
GateTimer[2] = SetTimer("GateMovement3",5000,1)
return 1;
}
public GateMovement1()
{
switch(Open{0})//Check whether the gate opened or closed
{
case true://If the gate opened
{
foreach(Player,i)//For more information about foreach: https://sampforum.blast.hk/showthread.php?tid=92679
{
if(IsPlayerInRangeOfPoint(i,10,xxx,yyy,zzz)) return 1;//If someone near the gate, the gate will remain opened
}
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate if there's nobody near the gate
Open{0} == false;//false for closed
}
case false://If the gate closed
{
foreach(Player,i)
{
if(IsPlayerInRangeOfPoint(i,10,xxx,yyy,zzz))//If someone near the gate, the gate will open
{
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{0} == true;//true for opened
return 1;
}
}
}
}
return 1;
}
//Create GateMovement2 and GateMovement3 too by your self just like the code above. Just change "0" to "1" and so on.
if (IsPlayerInRangeOfPoint(playerid,posRange,whereX,whereY,whereZ))
{
Open{0} = !Open{0}; // Sets Open variable to the opposite side as it's current side (false = true, true = false).
switch(Open{0})// Switch depends what is the current state.
{
case true : // Gate should be opened
MoveObject(Gate[0],openX,openY,openZ,moveSpeed ); // Gate[ 0 ] = the object
default : // Else, gate should be closed
MoveObject(Gate[0],closeX,closeY,closeZ,moveSpeed ); // Gate[ 0 ] = the object
}
return 1;
}
stock IsNearGate(playerid)
{
for(new a;a<sizeof(GatePos);a++)
{
if(IsPlayerInRangeOfPoint(playerid,10,GatePos[a][0],GatePos[a][1],GatePos[a][2])
{
OnGate[playerid] = a;
return 1;
}
}
return 0;
if(IsPlayerInRangeOfPoint(playerid,10,xxx,yyy,zzz)//Gate 1
{
switch(Open{0})//Check whether the gate opened or closed
{
case true://If the gate opened
{
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Close the gate
Open{0} == false;//false for closed
}
case false://If the gate closed
{
MoveObject(Gate[0],Float:X,Float:Y,Float:Z,Float:Speed);//Open the gate
Open{0} == true;//true for opened
}
}
}
if ( IsPlayerInRangeOfPoint( playerid, posRange, whereX, whereY, whereZ ) )
{
Open{ 0 } = ! Open{ 0 }; // Sets Open variable to the opposite side as it's current side ( false = true, true = false ).
// Why { } ? Because we are using CHAR-ARRAYS, which is limited to ' 255 '.
switch ( Open{ 0 } ) // Switch depends what is the current state.
{
case true : // Gate should be opened
MoveObject( Gate[ 0 ], openX, openY, openZ, moveSpeed ); // Gate[ 0 ] = the object
default : // Else, gate should be closed
MoveObject( Gate[ 0 ], closeX, closeY, closeZ, moveSpeed ); // Gate[ 0 ] = the object
}
}
new OnGate[MAX_PLAYERS char];
OnGate[playerid] = a; // Wrong
MoveObject(Gate[OnGate[playerid]], ... ) // Wrong
Also I think you can do a simpler way on this
pawn Code:
pawn Code:
|
No idea why you are not using char-arrays to the ' Gate ' variable, when you used ' OnGate ' variable to an char-array ( 8bits ) to the size of gate positions.
Plus, char arrays need to use { } not [ ] pawn Code:
|
//automatic
//Change the coordinate by yourself
#define FILTERSCRIPT
#include <a_samp>
#include <foreach>//Download this include if you don't have one
#define MAX_GATES 1
new Gate[MAX_GATES],
bool:Open[MAX_GATES char];
new GateTimer[MAX_GATES];
forward GateMovement1();
public OnFilterScriptInit()
{
Gate[0] = CreateObject(980,2044.09997559,1313.50000000,12.39999962,0.00000000,0.00000000,2.00000000);
GateTimer[0] = SetTimer("GateMovement1",5000,1);
return 1;
}
public GateMovement1()
{
switch(Open{0})
{
case true:
{
foreach(Player,i)
{
if(IsPlayerInRangeOfPoint(i,10,2044.09997559,1313.50000000,12.39999962)) return 1;
}
MoveObject(Gate[0],2044.09997559,1313.50000000,6.39999962,1);
Open{0} == false;
}
case false:
{
foreach(Player,i)
{
if(IsPlayerInRangeOfPoint(i,10,2044.09997559,1313.50000000,12.39999962))
{
MoveObject(Gate[0],10,2044.09997559,1313.50000000,6.39999962,1);
Open{0} == true;
return 1;
}
}
}
}
return 1;
}