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

[TF2] Blocking player_hurt/death events?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 08-22-2011 , 05:45   [TF2] Blocking player_hurt/death events?
Reply With Quote #1

So I'm trying to create a plugin that will protect duelists from people who are not dueling, as well as prevent them from attacking people who are not dueling.

Right now I'm using "EventHookMode_Pre" hooks for "player_hurt" and "player_death". Then returning Plugin_Handled if either the attacker or victim isn't in a duel and the other is.

The problem is that, the victim takes the damage or dies, but it isn't reported. If a duelist gets an unreported assist on the player they're dueling, they still receive a point in the duel.

Here's my code:
Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>

#define PLUGIN_VERSION  "0.01a"

public Plugin:myinfo =
{
    name = "TF2 Duel Protection",
    author = "NIGathan",
    description = "Restricts dueling players to only hurt and be hurt by other duelists.",
    version = PLUGIN_VERSION,
    url = "http://justca.me/"
};

new Handle:c_Enabled = INVALID_HANDLE;
new g_Enabled = 1;

public OnPluginStart()
{
    CreateConVar("sm_duel_protect_version", PLUGIN_VERSION, "TF2 Duel Protection Version",FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    c_Enabled = CreateConVar("sm_duel_protect", "1", "Enable/Disable Duel Protection.", FCVAR_PLUGIN, true, 0.0, true, 1.0);
    HookConVarChange(c_Enabled,UpdateCvar);
    HookEvent("player_hurt", Event_Check, EventHookMode_Pre);
    HookEvent("player_death", Event_Check, EventHookMode_Pre);
}
public OnEventShutDown()
{
    UnhookConVarChange(c_Enabled,UpdateCvar);
    UnhookEvent("player_hurt", Event_Check);
    UnhookEvent("player_death", Event_Check);
}

public UpdateCvar(Handle:convar, const String:oldValue[], const String:newValue[])
{
    g_Enabled = GetConVarInt(c_Enabled);
    if (g_Enabled == 1)
    {
        HookEvent("player_hurt", Event_Check, EventHookMode_Pre);
        HookEvent("player_death", Event_Check, EventHookMode_Pre);
    }
    else
    {
        UnhookEvent("player_hurt", Event_Check);
        UnhookEvent("player_death", Event_Check);
    }
}

public Action:Event_Check(Handle:event, const String:name[], bool:dontBroadcast)
{
    new attackerId = GetClientOfUserId(GetEventInt(event, "attacker"));
    new victimId = GetClientOfUserId(GetEventInt(event, "userid"));
    
    if (attackerId <= 0 || victimId <= 0) return Plugin_Continue;
    
    if ((TF2_IsPlayerInDuel(attackerId)) && (!TF2_IsPlayerInDuel(victimId))) return Plugin_Handled;
    if ((!TF2_IsPlayerInDuel(attackerId)) && (TF2_IsPlayerInDuel(victimId))) return Plugin_Handled;
    return Plugin_Continue;
}
Any ideas?

Thanks in advance.
NIGathan is offline
Hardcor3
Member
Join Date: Mar 2009
Old 08-22-2011 , 05:48   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #2

I dont think you can block damage or deaths using those events, even in pre-hook mode. You probs need to use SDKHooks extension to achieve this.

Last edited by Hardcor3; 08-22-2011 at 05:48. Reason: typo
Hardcor3 is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 08-22-2011 , 05:56   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #3

Thanks for your quick response, although to me, it isn't worth using an extension.

I have gotten around it in a different plugin inside player_hurt by adding the dmg to the victim's hp, and this also prevents them from dying. The only problem with this is when their new hp is more than their old hp. Like if they get backstabbed.. Tons of buffed hp would not be acceptable in this plugin.
NIGathan is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 08-22-2011 , 08:24   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #4

Sorry for double post, do you think if I were to change "damageamount" to 0 in the player_hurt event, and return Plugin_Changed, it wouldn't hurt the player?

I would test real quick, but I've already begun rewriting this a whole different way, and my servers empty atm.

Thanks.
NIGathan is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-22-2011 , 09:59   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #5

Player is already hurt when event launched.
Use SDKHooks change or prevent damage.


*edit
ou, mean of this was block event.

*edit WTF ?

Last edited by Bacardi; 08-22-2011 at 10:19.
Bacardi is offline
psychonic

BAFFLED
Join Date: May 2008
Old 08-22-2011 , 10:03   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #6

Quote:
Originally Posted by NIGathan View Post
Thanks for your quick response, although to me, it isn't worth using an extension.
You are already using one. TF2_IsPlayerInDuel comes from the TF2 extension.
psychonic is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 08-22-2011 , 10:18   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #7

Quote:
Originally Posted by psychonic View Post
You are already using one. TF2_IsPlayerInDuel comes from the TF2 extension.
Heh.. Good point. I suppose SDKHooks would be better than the current method I just wrote up...

Thanks for all the help.
NIGathan is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 08-22-2011 , 10:44   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #8

Alright so I've never used SDKHooks before, and this is what I've got:

Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    if ((TF2_IsPlayerInDuel(attacker)) && (!TF2_IsPlayerInDuel(victim))) return Plugin_Handled;
    if ((!TF2_IsPlayerInDuel(attacker)) && (TF2_IsPlayerInDuel(victim))) return Plugin_Handled;
    return Plugin_Continue;
}
Should this work? Or am I doing something wrong here?

Edit: Or do I need to set the damage to 0 before returning?

Last edited by NIGathan; 08-22-2011 at 10:51.
NIGathan is offline
psychonic

BAFFLED
Join Date: May 2008
Old 08-22-2011 , 10:55   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #9

Quote:
Originally Posted by NIGathan View Post
Alright so I've never used SDKHooks before, and this is what I've got:

Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    if ((TF2_IsPlayerInDuel(attacker)) && (!TF2_IsPlayerInDuel(victim))) return Plugin_Handled;
    if ((!TF2_IsPlayerInDuel(attacker)) && (TF2_IsPlayerInDuel(victim))) return Plugin_Handled;
    return Plugin_Continue;
}
Should this work? Or am I doing something wrong here?

Edit: Or do I need to set the damage to 0 before returning?
Returning Plugin_Handled will indeed block the damage altogether.

You do want to make sure that attacker is a valid client. (it could be 0 for world/unspecified or even another entity, not necessarily a player).

Also, if you want to account for late-loading the plugin, loop through all client indexes in OnPluginStart and add the hook if IsClientInGame.
psychonic is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 08-22-2011 , 10:58   Re: [TF2] Blocking player_hurt/death events?
Reply With Quote #10

Quote:
Originally Posted by psychonic View Post
Returning Plugin_Handled will indeed block the damage altogether.

You do want to make sure that attacker is a valid client. (it could be 0 for world/unspecified or even another entity, not necessarily a player).

Also, if you want to account for late-loading the plugin, loop through all client indexes in OnPluginStart and add the hook if IsClientInGame.
Thanks again!

I gotta run to class now, but I'll try it out when I get back home in a few hours.
NIGathan 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 06:33.


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