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

pass handle through timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
foon
Member
Join Date: Dec 2018
Old 12-28-2018 , 23:54   pass handle through timer
Reply With Quote #1

Is it possible to pass an event handle through a timer (like below)?

Code:
public void Event_Death(Event event, const char[] name, bool dontBroadcast)
{
CreateTimer(20.0, HCD, event);
}

public Action HCD(Handle timer, Handle event)
{
PrintToServer("%i", event.GetInt("userid"));
}
I know I can make a datatimer and pass all of the events through that, but it would be much easier to just pass the event its self through the timer.
foon is offline
XiLuo
Member
Join Date: Mar 2018
Old 12-29-2018 , 00:18   Re: pass handle through timer
Reply With Quote #2

Why you dont have a try?I think it may work
XiLuo is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-29-2018 , 00:20   Re: pass handle through timer
Reply With Quote #3

from 2012
Set event handle to timer (not possible however)

Quick answer, you can't, Handle get deleted after event callback.
Bacardi is offline
foon
Member
Join Date: Dec 2018
Old 12-29-2018 , 00:26   Re: pass handle through timer
Reply With Quote #4

Quote:
Originally Posted by Bacardi View Post
from 2012
Set event handle to timer (not possible however)

Quick answer, you can't, Handle get deleted after event callback.
Ah, good to know, thanks.
foon is offline
XiLuo
Member
Join Date: Mar 2018
Old 12-29-2018 , 00:28   Re: pass handle through timer
Reply With Quote #5

Quote:
Originally Posted by Bacardi View Post
from 2012
Set event handle to timer (not possible however)

Quick answer, you can't, Handle get deleted after event callback.
Oh,I see ,you mean is that the event callback will destroy handle on return,only to use datatimer to save all datas of event can delay,that's right? thanks for you answer
XiLuo is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-29-2018 , 00:36   Re: pass handle through timer
Reply With Quote #6

yep

*edit
I just tested just for fun... seems timer callback didn't reach end of own callback when I use that deleted event. :/ No errors tough. something viewrd

Last edited by Bacardi; 12-29-2018 at 00:42.
Bacardi is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 12-29-2018 , 20:39   Re: pass handle through timer
Reply With Quote #7

I suppose you could clone the event handle and remember to close it later CreateEvent a new one, fill in its fields you care about, and Cancel it later.

Last edited by Fyren; 12-29-2018 at 20:48.
Fyren is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-30-2018 , 14:52   Re: pass handle through timer
Reply With Quote #8

Yes, this work.

In this code, I close Event handle by timer TIMER_DATA_HNDL_CLOSE (or is Cancel must ?)
See posts below
PHP Code:
#include <sdktools>

public void OnPluginStart()
{
    
HookEvent("player_death"player_death);
}

public 
void player_death(Event event, const char[] namebool dontBroadcast)
{
    
Event newevent CreateEvent("player_death");
    
newevent.SetInt("userid"event.GetInt("userid"));
    
newevent.SetInt("attacker"event.GetInt("attacker"));

    
CreateTimer(3.0delaynewevent);
}

public 
Action delay(Handle timerEvent newevent)
{
    
PrintToServer("Userid %i"newevent.GetInt("userid"));
    
PrintToServer("attacker %i"newevent.GetInt("attacker"));
    
newevent.Cancel(); // Must Cancel created Event

...ok, one benefit with this, you can continue using Event functions, if you like



*edit
Need Cancel Event #13

Last edited by Bacardi; 12-31-2018 at 17:58.
Bacardi is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 12-31-2018 , 08:43   Re: pass handle through timer
Reply With Quote #9

Quote:
Originally Posted by Bacardi View Post
Yes, this work.

In this code, I close Event handle by timer TIMER_DATA_HNDL_CLOSE (or is Cancel must ?)
PHP Code:
#include <sdktools>

public void OnPluginStart()
{
    
HookEvent("player_death"player_death);
}

public 
void player_death(Event event, const char[] namebool dontBroadcast)
{
    
Event newevent CreateEvent("player_death");
    
newevent.SetInt("userid"event.GetInt("userid"));
    
newevent.SetInt("attacker"event.GetInt("attacker"));

    
CreateTimer(3.0delayneweventTIMER_DATA_HNDL_CLOSE);
}

public 
Action delay(Handle timerEvent newevent)
{
    
PrintToServer("Userid %i"newevent.GetInt("userid"));
    
PrintToServer("attacker %i"newevent.GetInt("attacker"));


...ok, one benefit with this, you can continue using Event functions, if you like
This feels like disaster. I think you should use datapacks instead.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 12-31-2018 , 09:54   Re: pass handle through timer
Reply With Quote #10

Quote:
Originally Posted by Bacardi View Post
Yes, this work.

In this code, I close Event handle by timer TIMER_DATA_HNDL_CLOSE (or is Cancel must ?)
PHP Code:
#include <sdktools>

public void OnPluginStart()
{
    
HookEvent("player_death"player_death);
}

public 
void player_death(Event event, const char[] namebool dontBroadcast)
{
    
Event newevent CreateEvent("player_death");
    
newevent.SetInt("userid"event.GetInt("userid"));
    
newevent.SetInt("attacker"event.GetInt("attacker"));

    
CreateTimer(3.0delayneweventTIMER_DATA_HNDL_CLOSE);
}

public 
Action delay(Handle timerEvent newevent)
{
    
PrintToServer("Userid %i"newevent.GetInt("userid"));
    
PrintToServer("attacker %i"newevent.GetInt("attacker"));


...ok, one benefit with this, you can continue using Event functions, if you like

This is actually a really good idea. You can pass data with custom names you give and use the native binary write system the source engine utilizes. Since sourcemod isn't freaking out about non existing event parameters and you aren't firing the event that would clog up the event system, I don't see any issue with using that. Assuming the TIMER_DATA_HNDL_CLOSE parameter is actually freeing the memory. I like it because you can define a string that represents an array index like in python.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards 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 19:01.


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