IG timer?
#1

I wonder how can I set a timer in the game with a command so after the timer passed the planted bomb will explode. Just like a time bomb.
Reply
#2

Make a command, when the player uses the command save his position to a global variables, and set a timer for when you want the explosion to happen. Inside the timer function create an explosion at the position stored in the global variables.

If you want code then show us what you have tried so far.
Reply
#3

I mean like that the player can set the bomb timer like this /plantbomb [time]. Similar to jail commands I just need the timer that the player can set ingame after the timer passed the bomb will explode just like that, so far I don't need help with anything else then the timer tho
Reply
#4

Well actually you wouldn't use global vars like i said before, just pass the position to the timer func:

pawn Код:
COMMAND:plantbomb(playerid, params[])
{
    //store the number the player entered, in your version check if its numeric.
    new iSeconds = strval(params);

    new Float: fBombX, Float: fBombY, Float: fBombZ;

    GetPlayerPos( playerid, fBombX, fBombY, fBombZ );

    //check to make sure player hasn't entered in a silly time (too long/short)
    if( iSeconds <= MAX_BOMB_COUNTDOWN && iSeconds > 1 )
    {
        //do *1000 on the time the player entered to convert seconds to millisecond
        SetTimerEx("BombFunc", iSeconds*1000, false, "fff", fBombX, fBombY, fBombZ );//pass players position
    }

    return 1;
}

//you could also pass playerid if needed
public BombFunc(Float: fBombX, Float: fBombY, Float: fBombZ)
{
    //create your explosion here
}
PS, pasting that code will cause errors. some things not defined/forwarded. You woud also have to check whether the player input is numeric.
Reply
#5

Thanks, I just did it quick like this
pawn Код:
public BombFunc(Float: fBombX, Float: fBombY, Float: fBombZ)
{
    CreateExplosion(fBombX, fBombY, fBombZ, 2, 10);
    return 1;
}

CMD:plantbomb(playerid, params[])
{
    new iSeconds = strval(params);
    new Float: fBombX, Float: fBombY, Float: fBombZ;
    GetPlayerPos(playerid, fBombX, fBombY, fBombZ );
    if( iSeconds <= MAX_BOMB_COUNTDOWN && iSeconds > 1 )
    {
        SetTimer("BombFunc", iSeconds*1000, false, "fff", fBombX, fBombY, fBombZ );//pass players position
    }
    return 1;
}
I defined and forwarded the things that needed to just getting warnings from this line
SetTimer("BombFunc", iSeconds*1000, false, "fff", fBombX, fBombY, fBombZ );
Reply
#6

Yes i edited my code use SetTimerEx, sorry about that.
Reply
#7

It's awesome thank you very much.
Reply
#8

No worries, you could make it look a lot better by applying an animation (i think there's a bomb planting one). Maybe create a bomb object, you could pass the objectid to the timer func to make sure it gets destroyed at the correct time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)