楼主,能否在vscript中创建事件监听器实体?我试了以下代码,info_game_event_proxy 能正常 GenerateGameEvent,但是监听器实体就
是监听不到事件,求帮助
代码:
// 创建一个事件监听器实体,监听player_use事件
if ( !("event_listener_player_use" in getroottable()) || ! (::event_listener_player_use.IsValid()) )
{
::event_listener_player_use <- Entities.CreateByClassname("logic_eventlistener");
::event_listener_player_use.__KeyValueFromString("EventName","player_use");
::event_listener_player_use.__KeyValueFromInt("FetchEventData", 1);
EntFireByHandle(::event_listener_player_use, "Enable", "", 0.0, null, null);
}
// 设置监听器监听到事件发生时触发的函数
::event_listener_player_use.ValidateScriptScope();
::event_listener_player_use.GetScriptScope().OnGameEvent_player_use <- function(event_data)
{
printl( event_data["userid"] + "has used something!" );
}
::event_listener_player_use.ConnectOutput("OnEventFired", "OnGameEvent_player_use");
// 设置 info_game_event_proxy 实体以帮助触发事件player_use
if ( !("gameevents_proxy" in getroottable()) || ! (::gameevents_proxy.IsValid()) )
{
::gameevents_proxy <- Entities.CreateByClassname("info_game_event_proxy");
::gameevents_proxy.__KeyValueFromString("targetname","gameevents_proxy");
::gameevents_proxy.__KeyValueFromString("event_name","player_use");
::gameevents_proxy.__KeyValueFromInt("range",0);
}
::gameevents_proxy.ValidateScriptScope();
// 当 gameevents_proxy 成功 GenerateGameEvent 时输出字符串
::gameevents_proxy.GetScriptScope().InputGenerateGameEvent <- function(){ printl("GenerateGameEvent!!!"); }
// 让每一位玩家都触发一次player_use事件
player <- null;
while( (player = Entities.FindByClassname(player,"*")) != null )
{
if ( player.GetClassname() == "player" && player.IsValid() )
{
EntFireByHandle(::gameevents_proxy, "GenerateGameEvent", "", 0.0, player, null);
}
}