Added amb1528 - Entity Output Hooking.
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401977
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
#include <sdktools_tempents_stocks>
|
||||
#include <sdktools_voice>
|
||||
#include <sdktools_entinput>
|
||||
#include <sdktools_entoutput>
|
||||
|
||||
enum SDKCallType
|
||||
{
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This file is part of the SourceMod/SourcePawn SDK.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id: sdktools_entoutput.inc 1504 2007-09-28 19:56:19Z faluco $
|
||||
*/
|
||||
|
||||
#if defined _sdktools_entoutput_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _sdktools_entoutput_included
|
||||
|
||||
/**
|
||||
* Called when an entity output is fired.
|
||||
*
|
||||
* @param output Name of the output that fired.
|
||||
* @param caller Entity index of the caller.
|
||||
* @param activator Entity index of the activator.
|
||||
* @param delay Delay in seconds? before the event gets fired.
|
||||
*/
|
||||
functag EntityOutput public(const String:output[], caller, activator, Float:delay);
|
||||
|
||||
/**
|
||||
* Add an entity output hook on a entity classname
|
||||
*
|
||||
* @param classname The classname to hook.
|
||||
* @param output The output name to hook.
|
||||
* @param callback An EntityOutput function pointer.
|
||||
* @noreturn
|
||||
* @error Entity Outputs disabled.
|
||||
*/
|
||||
native HookEntityOutput(const String:classname[], const String:output[], EntityOutput:callback);
|
||||
|
||||
/**
|
||||
* Remove an entity output hook.
|
||||
* @param classname The classname to hook.
|
||||
* @param output The output name to hook.
|
||||
* @param callback An EntityOutput function pointer.
|
||||
* @return True on success, false if no valid hook was found.
|
||||
* @error Entity Outputs disabled.
|
||||
*/
|
||||
native bool:UnHookEntityOutput(const String:classname[], const String:output[], EntityOutput:callback);
|
||||
|
||||
/**
|
||||
* Add an entity output hook on a single entity instance
|
||||
*
|
||||
* @param entity The entity on which to add a hook.
|
||||
* @param output The output name to hook.
|
||||
* @param callback An EntityOutput function pointer.
|
||||
* @param once Only fire this hook once and then remove itself.
|
||||
* @noreturn
|
||||
* @error Entity Outputs disabled or Invalid Entity index.
|
||||
*/
|
||||
native HookSingleEntityOutput(entity, const String:output[], EntityOutput:callback , bool:once=false);
|
||||
|
||||
/**
|
||||
* Remove a single entity output hook.
|
||||
*
|
||||
* @param entity The entity on which to remove the hook.
|
||||
* @param output The output name to hook.
|
||||
* @param callback An EntityOutput function pointer.
|
||||
* @return True on success, false if no valid hook was found.
|
||||
* @error Entity Outputs disabled or Invalid Entity index.
|
||||
*/
|
||||
native bool:UnHookSingleEntityOutput(entity, const String:output[], EntityOutput:callback);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Entity Output Hook Testing",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Test suite for Entity Output Hooks",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
HookEntityOutput("point_spotlight", "OnLightOn", OutputHook);
|
||||
|
||||
HookEntityOutput("func_door", "OnOpen", OutputHook);
|
||||
HookEntityOutput("func_door_rotating", "OnOpen", OutputHook);
|
||||
HookEntityOutput("func_door", "OnClose", OutputHook);
|
||||
HookEntityOutput("func_door_rotating", "OnClose", OutputHook);
|
||||
}
|
||||
|
||||
public OutputHook(const String:name[], caller, activator, Float:delay)
|
||||
{
|
||||
LogMessage("[ENTOUTPUT] %s", name);
|
||||
}
|
||||
|
||||
public OnMapStart()
|
||||
{
|
||||
new ent = FindEntityByClassname(-1, "point_spotlight");
|
||||
|
||||
if (ent == -1)
|
||||
{
|
||||
LogError("Could not find a point_spotlight");
|
||||
ent = CreateEntityByName("point_spotlight");
|
||||
DispatchSpawn(ent);
|
||||
}
|
||||
|
||||
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, true);
|
||||
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, true);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, false);
|
||||
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, false);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
//Comment these out (and reload the plugin heaps) to test for leaks on plugin unload
|
||||
UnHookSingleEntityOutput(ent, "OnLightOn", OutputHook);
|
||||
UnHookSingleEntityOutput(ent, "OnLightOff", OutputHook);
|
||||
}
|
||||
Reference in New Issue
Block a user