Gates
#2

Quote:
Originally Posted by dalkgamler
Посмотреть сообщение
i have done a script with gates but only the player with highest id can open them
Hey, first we want to find out why this happens, so let us analyse your code.

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
  1. Player isnt near => close
  2. Player is near => open
  3. Player isnt near => close
So the last MoveObject call closes the object
Just open the gate if someone is near and ignore the rest of the player
  1. Player is near => close
  2. Player is near => open
  3. ignored
Gate opens


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
            }
        }
    }
}
Also your signature, it is not the fault of the country
Reply


Messages In This Thread
Gates - by dalkgamler - 25.07.2012, 12:59
AW: Gates - by Nero_3D - 25.07.2012, 14:32
AW: Gates - by dalkgamler - 25.07.2012, 16:01
AW: Gates - by dalkgamler - 25.07.2012, 16:07
AW: Gates - by Nero_3D - 25.07.2012, 17:59
AW: Gates - by dalkgamler - 26.07.2012, 06:53
AW: Gates - by dalkgamler - 27.07.2012, 06:41
Re: Gates - by dowster - 27.07.2012, 06:51
AW: Gates - by dalkgamler - 27.07.2012, 06:53
AW: Gates - by dalkgamler - 27.07.2012, 07:24

Forum Jump:


Users browsing this thread: 2 Guest(s)