PDA

View Full Version : TF2: Add health on backstab (FF2 related)


SomePanns
03-15-2016, 14:53
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).

#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!

Powerlord
03-15-2016, 15:35
Wait, you want to add HP to the boss when they get backstabbed?

This will conflict with the FF2 core, which uses an OnTakeDamage hook to modify the amount of damage a boss takes from a backstab.

Side note: There are better way of detecting a backstab, such as checking if TakeDamage's damagecustom == TF_CUSTOM_BACKSTAB

SomePanns
03-15-2016, 15:44
Wait, you want to add HP to the boss when they get backstabbed?

This will conflict with the FF2 core, which uses an OnTakeDamage hook to modify the amount of damage a boss takes from a backstab.

Side note: There are better way of detecting a backstab, such as checking if TakeDamage's damagecustom == TF_CUSTOM_BACKSTAB

No, that's not my intention at all. I want to add HP to the boss when HE backstabs someone.

Powerlord
03-15-2016, 16:14
Ah, OK.

I still think the hook would be better written like this:

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
{
if(IsValidClient(attacker)) {

int boss = FF2_GetBossIndex(attacker);
if (boss != -1 && damagecustom == TF_CUSTOM_BACKSTAB) {
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_Continue;
}

I don't remember if FF2_GetBossIndex takes a client index or a userid.

SomePanns
03-15-2016, 16:30
Ah, OK.

I still think the hook would be better written like this:

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
{
if(IsValidClient(attacker)) {

int boss = FF2_GetBossIndex(attacker);
if (boss != -1 && damagecustom == TF_CUSTOM_BACKSTAB) {
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_Continue;
}

I don't remember if FF2_GetBossIndex takes a client index or a userid.
Agreed. Applied this and tried it out. Still doesn't give the boss any health when he backstabs someone. And FF2_GetBossIndex returns boss index as far as I know.

SomePanns
03-22-2016, 07:52
Bump, anyone?