AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to make a countdown in HUD [SOLVED] (https://forums.alliedmods.net/showthread.php?t=47940)

mateo10 11-30-2006 12:25

How to make a countdown in HUD [SOLVED]
 
Hello, my title is very descriptive so I'll be short.

I need to know how to make a HUD message which counts from an hour
to 1 second

Da_sk8rboy 11-30-2006 12:29

Re: How to make a countdown in HUD
 
umm... the hud msg generator in studio?

jim_yang 11-30-2006 12:33

Re: How to make a countdown in HUD
 
set_task(1.0,"count_down",1234567,"",0,"a",36 00)
public count_down()
{


}

The Specialist 11-30-2006 12:37

Re: How to make a countdown in HUD
 
oviously he's not asking how to make a hud message . He needs help making it count.

Code:
new Second_Counter;   set_task(1.0,"my_clock",0,"",0,"b");   public my_clock() { --SecondCounter;set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 6.0, 12.0); show_hudmessage(id, "second left are %i",Second_COUnter);

mateo10 11-30-2006 12:53

Re: How to make a countdown in HUD
 
Does this work?
Code:
#include <amxmodx> #include <amxmisc> new g_Switch, g_Time new Hour, Minute, Second public plugin_init() {     register_plugin("Server Restart","1.2","MaTTe (mateo10)")         g_Switch = register_cvar("server_restart", "1")     g_Time = register_cvar("server_restarttime", "3600.0")         set_task(get_pcvar_float(g_Time), "restartServer")     set_task(3600.0, "HourCounter", 0, "", 0, "b")     set_task(60.0, "MinuteCounter", 0, "", 0, "b")     set_task(1.0, "SecondCounter", 0, "", 0, "b") } public CountDown() {     set_hudmessage(0, 0, 255, -1.0, 0.0, 0, 6.0, 1.0)     show_hudmessage(0, "Server Restart In %i:%i:%i", Hour, Minute, Second) } public restartServer(id) {     if(get_pcvar_num(g_Switch)==1)     {         server_cmd("exec server.cfg")         server_cmd("restart")         client_print(0, print_console, "Hourly server restart")     }else{         client_print(id, print_console, "The server restart plugin is disabled.")         return PLUGIN_HANDLED     }     return PLUGIN_CONTINUE } public HourCounter() {     --Hour     set_task(0.0, "CountDown") } public MinuteCounter() {     --Minute     set_task(0.0, "CountDown") } public SecondCounter() {     --Second     set_task(0.0, "CountDown") }

Da_sk8rboy 11-30-2006 18:16

Re: How to make a countdown in HUD
 
compile it & find out.

Zenith77 11-30-2006 20:20

Re: How to make a countdown in HUD
 
There are some logic and general code flaws and you're a bit confused on what the task id is. I'd search around the forum for more info and also consult the funcwiki on the main page.

Brad 11-30-2006 20:43

Re: How to make a countdown in HUD
 
I hope you're happy. You made my eyes bleed. :wink:

I would suggest searching the forums for other plugins that have a countdown and see how they did it.

By the way, while you don't need so many set_task calls, it is acceptable to use 0 as each of their task ids in this context. This context being that you're not manually ending the tasks later. However, I'd suggest using _ instead of 0 when the task id isn't meaningful, such as how you're using it. The _ is used when you want to accept the default value for an argument.

stupok 11-30-2006 21:01

Re: How to make a countdown in HUD
 
I wanted to try my hand at this, since I'm relatively new to writing programs. I spent a while figuring out how to do the counter nicely.

The code below should work fine, though the hudmessage is untested. (I tested it with server_print.) Anyway, I'd really appreciate some feedback on this. If you can do this better, or more efficiently, please show me how.

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #define PLUGIN "Restart Timer" #define VERSION "1.0" #define AUTHOR "stupok69" new itimer new clocktime[8] new start_time public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         start_time = register_cvar("restart_server_time", "0")     itimer = get_pcvar_num(start_time)         register_concmd("startcounter", "set_clock", ADMIN_SLAY, "-displays timer, restarts server when finished") } public set_clock(id, level, cid) {     if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED         set_task(1.0,"my_clock",0,"",0,"a", itimer)     set_task(0.1,"display_clock",0,"",0,"b")         return PLUGIN_CONTINUE }   public my_clock() {       output_hms(--itimer, clocktime, 7)         if(itimer == 0) server_cmd("restart") } public display_clock() {     set_hudmessage(255, 255, 255, 0.5, 0.3, 0, 6.0, 12.0)     show_hudmessage(0, "Server Restart In %s", clocktime) } output_hms(inputseconds, outputstring[], outputlen) {     if(!inputseconds) return 0         new hours, minutes, seconds, h, m, s         if(inputseconds > 3600)     {         for(h = inputseconds; h >= 3600; h -= 3600)         {                     }             hours = (inputseconds - h) / 3600     }     else     {         hours = 0     }         if(inputseconds > 60)     {         for(s = inputseconds; s >= 60; s -= 60)         {                     }                 seconds = s                 minutes = (inputseconds - s) / 60                 for(m = minutes; m >= 60; m -= 60)         {                     }                 minutes = m     }     else     {         minutes = 0         seconds = inputseconds - 1     }         format(outputstring, outputlen, "%i:%i:%i", hours, minutes, seconds)         return 1 }

Zenith77 11-30-2006 21:42

Re: How to make a countdown in HUD
 
http://forums.alliedmods.net/attachm...1&d=1160097414

I think this should answer your question a little, I made for a request some time ago.


All times are GMT -4. The time now is 06:54.

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