BossHP refactor, untested
This commit is contained in:
parent
8b2441866b
commit
6faaed6ca2
@ -21,6 +21,8 @@ ConVar g_hCvar_DebugMode;
|
||||
|
||||
char g_sHUDText[256];
|
||||
|
||||
char g_aHurtEntityToBossIdx[2048] = {0xFF, ...};
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "BossHP",
|
||||
@ -423,81 +425,16 @@ public void OnEntitySpawned(int entity, const char[] classname)
|
||||
|
||||
LogDebugMessage("Hooked trigger %s:%s", sTrigger, sOutput);
|
||||
}
|
||||
|
||||
char sShowTrigger[64];
|
||||
Config.GetShowTrigger(sShowTrigger, sizeof(sShowTrigger));
|
||||
|
||||
int iShowTriggerHammerID = -1;
|
||||
if(sShowTrigger[0] == '#')
|
||||
iShowTriggerHammerID = StringToInt(sShowTrigger[1]);
|
||||
|
||||
if((iShowTriggerHammerID == -1 && sShowTrigger[0] && StrEqual(sTargetname, sShowTrigger)) || iShowTriggerHammerID == iHammerID)
|
||||
{
|
||||
char sShowOutput[64];
|
||||
Config.GetShowOutput(sShowOutput, sizeof(sShowOutput));
|
||||
|
||||
if(StrEqual(sShowOutput, "OnTakeDamage"))
|
||||
{
|
||||
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostShow);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool Once = !Config.bMultiTrigger;
|
||||
HookSingleEntityOutput(entity, sShowOutput, OnEntityOutputShow, Once);
|
||||
}
|
||||
}
|
||||
|
||||
LogDebugMessage("Hooked showtrigger %s:%s", sShowTrigger, sShowOutput);
|
||||
}
|
||||
public void OnEntityDestroyed(int entity)
|
||||
{
|
||||
if(!g_aConfig)
|
||||
return;
|
||||
|
||||
char sKillTrigger[64];
|
||||
Config.GetKillTrigger(sKillTrigger, sizeof(sKillTrigger));
|
||||
|
||||
int iKillTriggerHammerID = -1;
|
||||
if(sKillTrigger[0] == '#')
|
||||
iKillTriggerHammerID = StringToInt(sKillTrigger[1]);
|
||||
|
||||
if((iKillTriggerHammerID == -1 && sKillTrigger[0] && StrEqual(sTargetname, sKillTrigger)) || iKillTriggerHammerID == iHammerID)
|
||||
{
|
||||
char sKillOutput[64];
|
||||
Config.GetKillOutput(sKillOutput, sizeof(sKillOutput));
|
||||
|
||||
if(StrEqual(sKillOutput, "OnTakeDamage"))
|
||||
{
|
||||
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostKill);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool Once = !Config.bMultiTrigger;
|
||||
HookSingleEntityOutput(entity, sKillOutput, OnEntityOutputKill, Once);
|
||||
}
|
||||
|
||||
LogDebugMessage("Hooked killtrigger %s:%s", sKillTrigger, sKillOutput);
|
||||
}
|
||||
|
||||
char sHurtTrigger[64];
|
||||
Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
|
||||
|
||||
int iHurtTriggerHammerID = -1;
|
||||
if(sHurtTrigger[0] == '#')
|
||||
iHurtTriggerHammerID = StringToInt(sHurtTrigger[1]);
|
||||
|
||||
if((iHurtTriggerHammerID == -1 && sHurtTrigger[0] && StrEqual(sTargetname, sHurtTrigger)) || iHurtTriggerHammerID == iHammerID)
|
||||
{
|
||||
char sHurtOutput[64];
|
||||
Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput));
|
||||
|
||||
if(StrEqual(sHurtOutput, "OnTakeDamage"))
|
||||
{
|
||||
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostHurt);
|
||||
}
|
||||
else
|
||||
{
|
||||
HookSingleEntityOutput(entity, sHurtOutput, OnEntityOutputHurt);
|
||||
}
|
||||
|
||||
LogDebugMessage("Hooked hurttrigger %s:%s", sHurtTrigger, sHurtOutput);
|
||||
}
|
||||
}
|
||||
if(entity >= 0 && entity < sizeof(g_aHurtEntityToBossIdx))
|
||||
g_aHurtEntityToBossIdx[entity] = 0xFF;
|
||||
}
|
||||
|
||||
void OnTrigger(int entity, const char[] output, SDKHookType HookType = view_as<SDKHookType>(-1))
|
||||
@ -753,62 +690,13 @@ void OnKillTrigger(int entity, const char[] output, SDKHookType HookType = view_
|
||||
}
|
||||
}
|
||||
|
||||
void OnHurtTrigger(int entity, const char[] output, int activator, float damage = 1.0)
|
||||
void OnHurtTrigger(int entity, int activator, float damage = 1.0)
|
||||
{
|
||||
char sTargetname[64];
|
||||
GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname));
|
||||
int BossIdx = g_aHurtEntityToBossIdx[entity];
|
||||
if(BossIdx == 0xFF)
|
||||
return;
|
||||
|
||||
int iHammerID = GetEntProp(entity, Prop_Data, "m_iHammerID");
|
||||
|
||||
int iTemplateNum = -1;
|
||||
int iTemplateLoc = FindCharInString(sTargetname, '&', true);
|
||||
if(iTemplateLoc != -1)
|
||||
{
|
||||
iTemplateNum = StringToInt(sTargetname[iTemplateLoc + 1]);
|
||||
sTargetname[iTemplateLoc] = 0;
|
||||
}
|
||||
|
||||
for(int i = 0; i < g_aConfig.Length; i++)
|
||||
{
|
||||
CConfig Config = g_aConfig.Get(i);
|
||||
|
||||
char sHurtTrigger[64];
|
||||
Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
|
||||
|
||||
if(!sHurtTrigger[0])
|
||||
continue;
|
||||
|
||||
int iHurtTriggerHammerID = -1;
|
||||
if(sHurtTrigger[0] == '#')
|
||||
{
|
||||
iHurtTriggerHammerID = StringToInt(sHurtTrigger[1]);
|
||||
|
||||
if(iHurtTriggerHammerID != iHammerID)
|
||||
continue;
|
||||
}
|
||||
else if(!sTargetname[0] || !StrEqual(sTargetname, sHurtTrigger))
|
||||
continue;
|
||||
|
||||
char sHurtOutput[64];
|
||||
Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput));
|
||||
|
||||
if(!StrEqual(output, sHurtOutput))
|
||||
continue;
|
||||
|
||||
if(iHurtTriggerHammerID == -1)
|
||||
LogDebugMessage("Triggered hurt boss %s(%d) from output %s", sTargetname, entity, output);
|
||||
else
|
||||
LogDebugMessage("Triggered hurt boss #%d(%d) from output %s", iHurtTriggerHammerID, entity, output);
|
||||
|
||||
for(int j = 0; j < g_aBoss.Length; j++)
|
||||
{
|
||||
CBoss Boss = g_aBoss.Get(j);
|
||||
|
||||
if(Boss.dConfig != Config)
|
||||
continue;
|
||||
|
||||
if(Boss.iTemplateNum != iTemplateNum)
|
||||
continue;
|
||||
CBoss Boss = g_aBoss.Get(BossIdx);
|
||||
|
||||
Call_StartForward(g_hFwd_OnBossDamaged);
|
||||
Call_PushCell(Boss);
|
||||
@ -816,8 +704,6 @@ void OnHurtTrigger(int entity, const char[] output, int activator, float damage
|
||||
Call_PushCell(activator);
|
||||
Call_PushFloat(damage);
|
||||
Call_Finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnvEntityMakerEntitySpawned(const char[] output, int caller, int activator, float delay)
|
||||
@ -864,7 +750,7 @@ public void OnEntityOutputKill(const char[] output, int caller, int activator, f
|
||||
|
||||
public void OnEntityOutputHurt(const char[] output, int caller, int activator, float delay)
|
||||
{
|
||||
OnHurtTrigger(caller, output, activator);
|
||||
OnHurtTrigger(caller, activator);
|
||||
}
|
||||
|
||||
public void OnTakeDamagePost(int victim, int attacker, int inflictor, float damage, int damagetype)
|
||||
@ -884,7 +770,7 @@ public void OnTakeDamagePostKill(int victim, int attacker, int inflictor, float
|
||||
|
||||
public void OnTakeDamagePostHurt(int victim, int attacker, int inflictor, float damage, int damagetype)
|
||||
{
|
||||
OnHurtTrigger(victim, "OnTakeDamage", attacker, damage);
|
||||
OnHurtTrigger(victim, attacker, damage);
|
||||
}
|
||||
|
||||
public void OnGameFrame()
|
||||
@ -925,7 +811,7 @@ public void OnGameFrame()
|
||||
Boss.fWaitUntil = 0.0;
|
||||
}
|
||||
|
||||
if(!BossInit(Boss))
|
||||
if(!BossInit(i, Boss))
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -985,7 +871,7 @@ public void OnGameFrame()
|
||||
}
|
||||
}
|
||||
|
||||
bool BossInit(CBoss _Boss)
|
||||
bool BossInit(int iBoss, CBoss _Boss)
|
||||
{
|
||||
CConfig _Config = _Boss.dConfig;
|
||||
bool bNameFixup = _Config.bNameFixup;
|
||||
@ -1226,17 +1112,37 @@ bool BossInit(CBoss _Boss)
|
||||
|
||||
_Boss.bActive = true;
|
||||
|
||||
char sShowTrigger[64];
|
||||
_Config.GetShowTrigger(sShowTrigger, sizeof(sShowTrigger));
|
||||
|
||||
char sKillTrigger[64];
|
||||
_Config.GetKillTrigger(sKillTrigger, sizeof(sKillTrigger));
|
||||
|
||||
char sHurtTrigger[64];
|
||||
_Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
|
||||
|
||||
if(iTemplateNum != -1)
|
||||
{
|
||||
_Boss.iTemplateNum = iTemplateNum;
|
||||
|
||||
char sShowTrigger[64];
|
||||
_Config.GetShowTrigger(sShowTrigger, sizeof(sShowTrigger));
|
||||
|
||||
if(sShowTrigger[0])
|
||||
{
|
||||
Format(sShowTrigger, sizeof(sShowTrigger), "%s&%04d", sShowTrigger, iTemplateNum);
|
||||
}
|
||||
|
||||
if(sKillTrigger[0])
|
||||
{
|
||||
Format(sKillTrigger, sizeof(sKillTrigger), "%s&%04d", sKillTrigger, iTemplateNum);
|
||||
}
|
||||
|
||||
if(sHurtTrigger[0])
|
||||
{
|
||||
Format(sHurtTrigger, sizeof(sHurtTrigger), "%s&%04d", sHurtTrigger, iTemplateNum);
|
||||
}
|
||||
}
|
||||
|
||||
if(sShowTrigger[0])
|
||||
{
|
||||
char sShowOutput[64];
|
||||
_Config.GetShowOutput(sShowOutput, sizeof(sShowOutput));
|
||||
|
||||
@ -1257,13 +1163,8 @@ bool BossInit(CBoss _Boss)
|
||||
}
|
||||
}
|
||||
|
||||
char sKillTrigger[64];
|
||||
_Config.GetKillTrigger(sKillTrigger, sizeof(sKillTrigger));
|
||||
|
||||
if(sKillTrigger[0])
|
||||
{
|
||||
Format(sKillTrigger, sizeof(sKillTrigger), "%s&%04d", sKillTrigger, iTemplateNum);
|
||||
|
||||
char sKillOutput[64];
|
||||
_Config.GetKillOutput(sKillOutput, sizeof(sKillOutput));
|
||||
|
||||
@ -1284,19 +1185,16 @@ bool BossInit(CBoss _Boss)
|
||||
}
|
||||
}
|
||||
|
||||
char sHurtTrigger[64];
|
||||
_Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
|
||||
|
||||
if(sHurtTrigger[0])
|
||||
{
|
||||
Format(sHurtTrigger, sizeof(sHurtTrigger), "%s&%04d", sHurtTrigger, iTemplateNum);
|
||||
|
||||
char sHurtOutput[64];
|
||||
_Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput));
|
||||
|
||||
int entity = INVALID_ENT_REFERENCE;
|
||||
while((entity = FindEntityByTargetname(entity, sHurtTrigger)) != INVALID_ENT_REFERENCE)
|
||||
{
|
||||
g_aHurtEntityToBossIdx[entity] = iBoss;
|
||||
|
||||
if(StrEqual(sHurtOutput, "OnTakeDamage"))
|
||||
{
|
||||
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostHurt);
|
||||
@ -1309,7 +1207,6 @@ bool BossInit(CBoss _Boss)
|
||||
LogDebugMessage("Hooked hurttrigger %s:%s", sHurtTrigger, sHurtOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char sBoss[64];
|
||||
_Config.GetName(sBoss, sizeof(sBoss));
|
||||
|
Loading…
Reference in New Issue
Block a user