Raised This Month: $23 Target: $400
 5% 

[SNIPPET] Timers done Easy (requires SM 1.7+)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 03-07-2015 , 18:36   [SNIPPET] Timers done Easy (requires SM 1.7+)
Reply With Quote #1

This snippets makes it easy to make timers without having to make the timer function and then the callback timer callback.

This ugly and hacky looking wrapper does it in one move. It should also be noted that it's preferable to use this wrapper function for NON-Repeating timers.

Example code!
PHP Code:
SetPawnTimer(AddTwoNumbers1.022); 
the Parameters are ignorable so there's less hassle.
Of course, due to the way it's structured, you can't use arrays or strings unless you modify it.

Source Code Below

Spoiler


N-JOY
Attached Files
File Type: inc pawntimer.inc (1.4 KB, 127 views)
__________________

Last edited by nergal; 05-12-2015 at 12:53.
nergal is offline
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 03-07-2015 , 19:50   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #2

That's interesting! I probably won't use it, as I don't see any benefit for that right now, but still, great idea!
LambdaLambda is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-07-2015 , 20:32   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #3

Quote:
Originally Posted by LambdaLambda View Post
That's interesting! I probably won't use it, as I don't see any benefit for that right now, but still, great idea!
crap, u reminded me that I needed to add flags...
__________________
nergal is offline
BAILOPAN
Join Date: Jan 2004
Old 03-08-2015 , 03:31   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #4

I would recommend not using CallFunction which is slow and not using the random and valid number -999 as a marker value.
__________________
egg
BAILOPAN is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-08-2015 , 12:11   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #5

Quote:
Originally Posted by BAILOPAN View Post
I would recommend not using CallFunction which is slow and not using the random and valid number -999 as a marker value.
idk what default value to put it as...

I wanted the value to be placed as "null" but compiler bitched me at saying that I cannot make those null...

"error 148: cannot assign null to a non-nullable type"

Is there any other way to call a function inside a plugin other than Call_StartFunction?
__________________
nergal is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-08-2015 , 15:51   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #6

Quote:
Originally Posted by BAILOPAN View Post
I would recommend not using CallFunction which is slow and not using the random and valid number -999 as a marker value.
What would you recommend instead?

Would you still not recommend it for fire-once timers? Is it really so slow that it should be avoided for that case too?

Would 2147... whatever max is, or min is, be okay in your opinion? Or 0, since afaik null is defined as 0 anyway. Just like INVALID_HANDLE was.

Personally I'm not interested in this until switch (type) case bool case float is released, and getnumargs.
__________________

Last edited by Chdata; 03-08-2015 at 16:03.
Chdata is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-09-2015 , 04:58   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #7

Quote:
Originally Posted by Chdata View Post
What would you recommend instead?
CreateTimer, I hear it is already included in SourceMod.
__________________
asherkin is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-09-2015 , 08:05   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #8

Quote:
Originally Posted by asherkin View Post
CreateTimer, I hear it is already included in SourceMod.
I think you guys are missing the point of this wrapper ( ͡ ͜ʖ ͡)

Making timers requires making timer functions...

This wrapper code makes ONE timer functions to be used on (almost) any function that needs to a timed callback.

This code reduces the need to copypaste timer prototypes as there's already a timer made to callback the function you wish to use.
__________________
nergal is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-09-2015 , 11:23   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #9

Quote:
Originally Posted by asherkin View Post
CreateTimer, I hear it is already included in SourceMod.
I was asking if there's a better way to do what nergal's trying to accomplish [a CreateTimer that directly maps to some existing function, letting you use the original function as the callback instead of a timer callback].
__________________

Last edited by Chdata; 03-09-2015 at 11:25.
Chdata is offline
lingzhidiyu
Senior Member
Join Date: Mar 2014
Old 03-09-2015 , 14:27   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #10

whats the best code for fire once timer?

PHP Code:
new g_hTime INVALID_HANDLE;

g_hTime CreateTimer(...);
public 
Action:thistimer(Handle:timer)
{
        
dosomething();
    
g_hTime INVALID_HANDLE; or? timer INVALID_HANDLE;

PHP Code:
new g_hTime INVALID_HANDLE;

g_hTime CreateTimer(...);
public 
Action:thistimer(Handle:timer)
{
        if (
g_hTime != INVALID_HANDLE)
        {
            
dosomething();
            
g_hTime INVALID_HANDLE; or? timer INVALID_HANDLE;
        }


Last edited by lingzhidiyu; 03-09-2015 at 14:29.
lingzhidiyu is offline
Reply


Thread Tools
Display Modes

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 09:00.


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