Raised This Month: $ Target: $400
 0% 

remaining round time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
freamer
Member
Join Date: Nov 2005
Old 08-25-2007 , 14:00   remaining round time
Reply With Quote #1

Could anyone suggest me a best method to get remaining round time in seconds? (counter-strike mod)
freamer is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 08-25-2007 , 14:11   Re: remaining round time
Reply With Quote #2

I believe to do this you would have to:

1.) Hook when the round starts.
2.) Set a task to count how many seconds it is into the round.
3.) Subtract the seconds into the round from the mp_roundtime cvar.
hlstriker is offline
freamer
Member
Join Date: Nov 2005
Old 08-25-2007 , 14:31   Re: remaining round time
Reply With Quote #3

The mp_roundtime is set to 1.75,when the round starts,timer at the bottom of the screen, shows 1.45,so if i do as u mentioned in 3., things can go wrong
isnt that true?

...
soo... the question is how to convert 1.75 from mp_roundtime to real 1.45 = 105 seconds
...
okay 1.75 * 60
///////////////
Will that work?
new roundtime = floatround(floatmul(get_cvar_float("mp_roundt ime"), 60.0))

Last edited by freamer; 08-25-2007 at 15:01.
freamer is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-25-2007 , 15:17   Re: remaining round time
Reply With Quote #4

This will print each seconds and to every player how many seconds are remaining :

Code:
#include <amxmodx> #define TASKID 87654 new seconds, rt new roundtime public plugin_init() {     register_plugin("remaining seconds","0.1","connor")         register_logevent("eRoundStart", 2, "1=Round_Start")     register_logevent("eRoundEnd", 2, "1=Round_End")     register_event("TextMsg", "eRestart", "a", "2&#Game_C", "2&#Game_w")         roundtime = get_cvar_pointer("mp_roundtime") } public eRestart() {     if(task_exists(TASKID))         remove_task(TASKID) } public eRoundStart() {     seconds = 0     rt = floatround(get_pcvar_float(roundtime) * 60.0) - 1     set_task(1.0, "count", TASKID, _, _, "b") } public count(taskid) {     seconds++     client_print(0, print_center, "%i seconds left", rt - seconds) } public eRoundEnd() {     remove_task(TASKID)     seconds = 0 }
ConnorMcLeod is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 08-25-2007 , 15:28   Re: remaining round time
Reply With Quote #5

set_task() is never the right choice for counting seconds. Your snippet seems correct. You could use get_systime() at the start of each round and then again at the time of calculation.

Code:
roundTimeRemaining = floatround(floatmul(get_cvar_float("mp_roundtime"), 60.0)) - (get_systime() - roundStartTime)

Last edited by Lee; 08-25-2007 at 15:30.
Lee is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-25-2007 , 17:11   Re: remaining round time
Reply With Quote #6

You're right about get_systime that's better than set_task.
I wonder what is better to use, get_gametime or get_systime... (except the fact that one is Float).

But considering that mp_roundtime can be changed by an admin after the begining of a round, i think it's better to use a global and to set it each begining of round.

I think that this should do the trick :
Code:
#include <amxmodx> new started_time ,rt new roundtime public plugin_init() {     register_plugin("NAME","VERSION","AUTHOR")         register_logevent("eRoundStart", 2, "1=Round_Start")         roundtime = get_cvar_pointer("mp_roundtime")         register_clcmd("test","testCmd") } public eRoundStart() {     started_time = get_systime()     rt = floatround(floatmul(get_pcvar_float(roundtime), 60.0)) - 1 } get_remaining_seconds() {     new seconds_left = rt - (get_systime() - started_time)     return seconds_left } public testCmd(id) {     client_print(id, print_chat, "%i seconds remaining", get_remaining_seconds())     return PLUGIN_HANDLED }

Last edited by ConnorMcLeod; 08-25-2007 at 17:16.
ConnorMcLeod 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 16:13.


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