Raised This Month: $ Target: $400
 0% 

Milisecond Timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-15-2012 , 20:22   Milisecond Timer
Reply With Quote #1

hey,
is it possible to make a milisecond timer with steps per 50 miliseconds or lower?

I just made a 100milisecond step timer and i'm also wondering if this is a correct way to make a timer:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <dhudmessage>
#define PLUGIN "ms Timer"
#define VERSION "1.0"
#define AUTHOR "striker07"
new g_iMiliSeconds;
new 
g_iSeconds;
new 
g_iMinutes;
new 
g_iSync;
public 
plugin_init() {
 
register_plugin(PLUGINVERSIONAUTHOR)
 
 
g_iSync CreateHudSyncObj();
 
 
// Add your code here...
}
public 
Start_Timer()
{
 
set_task(0.1"Add_100ms" 1337__"b");
 
set_task(0.1"Update_Timer"___"b");
}
public 
Stop_Timer()
{
 
remove_task(1337);
}
public 
Add_100ms()
{
 
g_iMiliSeconds g_iMiliSeconds+100;
 
 if(
g_iMiliSeconds == 1000)
 {
  
g_iMiliSeconds 0;
  
g_iSeconds++;
 
  if(
g_iSeconds == 60)
  {
   
g_iSeconds 0;
   
g_iMinutes++;
  }
 }
}
public 
Update_timer()
{
 new 
Msg[512];
 
 
set_dhudmessage(25520400.01, -0.660_0.10.10.1);
 
 
format(Msg,511," Chronometer: ^n %i:%i.%.3i "g_iMinutesg_iSecondsg_iMiliSeconds );
 
ShowSyncHudMsg(0g_iSyncMsg);

__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 08-15-2012 at 20:23.
striker07 is offline
Merciless
BANNED
Join Date: Aug 2009
Location: Belgium
Old 08-15-2012 , 20:31   Re: Milisecond Timer
Reply With Quote #2

Use floats?

-= 0.01
Merciless is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-15-2012 , 20:39   Re: Milisecond Timer
Reply With Quote #3

what do you mean?

set_task minimum time is 0.1 of a second, changing it to 0.01 will probably crash the server.
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-15-2012 , 20:45   Re: Milisecond Timer
Reply With Quote #4

Quote:
Originally Posted by striker07 View Post
changing it to 0.01 will probably crash the server.
No, it won't.

If you want something faster than 100ms I think you would need to use a entity based timer. There are many threads about this. There is at least on in the Tutorials section.
__________________
fysiks is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 08-15-2012 , 21:04   Re: Milisecond Timer
Reply With Quote #5

http://forums.alliedmods.net/showthread.php?t=146556
Quote:
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" );     } }
OvidiuS is offline
Send a message via Skype™ to OvidiuS
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-15-2012 , 21:30   Re: Milisecond Timer
Reply With Quote #6

hmm i havent really worked with entities, so it's hard for me to figure what happens in this plugin.
but isnt this gonna bug when using get_gametime in stead of using a constant value g_iCounter or iCounTime to begin with? (in case of making the timer count up)

other then its a countdown timer it looks like somethings not right or i'm missing something, can you pls explain that script a lil so that i know what does what?
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 08-16-2012 at 07:44.
striker07 is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 08-16-2012 , 08:47   Re: Milisecond Timer
Reply With Quote #7

g_iCountdownEntity is our entity id.

Code:
#include <amxmodx> #include <engine> new const Version[] = "0.1"; const iCountTime = 1500; // count time new g_iCountdownEntity; // counter entity id new g_iCounter; // new counter variable public plugin_init() {     register_plugin( "Fast Countdown" , Version , "bugsy" ); // register plugin         g_iCountdownEntity = create_entity( "info_target" ); // creates new entity and stores its id in g_iCountdownEntity variable     entity_set_string( g_iCountdownEntity , EV_SZ_classname , "countdown_entity" ); // sets the classname to entity (countdown_entity)     register_think( "countdown_entity" , "fw_CountdownEntThink" ); // registers entity think (something like set task but for entity)         register_clcmd( "say /countdown" , "ShowCountdown" ); // registers clcmd command } public ShowCountdown() {     g_iCounter = iCountTime; // sets the counter time     entity_set_float( g_iCountdownEntity , EV_FL_nextthink , get_gametime() + 0.01 ); // sets the next think of entity (gametime + 0.01 ) so next think is in 0.01 second. } public fw_CountdownEntThink( iEntity ) {     if ( iEntity == g_iCountdownEntity )  // checks if entity is countdown entity     {         set_hudmessage( 255 , 255 , 255 , -1.0 , -1.0 , 0 , 0.1 , 0.1 ); // creates the hud message         show_hudmessage( 0 , "[ Countdown ends in: %d ]" , --g_iCounter ); // show the counter in hudmessage                 if ( g_iCounter ) // checks if counter is > 0             entity_set_float( g_iCountdownEntity , EV_FL_nextthink , get_gametime() + 0.01 ); // sets the next think in 0.01 second         else             server_cmd( "sv_restartround 1" ); // if counter is 0, restart the round     } }

Sorry for bad english
OvidiuS is offline
Send a message via Skype™ to OvidiuS
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-16-2012 , 09:58   Re: Milisecond Timer
Reply With Quote #8

thanks, that helped alot .
i converted it into a chronometer, its running perfectly timed with my stopwatch
PHP Code:
#include <amxmodx>
#include <engine>
#include <dhudmessage>
new const Version[] = "0.1";
const 
iCountTime 0// count start time
new g_iCounterEntity// counter entity id
new g_iCounter// new counter variable
new g_iMiliseconds;
new 
g_iSeconds;
new 
g_iMinutes;
new 
g_bStopTimer false;
new 
g_bHideTimer false;
 
public 
plugin_init() 
{
    
register_plugin"Fast Counter" Version "striker07" ); // register plugin
 
    
g_iCounterEntity create_entity"info_target" ); // creates new entity and stores its id in g_iCounterEntity variable
    
