09.10.2014, 17:43
eu gostaria de um cronometro que quando termina-se a contagem ele ativa-se uma aзгo.
new timerContagem[MAX_PLAYERS]; //define uma variбvel em primeiro lugar para salvar o id do timer
new varContagem[MAX_PLAYERS]; //variбvel para a contagem regressiva
forward Regressivo(playerid); //define a callback
//Agora a criaзгo do callback
public Regressivo(playerid)
{
new str[50];
varContagem[playerid]--;
format(str, sizeof(str), "Tempo restante %d", varContagem[playerid]);
SendClientMessage(playerid, -1, str);
if(varContagem[playerid] < 1)
{
KillTimer(timerContagem);
varContagem[playerid] = 0;
SendClientMessage(playerid, -1, "Timer terminado");
}
return 1;
}
//E por fim sua aplicaзгo
CMD:iniciar(playerid, params[])
{
if(sscanf(params, "d", temp)) return SendClientMessage(playerid, "Uso: /iniciar [tempo]");
varContagem[playerid] = temp;
timerContagem[playerid] = SetTimerEx("Regressivo", 1000, true, "i", playerid);
return 1;
}
if( !strcmp( cmd, "/econtar", true )) { tmp = strtok(cmdtext, idx); if( !strlen( tmp )) { SendClientMessage( playerid, Vermelho, " | ERRO | Uso correto: /eContar [Segundos]" ); return 1; } new eSegundos = strval( tmp ) ; if( eSegundos < 1 || eSegundos > 60 ) { SendClientMessage( playerid, 0xFF0000AA, " | ERRO | Somente segundos para iniciar uma contagem de 1 a 60!" ); return 1; } ContagemRegressiva = eSegundos; eContageme(); return 1; } // NAS SUAS forward '-*' forward eContageme(); public eContageme() { foreach(Player, i) { if( ParticipandoEvento[ i ] == 1 ) { if( ContagemRegressiva == 0 ) { T_AntBug = -1; GameTextForAll( "~n~~r~~h~VALENDO!", 1000, 5 ); T_Rank = SetTimer( "RankEvento", 1000, true ); PlayerPlaySound( i, 1057, 0.0, 0.0, 0.0 ); SetCameraBehindPlayer( i ); TextDrawShowForPlayer( i, text_Top5[ 0 ] ); TextDrawShowForPlayer( i, text_Top5[ 1 ] ); } else { format( gStr, sizeof( gStr ), "~n~%d", ContagemRegressiva ); GameTextForAll( gStr, 1000, 5 ); ContagemRegressiva --; SetTimer( "eContageme", 1000, false ); PlayerPlaySound( i, 1056, 0.0, 0.0, 0.0 ); } return 1; } } return 1; }