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

Get Damage in TF2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
naris
AlliedModders Donor
Join Date: Dec 2006
Old 12-31-2007 , 12:03   Get Damage in TF2
Reply With Quote #1

I have written a script to calculate the amount of damage in player_hurt for TF2 (since valve does not provide a it in the event).

To do this, I have to track the amout of health for all players and subtract the health in the player_hurt event form the previous health of the wounded client.

I placed the stocks in damage.inc and have provided an example test_damage.sp plugin that shows damage and weapon info in chat and logs it.

Oh, I also have stocks to detect gametype (cstrike, dod, tf2, etc...), health and maxhealth (for TF2).
Attached Files
File Type: inc damage.inc (1.3 KB, 511 views)
File Type: inc util.inc (1.8 KB, 454 views)
File Type: inc health.inc (1.8 KB, 459 views)
File Type: sp Get Plugin or Get Source (test_damage.sp - 516 views - 2.5 KB)

Last edited by naris; 12-31-2007 at 12:04. Reason: typo
naris is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 12-31-2007 , 14:31   Re: Get Damage in TF2
Reply With Quote #2

Awesome, this is just what I was looking for. Great job.

[edit]

http://forums.alliedmods.net/showthread.php?p=568684

Works like a charm, thanks.

Last edited by bl4nk; 12-31-2007 at 16:09.
bl4nk is offline
mtrxsol
Junior Member
Join Date: Jan 2008
Old 01-10-2008 , 08:02   Re: Get Damage in TF2
Reply With Quote #3

The events player_hurt & player_spawn are not visible in the modevents.res file in the resource folder.

I am building a stats module where I need to get such events. Can you tell me where can I get a listing of all the events in TF2 that I can hook.
mtrxsol is offline
ferret
SourceMod Developer
Join Date: Dec 2004
Location: Atlanta, GA
Old 01-10-2008 , 09:12   Re: Get Damage in TF2
Reply With Quote #4

Look in the hl2 folder. SourceMods have a search path. They first check the mod's folder (Ie, "tf", "cstrike"), then fall into the default hl2 folder. The HL2 folders also have a modevents.res, and its loaded as well.

If TF2's modevents.res doesn't have player_hurt, then it's coming from the hl2 copy of modevents.res
__________________
I'm a blast from the past!
ferret is offline
mtrxsol
Junior Member
Join Date: Jan 2008
Old 01-11-2008 , 05:23   Re: Get Damage in TF2
Reply With Quote #5

Quote:
Originally Posted by ferret View Post
Look in the hl2 folder. SourceMods have a search path. They first check the mod's folder (Ie, "tf", "cstrike"), then fall into the default hl2 folder. The HL2 folders also have a modevents.res, and its loaded as well.

If TF2's modevents.res doesn't have player_hurt, then it's coming from the hl2 copy of modevents.res
The events you are mentioning are there in gameevents.res file in hl2 dir. Still my plugin is unable to handle the events. The code is as follows, can you suggest me what's wrong with the code. The code is getting compiled well without any error.

Is there any other setting for hooking hl2 events anywhere in the game's config files.


HTML Code:
/* Plugin Template generated by Pawn Studio */

#include <sourcemod>

#define MAX_DATA 255

public Plugin:myinfo = 
{
    name = "Game Events",
    author = "mtrxsol",
    description = "<- Description ->",
    version = "1.0",
    url = "<- URL ->"
}

public OnPluginStart()
{
    LogMessage("Game Events Plugin Started");
    
    // Game events
    HookEvent("game_init",GameInitEvent);
    HookEvent("game_start",GameStartedEvent);
    HookEvent("round_start",RoundStartEvent);
    HookEvent("round_end",RoundEndEvent);
    HookEvent("game_end",GameEndEvent);
    
    // Player death event
    HookEvent("player_death",PlayerDeathEvent);
}

public GameInitEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    LogToGame("@MSG$1$Game Init@");
}

public GameStartedEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    new nRoundsLimit    = GetEventInt(event,"roundslimit");
    new nTimeLimit         = GetEventInt(event,"timelimit");
    new nFragLimit         = GetEventInt(event,"fraglimit");
    
    decl String:strObjective[MAX_DATA];
    decl String:strLogData[MAX_DATA];
    
    GetEventString(event,"objective",strObjective,sizeof(strObjective));
    
    Format(strLogData,sizeof(strLogData),"@MSG$2$Game Started$RoundsLimit = %d$TimeLimit = %d$FragLimit = %d$Objective = %s@",
        nRoundsLimit,nTimeLimit,nFragLimit,strObjective);
        
    LogToGame(strLogData);
}

public RoundStartEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    new nTimeLimit    = GetEventInt(event,"timelimit");
    new nFragLimit     = GetEventInt(event,"fraglimit");
    
    decl String:strObjective[MAX_DATA];
    decl String:strLogData[MAX_DATA];
    
    GetEventString(event,"objective",strObjective,sizeof(strObjective));
    
    Format(strLogData,sizeof(strLogData),"@MSG$3$Round Started$TimeLimit = %d$FragLimit = %d$Objective = %s@",
        nTimeLimit,nFragLimit,strObjective);
        
    LogToGame(strLogData);
}

public RoundEndEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    new nWinnerID    = GetEventInt(event,"winner");
    new nReason     = GetEventInt(event,"reason");
    
    decl String:strMessage[MAX_DATA];
    decl String:strLogData[MAX_DATA];
    
    GetEventString(event,"message",strMessage,sizeof(strMessage));
    
    Format(strLogData,sizeof(strLogData),"@MSG$4$Round End$WinnerID = %d$Reason = %d$Message = %s@",
        nWinnerID,nReason,strMessage);
        
    LogToGame(strLogData);
}

public GameEndEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    new nWinnerID = GetEventInt(event,"winner");
    LogToGame("@MSG$5$Game End$WinnerID = %d@",nWinnerID);
}

public PlayerDeathEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    decl String:strUserDied[MAX_NAME_LENGTH];
    decl String:strUserKilled[MAX_NAME_LENGTH];
    decl String:strUserAssisted[MAX_NAME_LENGTH];
    decl String:strLogData[MAX_DATA];
        
    // Id of the player who died
    new nUserDied     = GetEventInt(event,"userid");
    
    if( nUserDied != 0 )
    {
        GetClientName(GetClientUserId(nUserDied),strUserDied,sizeof(strUserDied));
    }
    
    // Id of the player who killed
    new nUserKilled = GetEventInt(event,"attacker");
    
    if( nUserKilled != 0 )
    {
        GetClientName(GetClientUserId(nUserKilled),strUserKilled,sizeof(strUserKilled));
    }
    
    // Weapon name used to kill
    decl String:strWeapon[MAX_DATA];
    GetEventString(event,"weapon",strWeapon,sizeof(strWeapon));    
    
    // Damage bits
    new nDamageBits = GetEventInt(event,"damagebits");
    
    // Type of custom kill
    new nCustomKillType = GetEventInt(event,"customkill");
    
    // Id of the player who assisted
    new nUserAssisted = GetEventInt(event,"assister");
    
    if( nUserAssisted != 0 )
    {
        GetClientName(GetClientUserId(nUserAssisted),strUserAssisted,sizeof(strUserAssisted));
    }
    
    // Did killer dominate victim with this kill
    new nKillerDominated = GetEventInt(event,"dominated");
    
    // Did assister dominate victim with this kill
    new nAssisterDominated = GetEventInt(event,"assister_dominated");
    
    // Did killer get revenge on victim with this kill
    new nKillerRevenge = GetEventInt(event,"revenge");
    
    // Did assister get revenge on victim with this kill
    new nAssisterRevenge = GetEventInt(event,"assister_revenge");
    
    // TODO: Log message to c# engine
    Format(strLogData,sizeof(strLogData),"@MSG$2$Died=%s$Killer=%s$Assister=%s$Weapon=%s$KillerDominated=%d$AssisterDominated=%d$KillerRevenge=%d$AssisterRevenge=%d",
        strUserDied,
        strUserKilled,
        strUserAssisted,
        strWeapon,
        nKillerDominated,
        nAssisterDominated,
        nKillerRevenge,
        nAssisterRevenge);
    LogToGame(strLogData);
}
mtrxsol is offline
ferret
SourceMod Developer
Join Date: Dec 2004
Location: Atlanta, GA
Old 01-11-2008 , 10:34   Re: Get Damage in TF2
Reply With Quote #6

Well, I should be more specific. Often events are carried over from the hl2 list, but they aren't always implemented. For example, team_score is an HL2 event... but CSS doesn't ever call it.

If you hook it, and its not called, then you're out of luck.. The game simply doesn't use it.

TF2 has a ton of custom events related to round start, round end, game modes, etc.
__________________
I'm a blast from the past!
ferret is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 01-11-2008 , 19:41   Re: Get Damage in TF2
Reply With Quote #7

Quote:
Originally Posted by mtrxsol View Post
The events player_hurt & player_spawn are not visible in the modevents.res file in the resource folder.

I am building a stats module where I need to get such events. Can you tell me where can I get a listing of all the events in TF2 that I can hook.
TF2 does indeed call the player_hurt & player_spawn events and you can hook them in the normal way. The event data is the same as for the HL2 event.

You will need to the use the TF2 specific events listed in modevents.res for the round stuff. TF2 has several different "rounf" types, each with it's own events.

use "teamplay_round_start" instead of "round_start"
use "teamplay_round_stalemate" and "teamplay_round_win" instead of "round_end" (a round is either won or it's a stalemate).

Try "teamplay_game_over" or "tf_game_over" instead of "game_end"

I don't have any suggestions for "game_init" and "game_start"...

What other events are you looking to hook?
naris is offline
mtrxsol
Junior Member
Join Date: Jan 2008
Old 01-14-2008 , 01:51   Re: Get Damage in TF2
Reply With Quote #8

Thank you naris & ferret for your valuable help. I am on my way to hook these events now. I am also thinking of a module which will help in collecting the match stats.
mtrxsol is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 01-28-2008 , 12:43   Re: Get Damage in TF2
Reply With Quote #9

The include files have been working great, naris, but so far I've only ran into one problem. Your SaveAllHealth() stock (in damage.inc) checks to see if a player is Connected, and then checks to see if they're Alive. It completely skips checking to see if they're actually in-game yet. To remedy this, I made a temporary function of my own:

PHP Code:
SaveAllHealth2()
{
    new 
clients GetClientCount();
    for (new 
1<= clientsi++)
    {
        if (
IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i))
            
savedHealth[i] = GetClientHealth(i);
    }

bl4nk 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 15:49.


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