AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Add milliseconds (https://forums.alliedmods.net/showthread.php?t=327926)

HowToRuski 10-17-2020 09:07

Add milliseconds
 
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)



Napoleon_be 10-17-2020 15:42

Re: Add milliseconds
 
use floats, easy as that lol..

HowToRuski 10-18-2020 02:38

Re: Add milliseconds
 
Quote:

Originally Posted by Napoleon_be (Post 2721665)
use floats, easy as that lol..

Any examples on how to do that, as im new to amxx?

fysiks 10-18-2020 03:50

Re: Add milliseconds
 
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.

HowToRuski 10-18-2020 14:25

Re: Add milliseconds
 
Quote:

Originally Posted by fysiks (Post 2721761)
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?

Napoleon_be 10-19-2020 09:34

Re: Add milliseconds
 
Quote:

Originally Posted by HowToRuski (Post 2721758)
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 (Post 2721827)
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.

fysiks 10-19-2020 22:34

Re: Add milliseconds
 
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.

HowToRuski 10-22-2020 09:23

Re: Add milliseconds
 
Quote:

Originally Posted by fysiks (Post 2721956)
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...

r0ma 10-22-2020 11:22

Re: Add milliseconds
 
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
    
}



HowToRuski 10-22-2020 14:45

Re: Add milliseconds
 
Quote:

Originally Posted by r0ma (Post 2722193)
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 :cry:


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

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