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

CreateTimer Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CloudRick
Junior Member
Join Date: Dec 2013
Old 01-03-2014 , 19:11   CreateTimer Help
Reply With Quote #1

How do I create a timer for a function that will be timed untill next mapchange?

I have tried some ways but it dont works.
CloudRick is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 01-03-2014 , 19:21   Re: CreateTimer Help
Reply With Quote #2

new Handle:g_hTimer;

g_hTimer = CreateTimer ( 1.0, MyTimer_Callback, any, TIMER_REPEAT );
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 01-03-2014 at 19:23.
GsiX is offline
CloudRick
Junior Member
Join Date: Dec 2013
Old 01-03-2014 , 20:23   Re: CreateTimer Help
Reply With Quote #3

It dont work, I get these errors when compiling:
warning 203: symbol is never used: "g_hTimer"
error 010: invalid function or declaration

Last edited by CloudRick; 01-03-2014 at 20:23.
CloudRick is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 01-03-2014 , 20:33   Re: CreateTimer Help
Reply With Quote #4

I punch the code from my limited space of Android phones. Anyway, the handle is global which is you put on top of your plugin and the timer will be inside your function.


EDIT:
PHP Code:
new Handle:g_hTimer INVALID_HANDLE;

public 
OnPluginStart()
{
    
g_hTimer CreateTimer1.0YourTimerCallBack_TIMER_REPEAT );
}

public 
Action:YourTimerCallBackHandle:timerany:data )
{
    
PrintToChatAll"Test timer is running" );

I dont know what you try to do so please take note that if you kill the timer, clear the handle as well.
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 01-03-2014 at 20:43. Reason: edited from pc
GsiX is offline
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 01-04-2014 , 01:31   Re: CreateTimer Help
Reply With Quote #5

I think Cloud wants to count time from action X (e.g. called cmd) until mapchange.

If I understand you right, then best way would be to use GetGameTime(). To use that, create two floats, and get value at the moment when you're trying to start counting the time, and the other, just before changelevel. Substruct them, and you're at home, mate. It will not lag srv at as Timer would if you would call to reapeat it, and add +1 to int/float every sec.

Last edited by LambdaLambda; 01-04-2014 at 01:37.
LambdaLambda is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 01-04-2014 , 04:11   Re: CreateTimer Help
Reply With Quote #6

I'm not sure what you are trying to do but what LambdaLambda tell you is if you goal is to get the number of time that a map have been running you can do it like this:

PHP Code:
new Float:g_fTime;

public 
OnMapStart()
{
    
g_fTime GetGameTime();
}

public 
OnMapEnd()
{
    static 
Float:total_time;
    if (
total_time)
    {
        
PrintToServer("Last map total time: %d seconds"total_time);
    }
    
total_time GetGameTime() - g_fTime// in seconds (apparently GetGameTime Restart to 0 on map start but it doesnt cost anything to make sure the time is correct
    
PrintToServer("Total time map have been running: %d seconds"total_time); 

In revenge if you want to call a timer and do some actions into it until the map end (GsiX solution):

PHP Code:

public OnMapStart()
{
    
CreateTimer1.0YourTimerCallBack_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE );
}

public 
Action:YourTimerCallBackHandle:timerany:data )
{
    
PrintToChatAll"Test timer is running" );


Last edited by Mathias.; 01-04-2014 at 04:12.
Mathias. is offline
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 22:01.


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