14.07.2013, 05:23
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.
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
}
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;
}