View Single Post
KennYSwe
Member
Join Date: Nov 2016
Old 02-22-2017 , 09:58   Re: Countdown timer in menu!
Reply With Quote #7

Quote:
Originally Posted by Kriax View Post
This is a Exemple.
Code:
#include <sourcemod>

Handle g_hTimer[MAXPLAYERS + 1];
int g_Time[MAXPLAYERS + 1];

public void OnPluginStart()
{
    RegConsoleCmd("sm_timer", Command_Timer);
}

public Action Command_Timer(int client, int args)
{
    if(!IsClientInGame(client))
        return Plugin_Handled;
    
    if(g_Time[client] > 0)
        return Plugin_Handled;
    
    g_Time[client] = 10;
    g_hTimer[client] = CreateTimer(1.0, Timer_Exemple, client, TIMER_REPEAT);

    return Plugin_Handled;
}

public Action Timer_Exemple(Handle timer, any client)
{
    if(!IsClientInGame(client))
        return Plugin_Stop;
    
    g_Time[client]--;
    
    if(g_Time[client] > 0)
        ExempleMenu(client);
    
    if(g_Time[client] == 0)
        return Plugin_Stop;
    
    return Plugin_Continue;
}

public void ExempleMenu(int client)
{
    Menu menu = new Menu(MenuHandler_Exemple);
    menu.SetTitle("Exemple Menu");
    menu.AddItem("option1", "Option 1");
    menu.AddItem("option2", "Option 2");
    
    char szTime[32];
    Format(szTime, sizeof(szTime), "Option Timer: %i", g_Time[client]);
    menu.AddItem("optiontimer", szTime);
    
    menu.AddItem("option3", "Option 3");
    menu.AddItem("option4", "Option 4");
    
    menu.ExitButton = false;
    menu.Display(client, 1);
}

public int MenuHandler_Exemple(Menu menu, MenuAction action, int client, int param)
{
    if(action == MenuAction_Select)
    {
        char szParam[16];
        GetMenuItem(menu, param, szParam, sizeof(szParam));

        PrintToChat(client, "You'r choice is %s. You'r time is at %i seconds from the end", szParam, g_Time[client]);
        
        g_Time[client] = 0;
    }
    if(action == MenuAction_End)
        delete menu;
}
Remember to check that you have no other open menu, otherwise they will be crushed
Sorry for my bad English.
Thank you, exactly what i needed.
KennYSwe is offline