BossHP: fix more bugs
This commit is contained in:
		
							parent
							
								
									f7f8271691
								
							
						
					
					
						commit
						961b1c6916
					
				| @ -21,7 +21,7 @@ ConVar g_hCvar_DebugMode; | |||||||
| 
 | 
 | ||||||
| char g_sHUDText[256]; | char g_sHUDText[256]; | ||||||
| 
 | 
 | ||||||
| char g_aHurtEntityToBossIdx[2048] = {0xFF, ...}; | Handle g_aHurtEntityToBoss[2048] = {INVALID_HANDLE, ...}; | ||||||
| 
 | 
 | ||||||
| public Plugin myinfo = | public Plugin myinfo = | ||||||
| { | { | ||||||
| @ -62,9 +62,9 @@ public void OnPluginEnd() | |||||||
| 
 | 
 | ||||||
| void Cleanup() | void Cleanup() | ||||||
| { | { | ||||||
| 	for(int entity = 0; entity < sizeof(g_aHurtEntityToBossIdx); entity++) | 	for(int entity = 0; entity < sizeof(g_aHurtEntityToBoss); entity++) | ||||||
| 	{ | 	{ | ||||||
| 		g_aHurtEntityToBossIdx[entity] = 0xFF; | 		g_aHurtEntityToBoss[entity] = INVALID_HANDLE; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(g_aBoss) | 	if(g_aBoss) | ||||||
| @ -374,9 +374,9 @@ public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) | |||||||
| 	if(!g_aConfig) | 	if(!g_aConfig) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	for(int entity = 0; entity < sizeof(g_aHurtEntityToBossIdx); entity++) | 	for(int entity = 0; entity < sizeof(g_aHurtEntityToBoss); entity++) | ||||||
| 	{ | 	{ | ||||||
| 		g_aHurtEntityToBossIdx[entity] = 0xFF; | 		g_aHurtEntityToBoss[entity] = INVALID_HANDLE; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(g_aBoss) | 	if(g_aBoss) | ||||||
| @ -477,19 +477,19 @@ public void OnEntitySpawned(int entity, const char[] classname) | |||||||
| 			char sHurtOutput[64]; | 			char sHurtOutput[64]; | ||||||
| 			Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput)); | 			Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput)); | ||||||
| 
 | 
 | ||||||
| 			int iBoss = -1; | 			CBoss Boss = view_as<CBoss>(INVALID_HANDLE); | ||||||
| 			for(int j = 0; j < g_aBoss.Length; j++) | 			for(int j = 0; j < g_aBoss.Length; j++) | ||||||
| 			{ | 			{ | ||||||
| 				CBoss Boss = g_aBoss.Get(j); | 				CBoss _Boss = g_aBoss.Get(j); | ||||||
| 
 | 
 | ||||||
| 				if(Boss.dConfig != Config) | 				if(Boss.dConfig != Config) | ||||||
| 					continue; | 					continue; | ||||||
| 
 | 
 | ||||||
| 				iBoss = j; | 				Boss = _Boss; | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if(iBoss == -1) | 			if(Boss == INVALID_HANDLE) | ||||||
| 			{ | 			{ | ||||||
| 				char sBoss[64]; | 				char sBoss[64]; | ||||||
| 				Config.GetName(sBoss, sizeof(sBoss)); | 				Config.GetName(sBoss, sizeof(sBoss)); | ||||||
| @ -497,7 +497,7 @@ public void OnEntitySpawned(int entity, const char[] classname) | |||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			g_aHurtEntityToBossIdx[entity] = iBoss; | 			g_aHurtEntityToBoss[entity] = Boss; | ||||||
| 
 | 
 | ||||||
| 			if(StrEqual(sHurtOutput, "OnTakeDamage")) | 			if(StrEqual(sHurtOutput, "OnTakeDamage")) | ||||||
| 			{ | 			{ | ||||||
| @ -508,7 +508,7 @@ public void OnEntitySpawned(int entity, const char[] classname) | |||||||
| 				HookSingleEntityOutput(entity, sHurtOutput, OnEntityOutputHurt); | 				HookSingleEntityOutput(entity, sHurtOutput, OnEntityOutputHurt); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			LogDebugMessage("Hooked hurttrigger %s:%s (iBoss %d)", sHurtTrigger, sHurtOutput, iBoss); | 			LogDebugMessage("Hooked hurttrigger %s:%s Late", sHurtTrigger, sHurtOutput); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -518,8 +518,8 @@ public void OnEntityDestroyed(int entity) | |||||||
| 	if(!g_aConfig) | 	if(!g_aConfig) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	if(entity >= 0 && entity < sizeof(g_aHurtEntityToBossIdx)) | 	if(entity >= 0 && entity < sizeof(g_aHurtEntityToBoss)) | ||||||
| 		g_aHurtEntityToBossIdx[entity] = 0xFF; | 		g_aHurtEntityToBoss[entity] = INVALID_HANDLE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void OnTrigger(int entity, const char[] output, SDKHookType HookType = view_as<SDKHookType>(-1)) | void OnTrigger(int entity, const char[] output, SDKHookType HookType = view_as<SDKHookType>(-1)) | ||||||
| @ -767,9 +767,7 @@ void OnKillTrigger(int entity, const char[] output, SDKHookType HookType = view_ | |||||||
| 				Call_PushCell(1); | 				Call_PushCell(1); | ||||||
| 				Call_Finish(); | 				Call_Finish(); | ||||||
| 
 | 
 | ||||||
| 				delete Boss; | 				DeleteBoss(j, Boss); | ||||||
| 				g_aBoss.Erase(j); |  | ||||||
| 				OnBossDeleted(j); |  | ||||||
| 				j--; | 				j--; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -778,11 +776,10 @@ void OnKillTrigger(int entity, const char[] output, SDKHookType HookType = view_ | |||||||
| 
 | 
 | ||||||
| void OnHurtTrigger(int entity, int activator, float damage = 1.0) | void OnHurtTrigger(int entity, int activator, float damage = 1.0) | ||||||
| { | { | ||||||
| 	int BossIdx = g_aHurtEntityToBossIdx[entity]; | 	if(g_aHurtEntityToBoss[entity] == INVALID_HANDLE) | ||||||
| 	if(BossIdx == 0xFF) |  | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
| 	CBoss Boss = g_aBoss.Get(BossIdx); | 	CBoss Boss = view_as<CBoss>(g_aHurtEntityToBoss[entity]); | ||||||
| 
 | 
 | ||||||
| 	Call_StartForward(g_hFwd_OnBossDamaged); | 	Call_StartForward(g_hFwd_OnBossDamaged); | ||||||
| 	Call_PushCell(Boss); | 	Call_PushCell(Boss); | ||||||
| @ -881,9 +878,7 @@ public void OnGameFrame() | |||||||
| 			Call_PushCell(1); | 			Call_PushCell(1); | ||||||
| 			Call_Finish(); | 			Call_Finish(); | ||||||
| 
 | 
 | ||||||
| 			delete Boss; | 			DeleteBoss(i, Boss); | ||||||
| 			g_aBoss.Erase(i); |  | ||||||
| 			OnBossDeleted(i); |  | ||||||
| 			i--; | 			i--; | ||||||
| 
 | 
 | ||||||
| 			continue; | 			continue; | ||||||
| @ -898,7 +893,7 @@ public void OnGameFrame() | |||||||
| 				Boss.fWaitUntil = 0.0; | 				Boss.fWaitUntil = 0.0; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if(!BossInit(i, Boss)) | 			if(!BossInit(Boss)) | ||||||
| 				continue; | 				continue; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -917,9 +912,7 @@ public void OnGameFrame() | |||||||
| 				Call_PushCell(2); | 				Call_PushCell(2); | ||||||
| 				Call_Finish(); | 				Call_Finish(); | ||||||
| 
 | 
 | ||||||
| 				delete Boss; | 				DeleteBoss(i, Boss); | ||||||
| 				g_aBoss.Erase(i); |  | ||||||
| 				OnBossDeleted(i); |  | ||||||
| 				i--; | 				i--; | ||||||
| 
 | 
 | ||||||
| 				continue; | 				continue; | ||||||
| @ -959,7 +952,7 @@ public void OnGameFrame() | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool BossInit(int iBoss, CBoss _Boss) | bool BossInit(CBoss _Boss) | ||||||
| { | { | ||||||
| 	CConfig _Config = _Boss.dConfig; | 	CConfig _Config = _Boss.dConfig; | ||||||
| 	bool bNameFixup = _Config.bNameFixup; | 	bool bNameFixup = _Config.bNameFixup; | ||||||
| @ -1279,7 +1272,7 @@ bool BossInit(int iBoss, CBoss _Boss) | |||||||
| 		int entity = INVALID_ENT_REFERENCE; | 		int entity = INVALID_ENT_REFERENCE; | ||||||
| 		while((entity = FindEntityByTargetname(entity, sHurtTrigger)) != INVALID_ENT_REFERENCE) | 		while((entity = FindEntityByTargetname(entity, sHurtTrigger)) != INVALID_ENT_REFERENCE) | ||||||
| 		{ | 		{ | ||||||
| 			g_aHurtEntityToBossIdx[entity] = iBoss; | 			g_aHurtEntityToBoss[entity] = _Boss; | ||||||
| 
 | 
 | ||||||
| 			if(StrEqual(sHurtOutput, "OnTakeDamage")) | 			if(StrEqual(sHurtOutput, "OnTakeDamage")) | ||||||
| 			{ | 			{ | ||||||
| @ -1484,11 +1477,16 @@ int FindEntityByTargetname(int entity, const char[] sTargetname, const char[] sC | |||||||
| 	return INVALID_ENT_REFERENCE; | 	return INVALID_ENT_REFERENCE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void OnBossDeleted(int iBoss) | void DeleteBoss(int index, CBoss Boss) | ||||||
| { | { | ||||||
| 	for(int entity = 0; entity < sizeof(g_aHurtEntityToBossIdx); entity++) | 	for(int entity = 0; entity < sizeof(g_aHurtEntityToBoss); entity++) | ||||||
| 	{ | 	{ | ||||||
| 		if(g_aHurtEntityToBossIdx[entity] == iBoss) | 		if(g_aHurtEntityToBoss[entity] == Boss) | ||||||
| 			g_aHurtEntityToBossIdx[entity] = 0xFF; | 		{ | ||||||
|  | 			g_aHurtEntityToBoss[entity] = INVALID_HANDLE; | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	delete Boss; | ||||||
|  | 	g_aBoss.Erase(index); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user