airstrike goes always to playerid 0
#2

You are user SetTimer on callbacks that require a parameter, you need to use SetTimerEx to pass a parameter to your callbacks, for example:

pawn Код:
SetTimer("sec5",1000,0, "i", playerid); // Passes the value of playerid as the first argument
If you do not pass an argument, then it will default the playerid variable in the function to 0 and hence any of the functions that use the playerid variable will then be executing on the ID of 0.

Also your code is rather messy, having that many callbacks for something as simple as a countdown? Why not use 1 callback? You could even avoid creating a large array for all of your players by using a simple trick with the callback parameters:

pawn Код:
public countdown(playerid, count)
{
    if((count - 1) >= 0)
    {
        new tmpstr[2];
        SendClientMessage(playerid, 0xFF3333FF, tmpstr);

        printf("Countdown: %s", tmpstr);
       
        SetTimerEx("countdown", 1000, 0, "ii", playerid, count - 1);
    }
    else
    {
        SendClientMessage(playerid, 0xFF3333FF, "FIRE");
        GetPlayerObjectPos(playerid, Marker, X, Y, Z);
        GetObjectPos(bomberplane, X, Y, Z);
        MoveObject(bomberplane, X, Y + 1000, Z + 100, 130);
        SetTimer("bomberbomb_1", 6000, 0);
        SetTimer("bomberdestroy1", 10000, 0);
    }
}
Now you can use it for a range of different times and it has the same effect, all in one callback instead of 6, so you can delete all of the "sec" callbacks and the ignition callback!

If you wanted to start it off in your current context, you would just do this:

pawn Код:
SetTimer("countdown", 1000, 0, "ii", playerid, 5); // Passes the value of playerid as the first argument and second argument as 5, which is how long the countdown will last
That would start the countdown for that player for 6 seconds (including the starting second) and then when the further 5 seconds are up, ignition!

You could also call it using

pawn Код:
countdown(playerid, 5);
Which will in essence make it exactly 5 seconds as there is no original 1 second wait for the first countdown.
Reply


Messages In This Thread
airstrike goes always to playerid 0 - by speediekiller2 - 04.05.2012, 14:02
Re: airstrike goes always to playerid 0 - by JaTochNietDan - 04.05.2012, 15:25

Forum Jump:


Users browsing this thread: 1 Guest(s)