diff --git a/FixGameUI/scripting/FixGameUI.sp b/FixGameUI/scripting/FixGameUI.sp index 9d571366..a2bc9bae 100644 --- a/FixGameUI/scripting/FixGameUI.sp +++ b/FixGameUI/scripting/FixGameUI.sp @@ -16,7 +16,7 @@ public Plugin myinfo = } Handle g_hAcceptInput; -int g_iAttachedGameUI[MAXPLAYERS + 1]; +ArrayList g_hAttachedClients; public void OnPluginStart() { @@ -25,6 +25,8 @@ public void OnPluginStart() HookEntityOutput("game_ui", "PlayerOn", GameUI_PlayerOn); HookEntityOutput("game_ui", "PlayerOff", GameUI_PlayerOff); + g_hAttachedClients = new ArrayList(); + // Gamedata. Handle hConfig = LoadGameConfigFile("sdktools.games"); if (hConfig == INVALID_HANDLE) @@ -43,7 +45,6 @@ public void OnPluginStart() DHookAddParam(g_hAcceptInput, HookParamType_CBaseEntity); DHookAddParam(g_hAcceptInput, HookParamType_Object, 20); //varaint_t is a union of 12 (float[3]) plus two int type params 12 + 8 = 20 DHookAddParam(g_hAcceptInput, HookParamType_Int); - } public Action Event_PlayerDeath(Handle hEvent, const char[] szName, bool bDontBroadcast) @@ -69,7 +70,11 @@ public void GameUI_PlayerOn(const char[] szOutput, int iCaller, int iActivator, if(!(1 <= iActivator <= MaxClients)) return; - g_iAttachedGameUI[iActivator] = EntIndexToEntRef(iCaller); + int GameUIArray[2]; + GameUIArray[0] = iCaller; + GameUIArray[1] = iActivator; + + g_hAttachedClients.PushArray(GameUIArray); } public void GameUI_PlayerOff(const char[] szOutput, int iCaller, int iActivator, float fDelay) @@ -77,19 +82,47 @@ public void GameUI_PlayerOff(const char[] szOutput, int iCaller, int iActivator, if(!(1 <= iActivator <= MaxClients)) return; - g_iAttachedGameUI[iActivator] = 0; + for(int i; i < g_hAttachedClients.Length; i++) + { + int GameUIArray[2]; + g_hAttachedClients.GetArray(i, GameUIArray); + + if (GameUIArray[0] == iCaller) + { + g_hAttachedClients.Erase(i); + break; + } + } +} + +public void OnEntityDestroyed(int entity) +{ + for(int i; i < g_hAttachedClients.Length; i++) + { + int GameUIArray[2]; + g_hAttachedClients.GetArray(i, GameUIArray); + + if (GameUIArray[0] == entity) + { + g_hAttachedClients.Erase(i); + break; + } + } } void RemoveFromGameUI(int client) { - if(!g_iAttachedGameUI[client]) - return; + for(int i; i < g_hAttachedClients.Length; i++) + { + int GameUIArray[2]; + g_hAttachedClients.GetArray(i, GameUIArray); - int entity = EntRefToEntIndex(g_iAttachedGameUI[client]); - if(entity == INVALID_ENT_REFERENCE) - return; - - AcceptEntityInput(entity, "Deactivate", client, entity); + if (GameUIArray[1] == client) + { + AcceptEntityInput(GameUIArray[0], "Deactivate", GameUIArray[1], GameUIArray[0]); + g_hAttachedClients.Erase(i); + } + } } public void OnEntityCreated(int entity, const char[] classname)