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

Rewriting player_hurt dmg_health


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 10-21-2011 , 20:40   Rewriting player_hurt dmg_health
Reply With Quote #1

Hello everyone,
I'm trying to adjust a throwing knife mod (http://forums.alliedmods.net/showthread.php?t=125226) so that if a player has some throwing knives left and they knife someone then it will deal the amount of damage a throwing knife usually would rather than the usual amount. This is because players often complain that they are trying to throw a throwing knife (which does 57hp damage) when they are in close quarters combat, but since they are too close to the victim it performs a standard left click knife attack (17hp damage) instead.

I went ahead and added this to OnPluginStart, just like the other hooks:
Code:
HookEvent("player_hurt", EventPlayerHurt, EventHookMode_Pre);
and have written this action:
Code:
public Action:EventPlayerHurt(Handle:event,const String:name[],bool:dontBroadcast) { // Checking for left click knifings that should be throwing knives instead

    if (GetConVarBool(g_CVarEnable)) {
        decl String:checkWeapon[32];
        GetEventString(event, "weapon", checkWeapon, sizeof(checkWeapon));
        if (!StrEqual(checkWeapon, "knife")){
            return Plugin_Continue;
        }
        new client = GetClientOfUserId(GetEventInt(event, "userid"));
        if (!IsFakeClient(client) && StrEqual(checkWeapon, "knife") && (g_iKnives[client] > 0)) {
            LogMessage("Knife health should be adjusted to %d", StringToInt(g_sDamage));
            SetEventInt(event, "dmg_health", StringToInt(g_sDamage));
            LogMessage("Knife health actually adjusted to %d", GetEventInt(event, "dmg_health"));
        }
        return Plugin_Changed;
    }
    return Plugin_Continue;
}
I *thought* that this would hook the player_hurt event before it was actually fired, check to make sure that it is a knife being used, change the damage the knife is applying, and then fire the weapon. I added the LogMessage()s to debug and it spits out the correct information:
Code:
L 10/21/2011 - 18:51:42: [cssthrowingknives.smx] Knife health should be adjusted to 61
L 10/21/2011 - 18:51:42: [cssthrowingknives.smx] Knife health actually adjusted to 61
I'm not really sure why this isn't working, unless it is changing the notification after the fact even though I am Pre-Hooking.

Any ideas?

Once I get the damage adjustment working correctly then I will subtract a knife from the player as if he had actually thrown a knife.

Last edited by thatguyyoulove; 10-21-2011 at 20:41.
thatguyyoulove is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 10-21-2011 , 20:48   Re: Rewriting player_hurt dmg_health
Reply With Quote #2

It's a common misconception that EventHookMode_Pre fires before the event fires. This is not true, however. The event has already fired, but the _Pre means before the client is notified of the event. Post of course, means after the client is notified.
__________________
thetwistedpanda is offline
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 10-21-2011 , 22:46   Re: Rewriting player_hurt dmg_health
Reply With Quote #3

Very well. Looks like I should look into applying damage manually. Thanks for clearing things up.
thatguyyoulove is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 10-22-2011 , 10:38   Re: Rewriting player_hurt dmg_health
Reply With Quote #4

You can use SDKHooks and use TraceAttack maybe... maybe
TnTSCS is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 10-22-2011 , 12:44   Re: Rewriting player_hurt dmg_health
Reply With Quote #5

If you just want to do extra damage, look into pimpinjuice's DealDamage snippet, used in a player_hurt hook or w/e.

Actually changing the damage can be done with SDKHook's OnTakeDamage.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 10-22-2011 , 16:04   Re: Rewriting player_hurt dmg_health
Reply With Quote #6

don't forget you can do extra damage with sdkhooks as well now.
blodia 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 17:07.


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