Raised This Month: $51 Target: $400
 12% 

Countdown timer in menu!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KennYSwe
Member
Join Date: Nov 2016
Old 02-20-2017 , 12:19   Countdown timer in menu!
Reply With Quote #1

Hello!

Can someone give me an example on how to make a countdown timer and show it inside a menu?

I cant figure out how to do it

//KennY
KennYSwe is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-20-2017 , 12:22   Re: Countdown timer in menu!
Reply With Quote #2

Resend menu every time you want your timer to update
__________________
Pelipoika is offline
KennYSwe
Member
Join Date: Nov 2016
Old 02-20-2017 , 12:30   Re: Countdown timer in menu!
Reply With Quote #3

Quote:
Originally Posted by Pelipoika View Post
Resend menu every time you want your timer to update
Can you give me an example? becouse i want it to go backwards, not forwards.

like:
3.
2.
1.
not:
1.
2.
3.
KennYSwe is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 02-20-2017 , 12:31   Re: Countdown timer in menu!
Reply With Quote #4

No
__________________
Pelipoika is offline
Kriax
Senior Member
Join Date: Apr 2012
Old 02-22-2017 , 08:47   Re: Countdown timer in menu!
Reply With Quote #5

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.

Last edited by Kriax; 02-22-2017 at 08:49.
Kriax is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-22-2017 , 09:16   Re: Countdown timer in menu!
Reply With Quote #6

If you mean you want to change the menu item numbers, you cant using menus.
You have to use panels and write the items manually, then you can make them say anything
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
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
Kriax
Senior Member
Join Date: Apr 2012
Old 02-22-2017 , 11:34   Re: Countdown timer in menu!
Reply With Quote #8

np
Kriax is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode