public AutoTor()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
/* if(IsPlayerInRangeOfPoint( i, 15,345.27, 1797.73, 19.45))
{
MoveObject(ArmyGate3l,339.28, 1793.84, 18.31, 3, 0.00, 0.00, 33.02);
MoveObject(ArmyGate3r,351.15, 1801.99, 18.31, 3, 0.00, 0.00, 35.95);
}
else
{
MoveObject(ArmyGate3l,342.90, 1796.20, 18.31, 3, 0.00, 0.00, 33.02);
MoveObject(ArmyGate3r,347.55, 1799.39, 18.31, 3, 0.00, 0.00, 35.95);
}*/
if(IsPlayerInRangeOfPoint( i, 15, 286.03, 1820.46, 19.94))
{
MoveObject(ArmyGate1,286.03, 1833.72, 19.94, 3, 0.00, 0.00, 90.00);
}
else
{
MoveObject(ArmyGate1,286.03, 1820.46, 19.94, 3, 0.00, 0.00, 90.00);
}
if(IsPlayerInRangeOfPoint( i, 15, 134.92, 1941.57, 21.64))
{
MoveObject(ArmyGate2, 120.84, 1941.57, 21.62, 3, 0.00, 0.00, 0.00);
}
else
{
MoveObject(ArmyGate2,134.92, 1941.57, 21.64, 3, 0.00, 0.00, 0.00);
}
}
}
return 1;
}
i have done a script with gates but only the player with highest id can open them
|
stock const
Float: gGateInfo[][12] = {
{ // ArmyGate1
286.03, 1833.72, 19.94, 0.00, 0.00, 90.00, // opend
286.03, 1820.46, 19.94, 0.00, 0.00, 90.00 // closed
}, { // ArmyGate2
120.84, 1941.57, 21.62, 0.00, 0.00, 0.00, // opend
134.92, 1941.57, 21.64, 0.00, 0.00, 0.00 // closed
}
}
;
stock
gGateData[sizeof gGateInfo]
;
// OnGameModeInit
gGateData[0] = CreateObject(...); // instead of ArmyGate1 =
gGateData[1] = CreateObject(...); // instead of ArmyGate2 =
public AutoTor() {
static const
Float: speed = 3.0,
opendFlag = 1 << (cellbits - 1)
;
new
i,
count,
connected[MAX_PLAYERS]
;
for( ; i != MAX_PLAYERS; i++) {
if(IsPlayerConnected(i)) {
connected[count++] = i;
}
}
for(new g; g != sizeof gGateData; g++) {
for(i = count; --i != -1; ) {
if(IsPlayerInRangeOfPoint(connected[i], 15.0, gGateInfo[g][6], gGateInfo[g][7], gGateInfo[g][8])) {
break; // stops the loop if someone is near the gate
}
}
if(i == -1) { // noone found
if(gGateData[g] & opendFlag) { // gate is opend
gGateData[g] ^= openedFlag; // removing flag
MoveObject(gGateData[0], // closing gate
gGateInfo[g][6], gGateInfo[g][7], gGateInfo[g][8], speed,
gGateInfo[g][9], gGateInfo[g][10], gGateInfo[g][11]
);
}
} else { // someone near the gate
if((gGateData[g] & opendFlag) == 0) { // closed
MoveObject(gGateData[0], // opening gate
gGateInfo[g][0], gGateInfo[g][1], gGateInfo[g][2], speed,
gGateInfo[g][3], gGateInfo[g][4], gGateInfo[g][5]
);
gGateData[g] ^= openedFlag; // adding flag
}
}
}
}
If you want to use an array, it could look like that
But you shouldnt use that code if you dont understand it |
public AutoTor() {
new
bool: openArmyGate1,
bool: openArmyGate2
;
for(new i; i < MAX_PLAYERS; i++) {
if(IsPlayerConnected(i)) {
if(!openArmyGate1 && IsPlayerInRangeOfPoint( i, 15, 286.03, 1820.46, 19.94)) {
openArmyGate1 = true;
}
else if(!openArmyGate2 && IsPlayerInRangeOfPoint( i, 15, 134.92, 1941.57, 21.64)) {
openArmyGate2 = true;
}
}
}
if(openArmyGate1) {
MoveObject(ArmyGate1, 286.03, 1833.72, 19.94, 3, 0.00, 0.00, 90.00);
} else {
MoveObject(ArmyGate1, 286.03, 1820.46, 19.94, 3, 0.00, 0.00, 90.00);
}
if(openArmyGate2) {
MoveObject(ArmyGate2, 120.84, 1941.57, 21.62, 3, 0.00, 0.00, 0.00);
} else {
MoveObject(ArmyGate2, 134.92, 1941.57, 21.64, 3, 0.00, 0.00, 0.00);
}
}
public OnPlayerUpdate(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, 15, 286.03, 1820.46, 19.94))
{
AutoTor1P=playerid;
MoveObject(ArmyGate1,286.03, 1833.72, 19.94, 3, 0.00, 0.00, 90.00);//offen Gate1
AutoTor1S = SetTimer("AutoTor1",1000,true);
}
return 1;
}
forward AutoTor1();
public AutoTor1()
{
if(!IsPlayerInRangeOfPoint(AutoTor1P,15,286.03, 1820.46, 19.94))
{
MoveObject(ArmyGate1,286.03, 1820.46, 19.94, 3, 0.00, 0.00, 90.00);//zu Gate1
KillTimer(AutoTor1S);
}
}