AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] Timers done Easy (requires SM 1.7+) (https://forums.alliedmods.net/showthread.php?t=259489)

nergal 03-07-2015 18:36

[SNIPPET] Timers done Easy (requires SM 1.7+)
 
1 Attachment(s)
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 :3

LambdaLambda 03-07-2015 19:50

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
That's interesting! I probably won't use it, as I don't see any benefit for that right now, but still, great idea!

nergal 03-07-2015 20:32

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
Quote:

Originally Posted by LambdaLambda (Post 2271045)
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...

BAILOPAN 03-08-2015 03:31

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
I would recommend not using CallFunction which is slow and not using the random and valid number -999 as a marker value.

nergal 03-08-2015 12:11

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
Quote:

Originally Posted by BAILOPAN (Post 2271117)
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?

Chdata 03-08-2015 15:51

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
Quote:

Originally Posted by BAILOPAN (Post 2271117)
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.

asherkin 03-09-2015 04:58

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
Quote:

Originally Posted by Chdata (Post 2271349)
What would you recommend instead?

CreateTimer, I hear it is already included in SourceMod.

nergal 03-09-2015 08:05

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
Quote:

Originally Posted by asherkin (Post 2271521)
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.

Chdata 03-09-2015 11:23

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
Quote:

Originally Posted by asherkin (Post 2271521)
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].

lingzhidiyu 03-09-2015 14:27

Re: [SNIPPET] Timers done Easy (requires SM 1.7)
 
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;
        }




All times are GMT -4. The time now is 12:58.

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