SA-MP Forums Archive
IG timer? - 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: IG timer? (/showthread.php?tid=450653)



IG timer? - RALL0 - 14.07.2013

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.


Re: IG timer? - iggy1 - 14.07.2013

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.


Re: IG timer? - RALL0 - 14.07.2013

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


Re: IG timer? - iggy1 - 14.07.2013

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.


Re: IG timer? - RALL0 - 14.07.2013

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 );


Re: IG timer? - iggy1 - 14.07.2013

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


Re: IG timer? - RALL0 - 14.07.2013

It's awesome thank you very much.


Re: IG timer? - iggy1 - 14.07.2013

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.