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

Add milliseconds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 10-17-2020 , 09:07   Add milliseconds
Reply With Quote #1

Hey, i wondered how to add milliseconds to this plugin? Because when i searched on google there wasnt what i needed...
Any help is appreciated.

PHP Code:
/* Plugin generated by AMXX-Studio */


#include <amxmodx>
#include <cstrike>

#define PLUGIN "Auto Restart vl"
#define VERSION "1.4"
#define AUTHOR "vato loco [GE-S]"

#define TIMER_TASK        123456
#define RESTART_TASK      789123

new g_counter  

new g_autorestart
new g_autoenabled
new g_autocds
new g_autocount_color
new g_autostart_color
new g_auto_xypos

new g_SyncRestartTimer

new bool:g_bRoundStart 

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_logevent("RoundStart"2"1=Round_Start")
    
register_event("TextMsg","RestartTask","a","2&#Game_C")   
    
    
register_dictionary("auto_restart_vl.txt")
    
    
g_autoenabled register_cvar("amx_autorr_enable","1")
    
g_autocds register_cvar("amx_autorr_cds","1")
    
g_autorestart register_cvar("amx_autorr_time","15")
    
g_autocount_color register_cvar("amx_autorr_count_color","255 0 0")
    
g_autostart_color register_cvar("amx_autorr_start_color","0 255 255")
    
g_auto_xypos register_cvar("amx_autorr_xypos","-1.0 0.25")
    
    
g_SyncRestartTimer CreateHudSyncObj()
}

public 
RoundStart()
{
    if(!
get_pcvar_num(g_autoenabled))
        return 
PLUGIN_HANDLED
    
    
if(g_bRoundStart)
    {
        static 
rgbFloat:xFloat:y
        HudMsgPos
(x,y)
        
HudMsgColor(g_autostart_colorrgb)
        
        
set_hudmessagerandom(256),random(256),random(256), xy15.08.00.00.0, -1)
    }
    
g_bRoundStart false
    
    
return PLUGIN_CONTINUE
}

public 
RestartTask() 
{
    if(!
get_pcvar_num(g_autoenabled))
        return 
PLUGIN_HANDLED
    
    set_task
(1.0,"TimeCounter",TIMER_TASK,_,_,"a",get_pcvar_num(g_autorestart))
    
set_task(get_pcvar_float(g_autorestart),"RestartRound",RESTART_TASK)
    
    return 
PLUGIN_CONTINUE
}

public 
TimeCounter(id
{
    
    
g_counter++
    
    new 
Float:iRestartTime get_pcvar_float(g_autorestart) - g_counter
    
new Float:fSec
    fSec 
iRestartTime 
    
    
static rgbFloat:xFloat:y
    HudMsgPos
(x,y)
    
HudMsgColor(g_autocount_colorrgb)
    
    
set_hudmessagerandom(256),random(256),random(256), xy00.01.00.00.0, -1)
    
ShowSyncHudMsg0g_SyncRestartTimer"%L",LANG_PLAYER"AUTO_RESTART"floatround(fSec))
        
    if(
get_pcvar_num(g_autocds) && get_pcvar_num(g_autorestart) - g_counter 11 && get_pcvar_num(g_autorestart) - g_counter !=0)
    {
        static 
szNum[32]
        
num_to_word(get_pcvar_num(g_autorestart) - g_counterszNum31)
    }
    if(
g_counter == get_pcvar_num(g_autorestart))
    {
        
g_bRoundStart true
        g_counter 
0
    
}
}

public 
RestartRound() 
{
    
server_cmd("sv_restartround 1")
}

public 
HudMsgColor(cvar, &r, &g, &b)
{
    static 
color[16], piece[5]
    
get_pcvar_string(cvarcolor15)
    
    
strbreakcolorpiece4color15)
    
str_to_num(piece)
    
    
strbreakcolorpiece4color15)
    
str_to_num(piece)
    
str_to_num(color)
}

