Raised This Month: $ Target: $400
 0% 

millisecond display problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sb123
Senior Member
Join Date: Jan 2007
Old 12-21-2023 , 22:14   millisecond display problem
Reply With Quote #1

How to add a colon between seconds and milliseconds
I am using the Fast Countdown plugin created by bugsy. But there's a question, I need to add a colon between seconds and milliseconds. How should I add a colon?

Now the countdown is displayed like this
If the countdown starts from 15 seconds
[Countdown ends in: 1500]
I want to change it to display like this
Add: colon between seconds and milliseconds
[Countdown ends in: 15:00]

I also want to add milliseconds to the C4 countdown. How do I get milliseconds from g_C4Timer = get_cvar_num("mp_c4timer")

thank

Code:
#include <amxmodx>
#include <engine>

new const Version[] = "0.1"

const iCountTime = 1500

new g_iCountdownEntity
new g_iCounter

public plugin_init() 
{
	register_plugin("Fast Countdown" , Version , "bugsy")
	
	g_iCountdownEntity = create_entity("info_target")
	entity_set_string(g_iCountdownEntity , EV_SZ_classname , "countdown_entity")
	register_think("countdown_entity" , "fw_CountdownEntThink")
	
	register_clcmd("say /countdown" , "ShowCountdown")
}

public ShowCountdown()
{
	g_iCounter = iCountTime
	entity_set_float(g_iCountdownEntity , EV_FL_nextthink , get_gametime() + 0.01)
}

public fw_CountdownEntThink(iEntity)
{
	if (iEntity == g_iCountdownEntity) 
	{
		set_hudmessage(255 , 255 , 255 , -1.0 , -1.0 , 0 , 0.1 , 0.1)
		show_hudmessage(0 , "[ Countdown ends in: %d ]" , --g_iCounter)
		
		if (g_iCounter)
			entity_set_float(g_iCountdownEntity , EV_FL_nextthink , get_gametime() + 0.01)
		else
			server_cmd("sv_restartround 1")
	}
}
Attached Files
File Type: sma Get Plugin or Get Source (Fast_Countdown.sma - 61 views - 989 Bytes)
__________________
sb123 is offline
Send a message via ICQ to sb123 Send a message via MSN to sb123 Send a message via Yahoo to sb123
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 12-21-2023 , 23:12   Re: millisecond display problem
Reply With Quote #2

countdown
PHP Code:
#include <amxmodx>
#include <engine>

new const Version[] = "0.1"

const Float:iCountTime 15.0

new g_iCountdownEntity
new Float:g_iCounter

public plugin_init() 
{
    
register_plugin("Fast Countdown" Version "bugsy")
    
    
g_iCountdownEntity create_entity("info_target")
    
entity_set_string(g_iCountdownEntity EV_SZ_classname "countdown_entity")
    
register_think("countdown_entity" "fw_CountdownEntThink")

    
register_clcmd("say /countdown" "ShowCountdown")
}

