AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Snippet] TF2 Damage (https://forums.alliedmods.net/showthread.php?t=74270)

DJ Tsunami 07-15-2008 10:53

[Snippet] TF2 Damage
 
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 :P 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); }

bl4nk 07-15-2008 14:19

Re: [Snippet] TF2 Damage
 
What about when players pick up med packs or use a resupply cabinet?

berni 07-15-2008 15:55

Re: [Snippet] TF2 Damage
 
And why should this be limited to TF2 only ? player_hurt and player_spawn are available in all games afaik.

DJ Tsunami 07-15-2008 18:10

Re: [Snippet] TF2 Damage
 
@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.

bl4nk 07-15-2008 20:27

Re: [Snippet] TF2 Damage
 
You could hook the OnEndTouch output of func_regenerate. That might do it for you.

DJ Tsunami 07-16-2008 16:02

Re: [Snippet] TF2 Damage
 
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 :(

bl4nk 07-16-2008 19:13

Re: [Snippet] TF2 Damage
 
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


DJ Tsunami 07-17-2008 12:18

Re: [Snippet] TF2 Damage
 
Nope, none of those outputs, nor OnPlayerTouch (which works fine for healthkits), fire for func_regenerate.

bl4nk 07-17-2008 13:36

Re: [Snippet] TF2 Damage
 
That's odd. Valve confuses me sometimes with why they leave stuff like that in there if it doesn't actually do anything.

msleeper 07-17-2008 18:23

Re: [Snippet] TF2 Damage
 
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.

DJ Tsunami 07-18-2008 18:19

Re: [Snippet] TF2 Damage
 
Well, LDuke indirectly gave me the idea of hooking OnAnimationBegun on the resupply locker's model. This unfortunately doesn't send who touched the locker, so I'm forced to loop through all the clients and save their health. Not perfect, but it works. The new code is in the first post. I'm still interested though if anyone knows of a better way to do the lockers. LDuke is also looking for a way, and he needs to know who touched the locker.

MikeJS 02-05-2009 16:06

Re: [Snippet] TF2 Damage
 
This wasn't working if the player was a medic (regen) or they were healed by a dispenser so I updated it.
PHP Code:

#include <sourcemod>
#include <sdktools>
#include <tf2_stocks>
new g_iHealth[MAXPLAYERS+1];
new 
g_condOffset;
public 
OnPluginStart() {
    
g_condOffset FindSendPropInfo("CTFPlayer""m_nPlayerCond");
    
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 
OnGameFrame() {
    for(new 
i=1;i<=MaxClients;i++) {
        if(
IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i)>1) {
            new 
cond GetEntData(ig_condOffset);
            if(
cond 8192 || cond 32768 || TF2_GetPlayerClass(i)==TFClass_Medic) {
                
g_iHealth[i] = GetClientHealth(i);
            }
        }
    }
}
public 
EntityOutput_SaveHealth(const String:output[],    calleractivatorFloat:delay) {
    
g_iHealth[activator] = GetClientHealth(activator);
}
public 
EntityOutput_SaveHealthAll(const String:output[], calleractivatorFloat:delay) {
    for(new 
i=1;i<=MaxClients;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"));
    new 
iHealth GetEventInt(event"health");
    
PrintToChatAll("Damage: %i"g_iHealth[iClient]-iHealth);
    
g_iHealth[iClient] = iHealth;
}
public 
Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
    
CreateTimer(0.01Timer_SaveHealthGetClientOfUserId(GetEventInt(event"userid")));
}
public 
Action:Timer_SaveHealth(Handle:timerany:client) {
    
g_iHealth[client] = GetClientHealth(client);



DJ Tsunami 02-14-2009 06:05

Re: [Snippet] TF2 Damage
 
Ouch, OnGameFrame :( That kind of defeats the whole purpose of hooking those events and outputs, you could just save their health every frame and be done. It would just be way more expensive.

MikeJS 02-14-2009 07:45

Re: [Snippet] TF2 Damage
 
It would probably be faster to just get everyone's health in OnGameFrame than what I do now :|

DJ Tsunami 02-14-2009 18:13

Re: [Snippet] TF2 Damage
 
I do appreciate you trying to fix it though, just like I forgot about healthpacks and the lockers in the first version, I didn't think about the medic and dispenser either :/

MikeJS 05-14-2009 10:09

Re: [Snippet] TF2 Damage
 
5 Attachment(s)
With the help of Fyren, I made a plugin that allows other plugins to get damage dealt by an attack.

CrancK 05-22-2009 05:20

Re: [Snippet] TF2 Damage
 
nvm, been said before... stupid me 0.o


All times are GMT -4. The time now is 18:12.

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