Automatic gates
#1

This is very weird, not sure what's happening. The function stopped working seemingly without me doing anything to it.

IsPlayerInArea:
pawn Код:
forward isPlayerInArea();
public isPlayerInArea()
{
    new mibgate_status;
    new armygate1_status;
    new armygate2_status;
    new grovegate_status;
    new swatgate_status;
    new swatgate2_status;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
   
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerInRangeOfPoint(i, 10, 1877.0999800,705.0999800,14.2000000) && gTeam[i] == TEAM_MIB) mibgate_status = 1;

        if(IsPlayerInRangeOfPoint(i, 10, 3424.8994100,1393.0996100,34.1000000) && gTeam[i] == TEAM_ARMY) armygate1_status = 1;
        if(IsPlayerInRangeOfPoint(i, 10, 3424.8000500,1377.0999800,34.1000000) && gTeam[i] == TEAM_ARMY) armygate2_status = 1;
        if(IsPlayerInRangeOfPoint(i, 10, 2856.8999000,2613.6001000,12.5000000) && gTeam[i] == TEAM_GROVE) grovegate_status = 1;
        if(IsPlayerInRangeOfPoint(i, 10, 2529.3999000,2424.0000000,12.6000000) && gTeam[i] == TEAM_SWAT) swatgate_status = 1;
        if(IsPlayerInRangeOfPoint(i, 10, 2515.8999000,2475.8999000,12.6000000) && gTeam[i] == TEAM_SWAT) swatgate2_status = 1;
    }

    if(mibgate_status) MoveObject(mibgate, 1877.0999800, 715.0999800, 14.2000000, 3);
    else MoveObject(mibgate, 1877.0999800, 705.0999800, 14.2000000, 3);

    if(armygate1_status) MoveObject(armygate1, 3424.8994100,1403.0996100,34.1000000, 3);
    else MoveObject(armygate1, 3424.8994100,1393.0996100,34.1000000, 3);

    if(armygate2_status) MoveObject(armygate2, 3424.8000500,1367.0999800,34.1000000, 3);
    else MoveObject(armygate2, 3424.8000500,1377.0999800,34.1000000, 3);

    if(grovegate_status) MoveObject(grovegate, 2856.8999000,2603.6001000,12.5000000, 3);
    else MoveObject(grovegate, 2856.8999000,2613.6001000,12.5000000, 3);

    if(swatgate_status) MoveObject(swatgate, 2519.3999000,2424.0000000,12.6000000, 3);
    else MoveObject(swatgate, 2529.3999000,2424.0000000,12.6000000, 3);

    if(swatgate2_status) MoveObject(swatgate2, 2515.8999000,2465.8999000,12.6000000, 3);
    else MoveObject(swatgate2, 2515.8999000,2475.8999000,12.6000000, 3);
}
OnGameModeInit:
pawn Код:
mibgate = CreateObject(971,1877.0999800,705.0999800,14.2000000,0.0000000,0.0000000,90.0000000); //object(subwaygate) (1)
    armygate1 = CreateObject(980,3424.8994100,1393.0996100,34.1000000,0.0000000,0.0000000,270.0000000); //object(airportgate) (1)
    armygate2 = CreateObject(980,3424.8000500,1377.0999800,34.1000000,0.0000000,0.0000000,270.0000000); //object(airportgate) (2)
    swatgate = CreateObject(980,2529.3999000,2424.0000000,12.6000000,0.0000000,0.0000000,0.0000000); //object(airportgate) (3)
    swatgate2 = CreateObject(980,2515.8999000,2475.8999000,12.6000000,0.0000000,0.0000000,270.0000000); //object(airportgate) (4)
    grovegate = CreateObject(975,2856.8999000,2613.6001000,12.5000000,0.0000000,0.0000000,268.0000000); //object(columbiangate) (1)
....
    SetTimer("isPlayerInArea", 1000, true);
...
Globally declared variables:
pawn Код:
new mibgate;
    new grovegate;
    new swatgate;
    new swatgate2;
    new armygate1;
    new armygate2;
Any idea why it's not working?
Reply
#2

What isn't working, if it was placed in an Enum of start and end positions I could reply strat away but this is just a bunch of variables... Therefore whats the problem so I dont ave to read it all?
Reply
#3

Never mind, the timer was being killed on in another place in my script. I fixed it, but this leads me to wonder that it could happen anywhere else in my script. Any tips for killing the timers you're meaning to kill? I've always assigned it to an array but I guess that's not good enough.

EDIT:
For example, I'll kill a timer once a countdown is down, but just incase that player leaves before the countdown is done, I'll kill it again on disconnect. Better way to do this?
Reply
#4

I recommend usin mGates by MP2, simplifies the process in making gates!
As for the timers, make a function like this

pawn Код:
new bool:GateOpen[10];

forward isPlayerInArea();
public isPlayerInArea()
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 10.0, 0.0000, 0.0000, 0.0000); OpenGate(0); //mibgate
        else if(IsPlayerInRangeOfPoint(i, 10.0, 0.000, 0.0000, 0.0000) OpenGate(1); // Some other gate
    }
    return 1;
}

forward OpenGate(Gate);
public OpenGate(Gate)
{
    switch(Gate)
    {
        case 0: // For example mibgate
        {
            if(!GateOpen[Gate])
            {
                MoveDynamicObject(mibgate, 0.0000, 0.0000, 0.0000, 0.5);
                SetTimerEx("CloseGate", 7000, false, "i", Gate);
                GateOpen[Gate] = true;
            }
        }
    }
    return 1;
}

forward CloseGate(Gate);
public CloseGate(Gate)
{
    switch(Gate)
    {
        case 0: // mibgate
        {
            MoveDynamicObject(mibgate, 0.0000, 0.0000, 0.0000, 0.5);
            GateOpen[Gate] = false;
        }
    }
    return 1;
}
As for the isPlayerInArea, you could do it like this with y_timers (include by ******)

pawn Код:
ptask isPlayerInArea[1000](playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 10.0, 0.0000, 0.0000, 0.0000); OpenGate(0); // mibgate
}
Shortens it down a lot if you ask me.
Reply
#5

Ok and back to the problems at hand. Lets say a timer is stored at idk..countertimer[playerid] and it's assigned a timer when someone does /timer, it's killed when the timer hits 0, and when the player disconnects. So if a player disconnects, a player who never done the /timer command, what happens? If it's something bad how to fix?
Reply
#6

Great, a different bug now. We can't damage eachother by punching eachother. I must be a very shitty scripter.
Reply
#7

Quote:
Originally Posted by Knappen
Посмотреть сообщение
I recommend usin mGates by MP2, simplifies the process in making gates!
^ this

I don't like 'advertising' my scripts, but mGates is especially useful. If you script your own gates you have to script the creation, the deletion, the distance checks, the skin/class/job/whatever checks 'conditions', the openning, the closing automatically etc. and it can take a LOT of time if you're a beginner, as it's not just CreateGate(x, y, z); - everything has to work together.

mGates does all the work for you - all you have to supply is the closed gate coordinates, the open gate coordinates, and the trigger point. Then you can script the conditions, which are relatively simple (see the topic).

http://forum.sa-mp.com/showthread.ph...33#post1908733
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)