25.07.2012, 14:32
Quote:
i have done a script with gates but only the player with highest id can open them
|
Your call MoveObject to open the gate if the current player which is checked is in range of the gate, if not it closes
Lets make an example why this dont work
- Player isnt near => close
- Player is near => open
- Player isnt near => close
Just open the gate if someone is near and ignore the rest of the player
- Player is near => close
- Player is near => open
- ignored
If you want to use an array, it could look like that
But you shouldnt use that code if you dont understand it
pawn Код:
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]
;
pawn Код:
// OnGameModeInit
gGateData[0] = CreateObject(...); // instead of ArmyGate1 =
gGateData[1] = CreateObject(...); // instead of ArmyGate2 =
pawn Код:
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
}
}
}
}