Raised This Month: $13 Target: $400
 3% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
VoiDeD
SourceMod Plugin Unapprover
Join Date: Mar 2009
Location: Illinois, USA
Old 03-09-2015 , 14:36   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #11

Quote:
Originally Posted by lingzhidiyu View Post
whats the best code for fire once timer?
PHP Code:
CreateTimermyTimeMyCallback_TIMER_FLAG_NO_MAPCHANGE );

...

public 
Action:MyCallbackHandle:hTimer )
{
    
// do my fire-once logic

__________________
VoiDeD is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-10-2015 , 19:58   Re: [SNIPPET] Timers done Easy (requires SM 1.7)
Reply With Quote #12

Quote:
Originally Posted by Chdata View Post
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].
There is no better way unless BAILOPAN or whoever else is working on SourcePAWN adds a new way.
__________________
nergal is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 04-10-2020 , 19:10   Re: [SNIPPET] Timers Done Easy (requires SM 1.7+)
Reply With Quote #13

After so many years, here's the improved version.
Code:
stock void SetPawnTimer(Function func, float thinktime = 0.1, const any[] args, const int len)
{
	DataPack thinkpack = new DataPack();
	thinkpack.WriteFunction(func);
	thinkpack.WriteCell(len);
	for( int i; i<len; i++ )
		thinkpack.WriteCell(args[i]);
	CreateTimer(thinktime, DoPawnTimer, thinkpack, TIMER_DATA_HNDL_CLOSE);
}

public Action DoPawnTimer(Handle t, DataPack pack)
{
	pack.Reset();
	Function fn = pack.ReadFunction();
	Call_StartFunction(null, fn);
	
	int len = pack.ReadCell();
	for( int i; i<len; i++ ) {
		any param = pack.ReadCell();
		Call_PushCell(param);
	}
	Call_Finish();
	return Plugin_Continue;
}
__________________

Last edited by nergal; 04-10-2020 at 19:11.
nergal 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 05:59.


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