AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   remaining round time (https://forums.alliedmods.net/showthread.php?t=60027)

freamer 08-25-2007 14:00

remaining round time
 
Could anyone suggest me a best method to get remaining round time in seconds? (counter-strike mod)

hlstriker 08-25-2007 14:11

Re: remaining round time
 
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.

freamer 08-25-2007 14:31

Re: remaining round time
 
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 :D 1.75 * 60
///////////////
Will that work?
new roundtime = floatround(floatmul(get_cvar_float("mp_roundt ime"), 60.0))

ConnorMcLeod 08-25-2007 15:17

Re: remaining round time
 
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 }

Lee 08-25-2007 15:28

Re: remaining round time
 
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)

ConnorMcLeod 08-25-2007 17:11

Re: remaining round time
 
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 }


All times are GMT -4. The time now is 16:13.

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