Raised This Month: $32 Target: $400
 8% 

Timers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-04-2016 , 12:25   Timers
Reply With Quote #1

How can you make a timer like SM's CreateTimer function in a Module?
TheDS1337 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-04-2016 , 12:35   Re: Timers
Reply With Quote #2

In a SourceMod Extension (the rough equivalent to AMXX's "Modules"), you can use the ITimerSys interface exposed by the timersys pointer.

Call CreateTimer, giving it an ITimedEvent implementation as the callback. You can see a couple of examples of it in CSSM, https://github.com/alliedmodders/css...sdm_events.cpp
psychonic is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-04-2016 , 12:46   Re: Timers
Reply With Quote #3

Assuming this is for a SourceMod Extension...

If you're using an extension based on the sample_ext extension:
  • Open smsdk_config.h and change this:
    Code:
    //#define SMEXT_ENABLE_TIMERSYS
    to this:
    Code:
    #define SMEXT_ENABLE_TIMERSYS
  • Create a new class that implements the ITimedEvent class. Specifically, you need to implement OnTimer and OnTimerEnd. As I recall, OnTimerEnd should call delete pTimer; as its last line.
  • In the code where you want to create the timer, call timersys->CreateTimer and pass a pointer to a copy of your timer class as the first argument (something like new ClassHere()).
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-04-2016 , 12:50   Re: Timers
Reply With Quote #4

Oh, great. I thought that we had to create one from scratch in Extension too.

What about a MMS module ?
TheDS1337 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-04-2016 , 13:16   Re: Timers
Reply With Quote #5

Quote:
Originally Posted by DeagLe.Studio View Post
What about a MMS module ?
There is no timer API for MetaMod:Source plugins.

You would have to make your own implementation.
psychonic is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-04-2016 , 13:59   Re: Timers
Reply With Quote #6

Well, so it'll be hard to create a timer system for MMS like in AMXx and MM it seems
TheDS1337 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-04-2016 , 14:13   Re: Timers
Reply With Quote #7

MM (Metamod) does not have a timer API either.
psychonic is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-04-2016 , 14:34   Re: Timers
Reply With Quote #8

Yes, that's what I said
TheDS1337 is offline
donrevan
AlliedModders Donor
Join Date: Jul 2010
Old 01-04-2016 , 17:30   Re: Timers
Reply With Quote #9

It's trivial to implement your own timer API in MM:S.
Just use GetGameTime(dunno SDK name) or even GetTickCount(see msdn) and check if time has passed every frame. Fire callback if it did.

Alternatively, you can probably create a new thread and call Sleep(not accurate) but you still have to sync with your main thread anyway.

Last edited by donrevan; 01-04-2016 at 17:31.
donrevan is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-05-2016 , 06:53   Re: Timers
Reply With Quote #10

Well, I'll be just using SM extension I guess. thanks for your answers!

There is a lot more to learn before I put myself in a project I am think on for a long time

Last edited by TheDS1337; 01-05-2016 at 06:53.
TheDS1337 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 20:18.


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