AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Milisecond Timer (https://forums.alliedmods.net/showthread.php?t=193021)

striker07 08-15-2012 20:22

Milisecond Timer
 
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);



Merciless 08-15-2012 20:31

Re: Milisecond Timer
 
Use floats?

-= 0.01

striker07 08-15-2012 20:39

Re: Milisecond Timer
 
what do you mean?

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

fysiks 08-15-2012 20:45

Re: Milisecond Timer
 
Quote:

Originally Posted by striker07 (Post 1772511)
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.

OvidiuS 08-15-2012 21:04

Re: Milisecond Timer
 
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" );     } }


striker07 08-15-2012 21:30

Re: Milisecond Timer
 
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?

OvidiuS 08-16-2012 08:47

Re: Milisecond Timer
 
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 :|

striker07 08-16-2012 09:58

Re: Milisecond Timer
 
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 :)

fysiks 08-16-2012 19:15

Re: Milisecond Timer
 
Quote:

Originally Posted by striker07 (Post 1772549)
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?

striker07 08-17-2012 07:23

Re: Milisecond Timer
 
Quote:

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


All times are GMT -4. The time now is 05:50.

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