Predicting CTakeDamageInfo on client?

The library is shared, and yet all the functions that use it seem to be exclusively server side. I found a way to predict fall damage, but it’s a bit hacky. Is there any way I could somehow intercept the creation of new DamageInfo() objects and get the data from there?

I’m stumped. :confused:

I found one shared hook: **[Gamemode.PlayerTraceAttack](**, but it only works when a player does some kind of trace attack (duh), so this won’t work when something like a physics object hurts a player. I even tried hooking to **[Gamemode.AddDeathNotice](**, but that didn’t even work.

Hmm well what’s wrong with letting the server tell clients they received damage? You can’t exactly tell the client he’s going to take damage before he actually does serverside…

Yeah, but I’m just trying to use all the Get methods of it on the client. If doing it on the server was an option for me, I wouldn’t have this issue in the first place.


What I don’t understand is why hooking to AddDeathNotice/DrawDeathNotice doesn’t work. They’re both client side gamemode functions.

If hooking fails, make sure it is actually called in the gamemode. If it is, override the gamemode function and call the old gamemode function after doing what you need to do.

I tried that and both GAMEMODE and gmod.GetGamemode() failed for overriding the function.


It seems that the Gamemode object is nil when my script is being loaded. :wtf:

Hook it in a PostGamemodeLoaded hook.

Didn’t work. :frown:

I’m testing in sandbox, so I can’t imagine why it’s not working.

What isn’t working? AddDeathNotice? I’m pretty sure that’s a function, not a hook.


So what you want to do is determine clientside if a client should die from fall damage or not?

You’re right. I just used hooks.GetTable() and realized it will add whatever you put in hook.Add regardless of whether it exists or not. That probably is what threw me off.

Hmm well if that’s what you’re looking for you probably caught on to that already, but maybe you could hook to the x Killed y usermessages detailed in cl_deathnotice.lua?

Or you could manually hook to it:
[lua]local GAMEMODEAddDeathNotice = GAMEMODE.AddDeathNotice
function GAMEMODE:AddDeathNotice(Victim, team1, Inflictor, Attacker, team2)
– Blah.
GAMEMODEAddDeathNotice(Victim, team1, Inflictor, Attacker, team2)


Of course that would be equivalent to receiving the information from the server, but isn’t it impossible to do otherwise unless you do all of the prediction work yourself?

That’s the function I’m using right now. Only problem is that it won’t work if it’s not called in the gamemode.

It should work in any gamemode as long as you don’t overwrite PlayerDeath and OnNPCKilled.

Those are both serverside so it doesn’t matter. What I meant was that not all gamemodes call the AddDeathNotice function. Most do, but there’s always the remote possibility of one not calling it.

If they don’t they most likely are still sending the usermessages. They could completely override the previously mentionned serverside hooks but it’s very unlikely and as long as they don’t you can hook to the usermessages.

Hooking to usermessages is a cool idea, but there’s could still be extra hooks they use in a custom gamemode. This method isn’t ideal in the first place since it doesn’t give me any damage info, just names.

You could always use gm_sourcenet. Messy, but I think message 16 in ProcessUserMessage is deaths. Just experiment with it.

Do you only need information about damage applied to you, or every other client as well?

It would be ideal to have the damageinfo of all players whenever they’re hurt, but having it for the client is nice too.