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

[TF2] Can you turn a regular hit into a crit?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ratty
SourceMod Donor
Join Date: Jan 2006
Old 07-01-2010 , 07:18   [TF2] Can you turn a regular hit into a crit?
Reply With Quote #1

I'm trying to make a plugin that will change a kill into a crit, can it be done in a player_death hook?

I think its in damagebits variable, but I can't find any doc on it on the developer.valvesoftware.com wiki or wiki.alliedmods.net, is there a list of them for TF2?

I made a plugin to print the damagebits, and it did change when I got a crit, so I'm hopeful I found it.
However, SetEventInt won't work on it, I get an error, type mismatch, maybe because its a long and not an int?
__________________
Visit the NOM NOM NOM community
http://www.nom-nom-nom.us
ratty is offline
CarlZalph
Junior Member
Join Date: May 2010
Old 07-01-2010 , 12:03   Re: [TF2] Can you turn a regular hit into a crit?
Reply With Quote #2

Hey, Kilorat.

Not sure why it'd give you an error/warning about it.
Perhaps posting a snippet of all the associated variables?
I know it'll complain if you use a float when expecting an int.

As for getting the event's deathbits, here's something that'll get you those:
Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>
#pragma semicolon 1
#define PL_VERSION "1.0.0"
public Plugin:myinfo = 
{
    name = "Deathbits",
    author = "CarlZalph",
    description = "N/A",
    version = PL_VERSION,
    url = "N/A"
}
public OnPluginStart()
{
    HookEvent("player_death ", hookPlayerDeath);
}
public OnPluginEnd()
{
    UnhookEvent("player_spawn", hookPlayerDeath);
}
public hookPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    new bits = GetEventInt(event, "damagebits");
    //Alter bits here
    SetEventInt(event, "damagebits", bits);
    PrintToChatAll("(%i)_%i",client,bits);
}
If you want to manipulate crits in general, you'd mess around with:
Code:
public Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bool:result)
{
    result = true;  //100% crits
    result = false;  //0% crits
    return Plugin_Handled;  //Stop TF2 from doing anything about it
    return Plugin_Continue;  //Allow TF2 to continue on random crit rate
}
The list of events for TF2 can be found: Here
CarlZalph is offline
ratty
SourceMod Donor
Join Date: Jan 2006
Old 07-01-2010 , 15:12   Re: [TF2] Can you turn a regular hit into a crit?
Reply With Quote #3

Heya, thanks for the help.

One thing I cant find is what all the deathbits are.

What I'm trying to do is fix a bug in TF2, if you set tf_weapon_criticals to 0, and if a spy gets a backstab, you don't get the backstab animation, since it is tied to crits. In the model, the animation sequence even says crit.
So I suppose that might be impossible, if the only time you can manipulate crits is when you are shooting.

I see what I did wrong in the SetEventInt, I totally mangled the use of it. I got that to compile now, and I see it changes the event, but the kill message doesn't change to "player killed player with knife (crit)". I figured at least the kill message might get the crit flag, even if it doesn't make a real crit.
I checked death_flags, but that did not seem to change when I turned crits on.
__________________
Visit the NOM NOM NOM community
http://www.nom-nom-nom.us

Last edited by ratty; 07-01-2010 at 15:20.
ratty is offline
CarlZalph
Junior Member
Join Date: May 2010
Old 07-01-2010 , 15:47   Re: [TF2] Can you turn a regular hit into a crit?
Reply With Quote #4

Yeah, I don't think that it'd be feasibly possible with Sourcemod alone.

All animation states are client-sided.
Thus, any crit edits you do after the fact of attack won't play.

Now you could allow crits, then use the calculated crit rate and return plugin_continue for only knife and false with plugin_handled for any other weapon.

There's a drawback, though.
All client-sided predicted crits will show up as crits on their screen.
When the server sees none of that.

For instance, a heavy with predicted crits will see the crit bullets, while not getting crit hits.


I'd fear that would actually be worse than not having a backstab animation.
If anything, you should definitely file a bug report to Valve.


The code to do the knife thing with drawbacks:
Code:
public Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bool:result)
{
    if(StrEqual(weaponname, "tf_weapon_knife"))
    {
        return Plugin_Continue;  //Normal crits for knife only
    }
    result = false;  //0% crits for all other weapons
    return Plugin_Handled;  //Stop TF2 from doing anything about it
}

Okay, this is going on a HUGE stretch!


Looking back at the events, you *might* be able to hook an event with a Prethink hook to edit the event then send it to the client.
"player_hurt" event has the 'weaponid' entity index, and 'crit' to determine if it were a crit.

