[FixGameUI] Change storage, entref only works for edicts.

This commit is contained in:
zaCade 2023-01-24 14:27:24 +01:00
parent 856b97d65a
commit 50ac606c28

View File

@ -16,7 +16,7 @@ public Plugin myinfo =
} }
Handle g_hAcceptInput; Handle g_hAcceptInput;
int g_iAttachedGameUI[MAXPLAYERS + 1]; ArrayList g_hAttachedClients;
public void OnPluginStart() public void OnPluginStart()
{ {
@ -25,6 +25,8 @@ public void OnPluginStart()
HookEntityOutput("game_ui", "PlayerOn", GameUI_PlayerOn); HookEntityOutput("game_ui", "PlayerOn", GameUI_PlayerOn);
HookEntityOutput("game_ui", "PlayerOff", GameUI_PlayerOff); HookEntityOutput("game_ui", "PlayerOff", GameUI_PlayerOff);
g_hAttachedClients = new ArrayList();
// Gamedata. // Gamedata.
Handle hConfig = LoadGameConfigFile("sdktools.games"); Handle hConfig = LoadGameConfigFile("sdktools.games");
if (hConfig == INVALID_HANDLE) if (hConfig == INVALID_HANDLE)
@ -43,7 +45,6 @@ public void OnPluginStart()
DHookAddParam(g_hAcceptInput, HookParamType_CBaseEntity); 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_Object, 20); //varaint_t is a union of 12 (float[3]) plus two int type params 12 + 8 = 20
DHookAddParam(g_hAcceptInput, HookParamType_Int); DHookAddParam(g_hAcceptInput, HookParamType_Int);
} }
public Action Event_PlayerDeath(Handle hEvent, const char[] szName, bool bDontBroadcast) 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)) if(!(1 <= iActivator <= MaxClients))
return; 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) 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)) if(!(1 <= iActivator <= MaxClients))
return; 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) void RemoveFromGameUI(int client)
{ {
if(!g_iAttachedGameUI[client]) for(int i; i < g_hAttachedClients.Length; i++)
return; {
int GameUIArray[2];
g_hAttachedClients.GetArray(i, GameUIArray);
int entity = EntRefToEntIndex(g_iAttachedGameUI[client]); if (GameUIArray[1] == client)
if(entity == INVALID_ENT_REFERENCE) {
return; AcceptEntityInput(GameUIArray[0], "Deactivate", GameUIArray[1], GameUIArray[0]);
g_hAttachedClients.Erase(i);
AcceptEntityInput(entity, "Deactivate", client, entity); }
}
} }
public void OnEntityCreated(int entity, const char[] classname) public void OnEntityCreated(int entity, const char[] classname)