public 
HudMsgPos(&Float:x, &Float:y)
{
    static 
coords[16], piece[10]
    
get_pcvar_string(g_auto_xypos coords15)
    
    
strbreak(coordspiece9coords15)
    
str_to_float(piece)
    
str_to_float(coords)

HowToRuski is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-17-2020 , 15:42   Re: Add milliseconds
Reply With Quote #2

use floats, easy as that lol..
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 10-18-2020 , 02:38   Re: Add milliseconds
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
use floats, easy as that lol..
Any examples on how to do that, as im new to amxx?
HowToRuski is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-18-2020 , 03:50   Re: Add milliseconds
Reply With Quote #4

To show fractional seconds in the HUD message, you would need to change the AUTO_RESTART value in the lang files (for all lanugages) to use "%.3f" instead of "%i" or "%d" and then change floatround(fSec) to fSec.

But note it will probably look really strange because it only updates the value once every second.
__________________
fysiks is offline
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 10-18-2020 , 14:25   Re: Add milliseconds
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
To show fractional seconds in the HUD message, you would need to change the AUTO_RESTART value in the lang files (for all lanugages) to use "%.3f" instead of "%i" or "%d" and then change floatround(fSec) to fSec.

But note it will probably look really strange because it only updates the value once every second.
And whats the possbile way to make it update every millisecond?
HowToRuski is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-19-2020 , 09:34   Re: Add milliseconds
Reply With Quote #6

Quote:
Originally Posted by HowToRuski View Post
Any examples on how to do that, as im new to amxx?
Didn't realize you wanted it to be shown in the hud.

Quote:
Originally Posted by HowToRuski View Post
And whats the possbile way to make it update every millisecond?
You could update it every few miliseconds using set_task, but that's probably not good for your server as this might cause lagg or even crash your server.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-19-2020 , 22:34   Re: Add milliseconds
Reply With Quote #7

The smallest time value for set_task() is 0.1 seconds (100 ms) and but I'm not sure what the minimum display time for a HUD message is. If it's not less than 0.1 seconds, then this won't be possible. Regardless, it's likely unnecessary to show millisecond resolution for something trivial like this.
__________________
fysiks is offline
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 10-22-2020 , 09:23   Re: Add milliseconds
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
The smallest time value for set_task() is 0.1 seconds (100 ms) and but I'm not sure what the minimum display time for a HUD message is. If it's not less than 0.1 seconds, then this won't be possible. Regardless, it's likely unnecessary to show millisecond resolution for something trivial like this.
Well it is possible, i've been on a server which shows milliseconds and hud is updated also in millisecond.
Thats because its kinda weird that random(256) hud color is updated every second...
HowToRuski is offline
r0ma
Senior Member
Join Date: Apr 2012
Location: Great Tomb of Nazarick
Old 10-22-2020 , 11:22   Re: Add milliseconds
Reply With Quote #9

try to adapt to your code:
PHP Code:
#include <amxmodx>

new Float:flTime;

public 
plugin_init() {
    
flTime 15.0// seconds
    
    
set_task(0.1"taskFunc"___"a"floatround(flTime)*10);
}

public 
taskFunc() {
    
flTime -= 0.1;
    
    
set_hudmessage(random(250), random(250), random(250), -1.0, -1.000.050.050.050.05);
    
show_hudmessage(0"Seconds: %0.1f"flTime);
    
    if(
flTime 0.1) {
        
// task end
    
}

__________________
Discord:FluffyDeveloper#4753
Github: https://github.com/francoromaniello
AMX-ES: https://amxmodx-es.com/r0ma'
r0ma is offline
Send a message via MSN to r0ma
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 10-22-2020 , 14:45   Re: Add milliseconds
Reply With Quote #10

Quote:
Originally Posted by r0ma View Post
try to adapt to your code:
PHP Code:
#include <amxmodx>

new Float:flTime;

public 
plugin_init() {
    
flTime 15.0// seconds
    
    
set_task(0.1"taskFunc"___"a"floatround(flTime)*10);
}

public 
taskFunc() {
    
flTime -= 0.1;
    
    
set_hudmessage(random(250), random(250), random(250), -1.0, -1.000.050.050.050.05);
    
show_hudmessage(0"Seconds: %0.1f"flTime);
    
    if(
flTime 0.1) {
        
// task end
    
}

Im so bad at this that it showed me errors on console but compiled without errors
HowToRuski is offline
Reply


Thread Tools
Display Modes

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 07:17.


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