public void OnConfigsExecuted()
{
CreateTimer(g_Cvar_fInterval, Timer_Task, _, TIMER_FLAG_NO_MAPCHANGE);
}
void KillTimerEx(Handle hTimer)
{
if(hTimer)
{
CloseHandle(hTimer);
hTimer = null;
}
}
public Action Timer_Task(Handle hTimer)
{
if(!LogPath[0]) BuildPath(Path_SM, LogPath, sizeof(LogPath), "logs/SHOP_Number_Random.log");
int k = 0;
for(int i = 1; i <= MaxClients; i++)
if(IsClientInGame(i) && GetClientTeam(i) > 1 && ++k >= g_Cvar_iNumberPlayer)
break;
if (k >= g_Cvar_iNumberPlayer)
{
g_iRandom = GetRandomInt(g_Cvar_iNumbersMin, g_Cvar_iNumbersMax);
CPrintToChatAll("%t {red}Я загадал число от {green}%d {red}до {green}%d{red}, отгадай его и получи {green}%d кредитов", "Tag", g_Cvar_iNumbersMin, g_Cvar_iNumbersMax, g_Cvar_iCredits);
if(g_hAnswerWaitTimer) CloseHandle(g_hAnswerWaitTimer);
g_hAnswerWaitTimer = CreateTimer(g_Cvar_fAnswerTime, Timer_Answer);
g_iPosition = 0;
if(g_Cvar_Logs == 1) LogToFileEx(LogPath, "Создано число: %d", g_iRandom);
}
for(int i = 1; i <= MaxClients; ++i) iLimitCount[i] = g_Cvar_iCountLimit;
CreateTimer(g_Cvar_fInterval, Timer_Task, _, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
public Action Timer_Answer(Handle hTimer)
{
g_hAnswerWaitTimer = null;
CPrintToChatAll("%t", "Tag", "Waiting for a response is over");
if(g_Cvar_Logs == 1) LogToFileEx(LogPath, "Ожидание ответа окончено");
return Plugin_Stop;
}
public Action Say(int iClient, const char[] command, int iArgs)
{
if(g_hAnswerWaitTimer && iClient && iClient <= MaxClients)
{
char text[16], yourtext[16];
GetCmdArg(1, text, sizeof(text));
if((IsCharNumeric(text[0]) || text[0] == '-') && iLimitCount[iClient] > 0)
{
FormatEx(yourtext, sizeof(yourtext), "%d", g_iRandom);
if(!strcmp(text, yourtext, true))
{
g_iPosition++;
Shop_GiveClientCredits(iClient, g_Cvar_iCredits);
CPrintToChatAll("%t {green}%N {red} угадал число и получил {green}%d{red} кредитов{default}!", "Tag", iClient, g_Cvar_iCredits);
if(g_iPosition >= g_Cvar_iNumberPrizes) KillTimerEx(g_hAnswerWaitTimer);
}
else
{
iLimitCount[iClient]--;
CPrintToChat(iClient, "%t {red}К сожалению это неправильный ответ{default}!", "Tag");
if(iLimitCount[iClient] < g_Cvar_iCountLimit)
{
CPrintToChat(iClient, "%t {red}У тебя осталось попыток: {green}%d{default}", "Tag", iLimitCount[iClient]);
}
else
{
CPrintToChat(iClient, "%t {red}У тебя осталось попыток: {green}%d{default}", "Tag", iLimitCount[iClient]-1);
}
if(!iLimitCount[iClient])
{
CPrintToChat(iClient, "%t {red}Попытки закончились{default} ({green}лимит: {red}%d попытки{default})", "Tag", g_Cvar_iCountLimit);
}
}
}
}
return Plugin_Continue;
}