SA-MP Forums Archive
Gates - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Gates (/showthread.php?tid=362729)



Gates - dalkgamler - 25.07.2012

i have done a script with gates but only the player with highest id can open them
pawn Код:
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;
}



AW: Gates - Nero_3D - 25.07.2012

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


AW: Gates - dalkgamler - 25.07.2012

sry i cant understand it is to complicated for me is their another way to do automatic gates?
or is it the only possible version

sry i was 13 when i created the signature i should write I'm a bad student from germany


AW: Gates - dalkgamler - 25.07.2012

i have it from a tutorial like this
https://sampforum.blast.hk/showthread.php?tid=279757


AW: Gates - Nero_3D - 25.07.2012

I put this disclaimer on top...
Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
If you want to use an array, it could look like that
But you shouldnt use that code if you dont understand it
The array thing way easier to use if you understand how it works

----

If I compare your code and the code in the tutorial the open variable is missing
pawn Код:
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);
    }
}



AW: Gates - dalkgamler - 26.07.2012

Maybe i understand if you discribe me in german
my skype account is xhoomerx


AW: Gates - dalkgamler - 27.07.2012

pls help


Re: Gates - dowster - 27.07.2012

What's going on here is that the gate will open for a player with say ID 80, but when it goes to check ID 81, and they aren't near the gate, it will close the gate. What you should do is have a function in OnPlayerUpdate to check if they are in range of the gate, if they are have it open the gate and set a timer to close the gate.


AW: Gates - dalkgamler - 27.07.2012

i try this


AW: Gates - dalkgamler - 27.07.2012

for now i have this
pawn Код:
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;
}
pawn Код:
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);
    }
}
do you think it work?