Raised This Month: $51 Target: $400
 12% 

TF2: Add health on backstab (FF2 related)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SomePanns
Senior Member
Join Date: Dec 2013
Old 03-15-2016 , 14:53   TF2: Add health on backstab (FF2 related)
Reply With Quote #1

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!
SomePanns is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-15-2016 , 15:35   Re: TF2: Add health on backstab (FF2 related)
Reply With Quote #2

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
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
SomePanns
Senior Member
Join Date: Dec 2013
Old 03-15-2016 , 15:44   Re: TF2: Add health on backstab (FF2 related)
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
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.
SomePanns is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-15-2016 , 16:14   Re: TF2: Add health on backstab (FF2 related)
Reply With Quote #4

Ah, OK.

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

PHP Code:
public Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3], int damagecustom)
{
    if(
IsValidClient(attacker)) {
    
        
int boss FF2_GetBossIndex(attacker);
        if (
boss != -&& damagecustom == TF_CUSTOM_BACKSTAB) {
            
FF2_SetBossHealth(bossFF2_GetBossHealth(boss) + FF2_GetAbilityArgument(bossthis_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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-15-2016 at 16:14.
Powerlord is offline
SomePanns
Senior Member
Join Date: Dec 2013
Old 03-15-2016 , 16:30   Re: TF2: Add health on backstab (FF2 related)
Reply With Quote #5

Quote:
Originally Posted by Powerlord View Post
Ah, OK.

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

PHP Code:
public Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3], int damagecustom)
{
    if(
IsValidClient(attacker)) {
    
        
int boss FF2_GetBossIndex(attacker);
        if (
boss != -&& damagecustom == TF_CUSTOM_BACKSTAB) {
            
FF2_SetBossHealth(bossFF2_GetBossHealth(boss) + FF2_GetAbilityArgument(bossthis_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 is offline
SomePanns
Senior Member
Join Date: Dec 2013
Old 03-22-2016 , 07:52   Re: TF2: Add health on backstab (FF2 related)
Reply With Quote #6

Bump, anyone?
SomePanns is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode