Basically writing a subplugin for a FF2 boss, however I'm concerned about why it's not working. I'm obviously doing something wrong but I can't put my finger on what exactly it is. I have some log messages print too, but it never prints "HP ON STAB: Applied weapon buff" which means it actually never gets to that stage (it prints the rest of the log messages thogh). As soon as the boss backstabs someone, additional health should be added (even if he is at max HP though).
Code:
#pragma semicolon 1
#include <sourcemod>
#include <tf2_stocks>
#include <sdkhooks>
#include <freak_fortress_2>
#include <freak_fortress_2_subplugin>
#pragma newdecls required
public Plugin myinfo = {
name = "Freak Fortress 2: HP on backstab passive ability",
author = "",
version = "1.0",
};
public void OnPluginStart2()
{
HookEvent("teamplay_round_start", Event_RoundStart);
HookEvent("arena_round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("player_spawn", Event_RoundStart);
LogMessage("HP ON STAB: Plugin loaded...");
if(FF2_GetRoundState()==1)
{
HookAbilities();
}
}
public Action FF2_OnAbility2(int boss,const char[] plugin_name,const char[] ability_name,int status)
{
}
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if(IsValidClient(attacker)) {
int boss = FF2_GetBossIndex(attacker);
char szClassName[64];
GetEntityClassname(GetEntPropEnt(attacker, Prop_Send, "m_hActiveWeapon"), szClassName, sizeof(szClassName));
if (StrEqual(szClassName, "tf_weapon_knife") && (damagetype & DMG_CRIT == DMG_CRIT))
{
if(boss !=-1) {
FF2_SetBossHealth(boss, FF2_GetBossHealth(boss) + FF2_GetAbilityArgument(boss, this_plugin_name, "hp_on_stab", 1));
LogMessage("HP ON STAB: Applied weapon buff");
}
}
}
return Plugin_Changed;
}
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
CreateTimer(0.35, CheckAbilities);
}
public Action CheckAbilities(Handle timer)
{
HookAbilities();
}
void HookAbilities()
{
for(int client=1;client<=MaxClients;client++)
{
if(!IsValidClient(client, false))
continue;
int boss=FF2_GetBossIndex(client);
if(boss>=0 && FF2_HasAbility(boss, this_plugin_name, "hp_on_stab"))
{
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
LogMessage("HP ON STAB: Hook successfull...");
}
}
}
stock bool IsValidClient(int client, bool isAlive=false)
{
if(!client||client>MaxClients) return false;
if(isAlive) return IsClientInGame(client) && IsPlayerAlive(client);
return IsClientInGame(client);
}
All help is appreciated!