entity_set_stringg_iCounterEntity EV_SZ_classname "counter_entity" ); // sets the classname to entity (countdown_entity)
    
register_think"counter_entity" "fw_CounterEntThink" ); // registers entity think (something like set task but for entity)
 
    
register_clcmd"say /timer" "ShowCounter" ); // registers clcmd command
    
register_clcmd"say /stoptimer" "StopCounter" );
}
public 
ShowCounter()
{
    
g_iCounter iCountTime// sets the counter time
    
entity_set_floatg_iCounterEntity EV_FL_nextthink get_gametime() + 0.01 ); // sets the next think of entity (gametime + 0.01 ) so next think is in 0.01 second.
}
public 
StopCounter ()
{
 
g_bStopTimer true;
}
public 
fw_CounterEntThinkiEntity )
{
    if ( 
iEntity == g_iCounterEntity )  // checks if entity is countdown entity
    
{
     if( !
g_bStopTimer)
 {
  
g_iCounter++;
 
  if(
g_iCounter == 100)
  {
   
g_iCounter 0;
   
g_iSeconds++;
 
   if(
g_iSeconds == 60)
   {
    
g_iSeconds 0;
    
g_iMinutes++;
   }
  }
 }
 
 if( !
g_bHideTimer )
 {
  
set_dhudmessage(25520400.43, -0.660_0.10.10.1); // creates the hud message
  
show_dhudmessage"[ Timer: ] ^n %i:%i:%i " g_iMinutesg_iSecondsg_iCounter ); // show the counter in hudmessage
 
}
 
 
entity_set_floatg_iCounterEntity EV_FL_nextthink get_gametime() + 0.01 ); // sets the next think in 0.01 second
 
    
}




ps: you're english is pretty good
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 08-16-2012 at 15:23.
striker07 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-16-2012 , 19:15   Re: Milisecond Timer
Reply With Quote #9

Quote:
Originally Posted by striker07 View Post
hmm i havent really worked with entities, so it's hard for me to figure what happens in this plugin.
Did you even bother to read my post?
__________________
fysiks is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-17-2012 , 07:23   Re: Milisecond Timer
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
Did you even bother to read my post?
Yes,
and i've searched for entitie/entity/time/timer/entity based everything i could think of searched in tutorials: nothing searched in amxx section: no tutorials found.

Why is my timer not good? its working perfectly though
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
Old 08-17-2012, 08:43
SpaceRip
This message has been deleted by SpaceRip. Reason: WTF IS ENTITY TIMER, never heard about this...
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 05:50.


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