Raised This Month: $ Target: $400
 0% 

HookSingleEntityOutput and OnMapStart


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 09-24-2012 , 13:25   HookSingleEntityOutput and OnMapStart
Reply With Quote #1

Hello,

I try to hook a specific trigger_teleport which works very well when I use my plugin right after the map has been started.

This is my code:
PHP Code:
#include <sourcemod>
#include <sdktools_entoutput>
#include <sdktools_functions>

// public Plugin:myinfo = ...

public OnMapStart()
{
    
HookTriggerTeleport();
}

public 
OnMapEnd()
{
    
}

HookTriggerTeleport()
{
    for (new 
entity FindEntityByClassname(-1"trigger_teleport"); entity != -1entity FindEntityByClassname(entity"trigger_teleport"))
    {
        
decl String:targetName[32];
        
GetEntPropString(entityProp_Data"m_iName"targetNamesizeof(targetName));
        
        if (
StrEqual(targetName"mytrigger"))
        {
            
PrintToServer("Hooked!");
            
            
HookSingleEntityOutput(entity"OnStartTouch"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnEndTouch"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnEndTouchAll"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnTouching"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnNotTouching"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnTrigger"OnEntityOutPut);
            
            break;
        }
    }
}

public 
OnEntityOutPut(const String:output[], calleractivatorFloat:delay)
{
    
PrintToServer("%s, %d, %d, %0.2f"outputcalleractivatordelay);

For debugging purpose, I print "Hooked!" to the server console if it found the trigger_teleport I want to hook.

The crazy thing is, that it prints "Hooked!", but it does not fire when I touch the entity. Buf if I then reload the plugin using "sm plugins reload <name>", it prints "Hooked!" again and it works. Here's the console output:

Hooked // YIPPIEH!
Initializing Steam libraries for secure Internet server
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Logging into anonymous gameserver account.
Connection to Steam servers successful.
Public IP is ...
Assigned anonymous gameserver Steam ID [...].
VAC secure mode is activated.
Client "..." connected (...).
>> Here I touched the trigger_teleport, nothing is printed to console
sm plugins reload mypluginname
Hooked! // YIPPIEH AGAIN!
>> Here I touch the trigger_teleport again, and the following output comes (as expected):
OnStartTouch, 191, 1, 0.00
OnEndTouch, 191, 1, 0.00
OnEndTouchAll, 191, 1, 0.00


What can I do to avoid this?
Thanks in advance!

Last edited by Chrisber; 09-24-2012 at 13:26.
Chrisber is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 09-24-2012 , 13:27   Re: HookSingleEntityOutput and OnMapStart
Reply With Quote #2

Quote:
Originally Posted by Chrisber View Post
What can I do to avoid this?
use SDKHooks?

or use HookEntityOutput instead

Last edited by Leonardo; 09-24-2012 at 13:29.
Leonardo is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 09-24-2012 , 13:31   Re: HookSingleEntityOutput and OnMapStart
Reply With Quote #3

Quote:
Originally Posted by Leonardo View Post
This is not an option, really.
I also tried this option using OnEntityCreated, but it seems that if the entity is created, that I can't read ANY data out of it. It is empty. I can't resolve the name.

Quote:
Originally Posted by Leonardo View Post
or use HookEntityOutput instead
Too many trigger_teleports in the map with too excessive usage from too many players. I don't want to generate lags.

Edit: I found out that if I clear the Target Destination with DispatchKeyValue, this also only works when reloading the plugin. It seems that something overrides the hooks and the key values.

Last edited by Chrisber; 09-24-2012 at 13:32.
Chrisber is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 09-24-2012 , 13:56   Re: HookSingleEntityOutput and OnMapStart
Reply With Quote #4

Back in the day I've found that HookSingleEntityOutput is rather unreliable. You can store entity index and HookEntityOutput.
__________________
FaTony is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-24-2012 , 15:11   Re: HookSingleEntityOutput and OnMapStart
Reply With Quote #5

PHP Code:
#include <sourcemod>
#include <sdktools>

// public Plugin:myinfo = ...

public OnPluginStart()
{
    
HookEventEx("teamplay_restart_round"round); // If TF2
    
HookEventEx("round_start"round);
}

public 
round(Handle:event, const String:name[], bool:dontBroadcast)
{
    
HookTriggerTeleport();
}

HookTriggerTeleport()
{
    new 
entity MaxClients+1;

    while( (
entity FindEntityByClassname(entity"trigger_teleport")) != -)
    {
        
decl String:targetName[32];
        
GetEntPropString(entityProp_Data"m_iName"targetNamesizeof(targetName));
        
        if (
StrEqual(targetName"mytrigger"))
        {
            
PrintToServer("Hooked!");
            
            
HookSingleEntityOutput(entity"OnStartTouch"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnEndTouch"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnEndTouchAll"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnTouching"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnNotTouching"OnEntityOutPut);
            
HookSingleEntityOutput(entity"OnTrigger"OnEntityOutPut);
            
            break;
        }
    }
}

public 
OnEntityOutPut(const String:output[], calleractivatorFloat:delay)
{
    
PrintToServer("%s, %d, %d, %0.2f"outputcalleractivatordelay);

*edit
https://developer.valvesoftware.com/...es#Mapfilter.h
__________________
Do not Private Message @me

Last edited by Bacardi; 09-24-2012 at 15:42.
Bacardi is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 09-24-2012 , 16:11   Re: HookSingleEntityOutput and OnMapStart
Reply With Quote #6

Thanks! :-)
Chrisber 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 14:10.


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