You can get the type of weapon from the index with:
Code:
decl String:WeaponTitle[128];  //Never know what Valve will name future weapons, best keep it big.
    GetEdictClassname(WeaponEntityIndexNumber, WeaponTitle, sizeof(WeaponTitle));
And force the event's 'crit' field to be a 1 if the TF2_CalcIsAttackCritical returns true on the knife.
Then force all other weapons 'crit' field to be a 0 regardless of the Calculated crit.

Last edited by CarlZalph; 07-01-2010 at 15:52.
CarlZalph is offline
ratty
SourceMod Donor
Join Date: Jan 2006
Old 07-01-2010 , 20:23   Re: [TF2] Can you turn a regular hit into a crit?
Reply With Quote #5

Wow this is sounding really nasty!

Another problem, it would have to turn on crits for backstab only, or we'll bring new meaning to "face stab". I only know how to detect backstabsin the context of player_death, so that's kind of a show stopper.

I used to have "tf_weapon_criticals 1" for years, and had a plugin turn off crits, so that spy backstabs would look ok, and everyone just got used to the false crit effects you'd sometimes get, at least you never falsely see the little "critical hit" text above the target if its not a real crit. One problem pointed out to me recently is this blocks demoman charge n targe from getting the short crit right after you charge. I was unable to resolve that one either, if I checked for the m_nPlayerCond that gets set when you're charging, as soon as you attack, that flag goes away, so I could not check it in TF2_CalcIsAttackCritical. I fell back to just tf_weapon_criticals 0, and the only problem with that is spy backstabs, compared to the short list of problems in having a plugin manage when to crit.

So the best position I've come up with so far is just to simply do this in a player_death hook:

decl String:weapon[64];
GetEventString(event, "weapon", weapon, sizeof(weapon));
new client = GetClientOfUserId(GetEventInt(event, "attacker"));
new customkill = GetEventInt(event, "customkill");
if(StrEqual(weapon, "knife")) {
if(customkill==2) EmitSoundToClient(client,"player/crit_hit.wav");

(for some reason, it actually comes out as "knife" and not tf_weapon_knife, not sure why)

So I have it just play the crit sound to the attacker if they get a backstab, so as a spy you can get that immediate feedback that you connected a backstab. Some would argue you can just roll your eyes to the corner of the screen to see, but in the heat of the moment I appreciate that audio feedback that I didn't failstab.

Ideally I'd like to make it a real crit so you can see the proper animation, but this is the best solution I could think of.

I got what I needed though, I was trying to see if there was just some straightforward way to induce crits with tf_weapon_criticals off and it doesn't seem like it is possible.

Thanks for the help!
__________________
Visit the NOM NOM NOM community
http://www.nom-nom-nom.us
ratty is offline
CarlZalph
Junior Member
Join Date: May 2010
Old 07-01-2010 , 22:22   Re: [TF2] Can you turn a regular hit into a crit?
Reply With Quote #6

Fixing a client-sided bug with a server modification isn't going to a cake-walk, unfortunately.

The knife would be allowed to crit through the Plugin_Continue with no alteration to the *result pointer.
If you look back at the post, the knife entity doesn't get affected by the detour, so you wouldn't get face-crits.

Yeah, I'm not too familiar with that charge code-wise to help that part out, unfortunately.

"knife" and not "tf_weapon_knife"?
Valve must have changed something in my absence..
Either the event feedback or the entity name itself.

A sound is definitely always good to know for good stabs.
You're right about that top-right thing.
Most of the time I don't even look at the thing since it's so far out of my way.

Just don't forget to file a bug report!
Valve does have some people look at the box on occasion.

I might just go to that server once I get a new computer, Kilo.
Have fun!
CarlZalph is offline
psychonic

BAFFLED
Join Date: May 2008
Old 07-01-2010 , 23:25   Re: [TF2] Can you turn a regular hit into a crit?
Reply With Quote #7

Quote:
Originally Posted by ratty View Post
One thing I cant find is what all the deathbits are.
FYI, the damage flags (used in damagebits) can be found in sdkhooks.inc, dukehacks.inc or in the SDK in takedamageinfo.h. (They should all match except crit is DMG_ACID and many are unused). Death flags (death_flags) are in include/tf2_stocks.inc
psychonic is offline
DarthNinja
SourceMod Plugin Approver
Join Date: Mar 2009
Location: PreThinkHook()
Old 07-03-2010 , 14:24   Re: [TF2] Can you turn a regular hit into a crit?
Reply With Quote #8

Have you tried sending a fake cvar of "tf_weapon_criticals 1" to spies?
Not sure if that would work or if it would have any other effects.
__________________
DarthNinja 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 16:39.


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