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

[Snippet] TF2 Damage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-15-2008 , 10:53   [Snippet] TF2 Damage
Reply With Quote #1

Yet another snippet I know this has been posted before by naris, but it had all these unnecessary files and stocks, so I made a shorter one a while back (just in case I'd ever need it), and now I'm posting it here Enjoy.
Code:
#include <sourcemod> #include <sdktools> new g_iHealth[MAXPLAYERS + 1]; new g_iMaxClients; public OnPluginStart() {     HookEntityOutput("item_healthkit_small""OnPlayerTouch",    EntityOutput_SaveHealth);     HookEntityOutput("item_healthkit_medium", "OnPlayerTouch",    EntityOutput_SaveHealth);     HookEntityOutput("item_healthkit_full",   "OnPlayerTouch",    EntityOutput_SaveHealth);     HookEntityOutput("prop_dynamic",          "OnAnimationBegun", EntityOutput_SaveHealthAll);         HookEvent("player_hurt",  Event_PlayerHurt);     HookEvent("player_spawn", Event_PlayerSpawn); } public OnMapStart() {     g_iMaxClients        = GetMaxClients(); } public EntityOutput_SaveHealth(const String:output[],    caller, activator, Float:delay) {     g_iHealth[activator] = GetClientHealth(activator); } public EntityOutput_SaveHealthAll(const String:output[], caller, activator, Float:delay) {     for (new i = 1; i <= g_iMaxClients; i++) {         if (IsClientInGame(i) && !IsClientObserver(i)) {             g_iHealth[i] = GetClientHealth(i);         }     } } public Action:Event_PlayerHurt(Handle:event,  const String:name[], bool:dontBroadcast)   {     new iClient = GetClientOfUserId(GetEventInt(event, "userid")),         iHealth = GetEventInt(event, "health");         PrintToChat(iClient, "Damage: %d", g_iHealth[iClient] - iHealth);         g_iHealth[iClient]   = iHealth; } public Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)   {     CreateTimer(0.1, Timer_SaveHealth, GetClientOfUserId(GetEventInt(event, "userid"))); } public Action:Timer_SaveHealth(Handle:timer, any:client) {     g_iHealth[client]    = GetClientHealth(client); }
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 07-18-2008 at 18:24.
DJ Tsunami is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-15-2008 , 14:19   Re: [Snippet] TF2 Damage
Reply With Quote #2

What about when players pick up med packs or use a resupply cabinet?
bl4nk is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-15-2008 , 15:55   Re: [Snippet] TF2 Damage
Reply With Quote #3

And why should this be limited to TF2 only ? player_hurt and player_spawn are available in all games afaik.
berni is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-15-2008 , 18:10   Re: [Snippet] TF2 Damage
Reply With Quote #4

@bl4nk: good point... You can hook medipacks being picked up, but you can't hook the resupply cabinet being used, so I'm not sure how to do the latter (other than a continuous check). naris' code didn't do this either though did it?

@berni: It's not limited to TF2, the point is that TF2 doesn't send the damage done in the player_hurt event, like most other mods do. This stores their previous health so you can get the damage done.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 07-15-2008 at 18:17.
DJ Tsunami is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-15-2008 , 20:27   Re: [Snippet] TF2 Damage
Reply With Quote #5

You could hook the OnEndTouch output of func_regenerate. That might do it for you.
bl4nk is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-16-2008 , 16:02   Re: [Snippet] TF2 Damage
Reply With Quote #6

According to http://developer.valvesoftware.com/wiki/Func_regenerate (and Hammer for that matter) func_regenerate only has the OnUser1-4 outputs, that's the problem
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-16-2008 , 19:13   Re: [Snippet] TF2 Damage
Reply With Quote #7

I wouldn't trust the wiki pages too much. Looking at the datamaps, I see the following for func_regenerate:
Code:
- m_OnStartTouch (Save|Key|Output)(0 Bytes) - OnStartTouch
- m_OnStartTouchAll (Save|Key|Output)(0 Bytes) - OnStartTouchAll
- m_OnEndTouch (Save|Key|Output)(0 Bytes) - OnEndTouch
- m_OnEndTouchAll (Save|Key|Output)(0 Bytes) - OnEndTouchAll
- m_OnTouching (Save|Key|Output)(0 Bytes) - OnTouching
- m_OnNotTouching (Save|Key|Output)(0 Bytes) - OnNotTouching
bl4nk is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-17-2008 , 12:18   Re: [Snippet] TF2 Damage
Reply With Quote #8

Nope, none of those outputs, nor OnPlayerTouch (which works fine for healthkits), fire for func_regenerate.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-17-2008 , 13:36   Re: [Snippet] TF2 Damage
Reply With Quote #9

That's odd. Valve confuses me sometimes with why they leave stuff like that in there if it doesn't actually do anything.
bl4nk is offline
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Old 07-17-2008 , 18:23   Re: [Snippet] TF2 Damage
Reply With Quote #10

In this case, I imagine that the func_regenerate at one time was classed as a Trigger entity, which all share the same OnStartTouch/EndTouch/etc outputs, but at some point for some reason was changed strictly to a normal function brush entity. The Valve wiki actually is right more often than not, and in either case you can load up Hammer and see what Outputs the entity can fire from there.
__________________
msleeper is offline
Reply


Thread Tools
Display Modes

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 08:46.


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