From f2f874939d53b9914ebeca1b7220f468fabc6484 Mon Sep 17 00:00:00 2001 From: samisalreadytaken <46823719+samisalreadytaken@users.noreply.github.com> Date: Fri, 4 Mar 2022 16:02:00 +0300 Subject: [PATCH] Fix vscript global hook calls --- sp/src/vscript/vscript_squirrel.nut | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/sp/src/vscript/vscript_squirrel.nut b/sp/src/vscript/vscript_squirrel.nut index b1700118..059f37f0 100644 --- a/sp/src/vscript/vscript_squirrel.nut +++ b/sp/src/vscript/vscript_squirrel.nut @@ -215,16 +215,17 @@ Hooks <- function Call( scope, event, ... ) { - local firstReturn = null + local firstReturn - if ( scope == null ) + // global hook; call all scopes + if ( !scope ) { - // null scope = global hook; call all scopes - vargv.insert(0,this) - foreach ( t in s_List ) + vargv.insert( 0, null ) + foreach( sc,t in s_List ) { if ( event in t ) { + vargv[0] = sc foreach( context, callback in t[event] ) { //printf( "(%.4f) Calling hook '%s' of context '%s' in static iteration\n", Time(), event, context ) @@ -241,7 +242,7 @@ Hooks <- local t = s_List[scope] if ( event in t ) { - vargv.insert(0,scope) + vargv.insert( 0, scope ) foreach( context, callback in t[event] ) { //printf( "(%.4f) Calling hook '%s' of context '%s'\n", Time(), event, context ) @@ -258,13 +259,7 @@ Hooks <- function ScopeHookedToEvent( scope, event ) { - if ( scope in s_List ) - { - if (event in s_List[scope]) - return true - } - - return false + return ( scope in s_List ) && ( event in s_List[scope] ) } }