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

How to detect a random crit?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 09-22-2018 , 08:33   How to detect a random crit?
Reply With Quote #1

Hello. I need a way to detect when someone does a random crit. but I don't want my plugin to detect forced crits like uber, frontier justice , diamondback , and this like that.
Is it possible to only trigger a function when it is a true random crit?
lugui is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-22-2018 , 09:43   Re: How to detect a random crit?
Reply With Quote #2

It's handled at the end of CTFWeaponBaseMelee::CalcIsAttackCriticalHelper(), specifically in the non-virtual function CBaseCombatWeapon::IsAllowedToWithdrawFromCritBucket(float). See this post for a partially disassembly of a previously bugged version.

As long as all you need to do is only check for the presence of random crits, you should be able to detour that and check that the return value is true.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 09-22-2018 at 21:54.
nosoop is offline
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 09-22-2018 , 10:05   Re: How to detect a random crit?
Reply With Quote #3

nosoop, I think that I did not understand you.
How can I hook it in sourcemod? Could I have a example?
Thx.
lugui is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-22-2018 , 10:18   Re: How to detect a random crit?
Reply With Quote #4

You'll need DHooks with dynamic detour support. The gist of it is that you'll create a detour on CBaseCombatWeapon::IsAllowedToWithdrawFromCritBucket() and check that it returns true.

Untested code:

Code:
{
    hWithdrawFromCritBucket = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Bool, ThisPointer_CBaseEntity);
    DHookSetFromConf(hWithdrawFromCritBucket, hGameData, SDKConf_Signature, "CBaseCombatWeapon::IsAllowedToWithdrawFromCritBucket()");
    DHookAddParam(hWithdrawFromCritBucket, HookParamType_Float);

    DHookEnableDetour(hWithdrawFromCritBucket, true, OnWithdrawFromCritBucketPost);
}

public MRESReturn OnWithdrawFromCritBucketPost(int weapon, Handle hReturn, Handle hParams) {
    bool bIsCritical = DHookGetReturn(hReturn);
    if (bIsCritical) {
        // is a random crit
    }
    return MRES_Ignored;
}
You'll need gamedata for this; that's left as an exercise for you.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 09-22-2018 at 10:27.
nosoop is offline
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 09-22-2018 , 10:30   Re: How to detect a random crit?
Reply With Quote #5

Thanks. I'll check it out.
Is there a way to do it only in sourcemod without the need to install any other extensions on the server?
lugui is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-22-2018 , 12:27   Re: How to detect a random crit?
Reply With Quote #6

There is not.

TF2_CalcIsAttackCritical() exists, but it also returns true when the player is crit boosted.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 09-22-2018 at 13:00.
nosoop 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:06.


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