public 
ShowCountdown()
{
    
g_iCounter iCountTime
    entity_set_float
(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
}

public 
fw_CountdownEntThink(iEntity)
{
    if (
iEntity == g_iCountdownEntity
    {
        
g_iCounter -= 0.01
        set_hudmessage
(255 255 255 , -1.0 0.8 0.1 0.1)
        
show_hudmessage("[ Countdown ends in: %.02f ]" g_iCounter)
        
        if (
g_iCounter 0.01)
            
entity_set_float(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
        else
            
server_cmd("sv_restartround 1")
    }

c4
PHP Code:
#include <amxmodx>
#include <engine>

new const Version[] = "0.1"

new g_iCountdownEntity
new Float:g_iCounter

public plugin_init() 
{
    
register_plugin("Fast Countdown" Version "bugsy")
    
    
g_iCountdownEntity create_entity("info_target")
    
entity_set_string(g_iCountdownEntity EV_SZ_classname "countdown_entity")
    
register_think("countdown_entity" "fw_CountdownEntThink")

    
register_logevent("Planted_The_Bomb"3"2=Planted_The_Bomb")
}

public 
Planted_The_Bomb()
{
    
g_iCounter get_cvar_float("mp_c4timer")
    
entity_set_float(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
}

public 
fw_CountdownEntThink(iEntity)
{
    if (
iEntity == g_iCountdownEntity
    {
        
g_iCounter -= 0.01
        set_hudmessage
(255 255 255 , -1.0 0.8 0.1 0.1)
        
show_hudmessage("[ Bomb explodes in: %.02f ]" g_iCounter)
        
        if (
g_iCounter 0.01)
            
entity_set_float(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
    }

__________________
bigdaddy424 is offline
sb123
Senior Member
Join Date: Jan 2007
Old 12-22-2023 , 05:25   Re: millisecond display problem
Reply With Quote #3

Quote:
Originally Posted by bigdaddy424 View Post
countdown
PHP Code:
#include <amxmodx>
#include <engine>

new const Version[] = "0.1"

const Float:iCountTime 15.0

new g_iCountdownEntity
new Float:g_iCounter

public plugin_init() 
{
    
register_plugin("Fast Countdown" Version "bugsy")
    
    
g_iCountdownEntity create_entity("info_target")
    
entity_set_string(g_iCountdownEntity EV_SZ_classname "countdown_entity")
    
register_think("countdown_entity" "fw_CountdownEntThink")

    
register_clcmd("say /countdown" "ShowCountdown")
}

public 
ShowCountdown()
{
    
g_iCounter iCountTime
    entity_set_float
(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
}

public 
fw_CountdownEntThink(iEntity)
{
    if (
iEntity == g_iCountdownEntity
    {
        
g_iCounter -= 0.01
        set_hudmessage
(255 255 255 , -1.0 0.8 0.1 0.1)
        
show_hudmessage("[ Countdown ends in: %.02f ]" g_iCounter)
        
        if (
g_iCounter 0.01)
            
entity_set_float(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
        else
            
server_cmd("sv_restartround 1")
    }

c4
PHP Code:
#include <amxmodx>
#include <engine>

new const Version[] = "0.1"

new g_iCountdownEntity
new Float:g_iCounter

public plugin_init() 
{
    
register_plugin("Fast Countdown" Version "bugsy")
    
    
g_iCountdownEntity create_entity("info_target")
    
entity_set_string(g_iCountdownEntity EV_SZ_classname "countdown_entity")
    
register_think("countdown_entity" "fw_CountdownEntThink")

    
register_logevent("Planted_The_Bomb"3"2=Planted_The_Bomb")
}

public 
Planted_The_Bomb()
{
    
g_iCounter get_cvar_float("mp_c4timer")
    
entity_set_float(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
}

public 
fw_CountdownEntThink(iEntity)
{
    if (
iEntity == g_iCountdownEntity
    {
        
g_iCounter -= 0.01
        set_hudmessage
(255 255 255 , -1.0 0.8 0.1 0.1)
        
show_hudmessage("[ Bomb explodes in: %.02f ]" g_iCounter)
        
        if (
g_iCounter 0.01)
            
entity_set_float(g_iCountdownEntity EV_FL_nextthink get_gametime() + 0.01)
    }

bigdaddy424
Thank you very much for your help. After testing, everything is normal in the code, except that the symbol in the middle is a dot. It would be nice if it could be changed to a colon.
If can't change it to a colon, then I'll just use the code you published earlier, because the code is already perfect
__________________
sb123 is offline
Send a message via ICQ to sb123 Send a message via MSN to sb123 Send a message via Yahoo to sb123
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-22-2023 , 14:53   Re: millisecond display problem
Reply With Quote #4

PHP Code:
new szBuffer35 ];
formatexszBuffer charsmaxszBuffer ) , "[ Countdown ends in: %.02f ]" g_iCounter);
replaceszBuffer charsmaxszBuffer ) , "." ":" );
show_hudmessage(szBuffer ); 
__________________
Bugsy is offline
sb123
Senior Member
Join Date: Jan 2007
Old 12-23-2023 , 01:11   Re: millisecond display problem
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
PHP Code:
new szBuffer35 ];
formatexszBuffer charsmaxszBuffer ) , "[ Countdown ends in: %.02f ]" g_iCounter);
replaceszBuffer charsmaxszBuffer ) , "." ":" );
show_hudmessage(szBuffer ); 
Bugsy Hello, thank you for your reply
Now I have a problem, please help me to see what the code is wrong
I now add the code to the miscstats code
It only shows the milliseconds on the left
C4: 35:0
Cannot display the milliseconds on the right
C4: 35:00
Is there an incorrect code somewhere?

Code:
new Float:g_iC4Timer

public bombcountdown()
{
	new bt_ppl[32], plnum = 0
	get_players(bt_ppl,plnum)
	g_iC4Timer -= 0.1
	for (new a=0; a<plnum; a++) {
		if ( !g_justKilled[bt_ppl[a]] ) {
			if(g_iC4Timer < 7) set_hudmessage(150, 0, 0, -1.0, 0.75, 0, 1.0, 1.0, 0.01, 0.01, -1)
			if(g_iC4Timer > 6) set_hudmessage(150, 150, 0, -1.0, 0.75, 0, 1.0, 1.0, 0.01, 0.01, -1)
			if(g_iC4Timer > 11) set_hudmessage(0, 150, 0, -1.0, 0.75, 0, 1.0, 1.0, 0.01, 0.01, -1)
			new szBuffer[35]
			formatex(szBuffer, 34, "C4: %0.1f", g_iC4Timer)
			replace(szBuffer, 34, ".", ":")
			ShowSyncHudMsg(bt_ppl[a], g_bombcounthud_sync, szBuffer)
		}
	}
	if(g_iC4Timer < 0.1) {
		remove_task(951010)
	}
}

public bomb_planted(planter)
{
	g_Defusing = 0
	
	if (BombPlanted)
		announceEvent(planter, "")
	
	if (BombPlantedSound)
		play_sound("djeyl/c4start")
	
	if(g_roundended) return
	
	g_C4Timer = get_cvar_num("mp_c4timer")
	bombTimer()
	set_task(1.0, "bombTimer", 8038, "", 0, "b")
	
	g_iC4Timer = get_cvar_float("mp_c4timer")
	bombcountdown()
	set_task(0.1, "bombcountdown", 951010, "", 0, "b")
}
__________________
sb123 is offline
Send a message via ICQ to sb123 Send a message via MSN to sb123 Send a message via Yahoo to sb123
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 04:52.


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