Skip to content

Commit

Permalink
Fix errors related to switching class
Browse files Browse the repository at this point in the history
  • Loading branch information
FortyTwoFortyTwo committed Oct 28, 2023
1 parent 3019618 commit 62caa28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions scripting/randomizer.sp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ bool g_bWeaponDecap[MAXPLAYERS];
Handle g_hTimerClientHud[MAXPLAYERS];

bool g_bOnTakeDamage;
bool g_bOnTakeDamageClass;
int g_iGainingRageWeapon = INVALID_ENT_REFERENCE;
int g_iTouchItem = INVALID_ENT_REFERENCE;
int g_iTouchToucher = INVALID_ENT_REFERENCE;
Expand Down
11 changes: 7 additions & 4 deletions scripting/randomizer/dhook.sp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static int g_iDHookGamerulesPre;
static int g_iDHookGamerulesPost;

static bool g_bDoClassSpecialSkill[MAXPLAYERS];
static bool g_bDoClassSpecialSkillClass[MAXPLAYERS];
static bool g_bApplyBiteEffectsChocolate[MAXPLAYERS];

public void DHook_Init(GameData hGameData)
Expand Down Expand Up @@ -461,7 +462,7 @@ public MRESReturn DHook_DoClassSpecialSkillPre(int iClient, DHookReturn hReturn)
//If Engineer, pickup buildings
//If Spy, cloak or uncloak

g_bDoClassSpecialSkill[iClient] = false;
g_bDoClassSpecialSkill[iClient] = true; // To stop DHook_SecondaryWeaponPost from calling this again
int iActiveWeapon = GetEntPropEnt(iClient, Prop_Send, "m_hActiveWeapon");
if (iActiveWeapon == INVALID_ENT_REFERENCE)
return MRES_Ignored;
Expand All @@ -477,7 +478,7 @@ public MRESReturn DHook_DoClassSpecialSkillPre(int iClient, DHookReturn hReturn)
int iButton = Controls_GetPassiveButtonBit(iClient, iWeapon);
if (iButton > 0 && iButtons & iButton)
{
g_bDoClassSpecialSkill[iClient] = true;
g_bDoClassSpecialSkillClass[iClient] = true;
Controls_OnPassiveUse(iClient, iWeapon);
SetClientClass(iClient, TF2_GetDefaultClassFromItem(iWeapon));
return MRES_Ignored;
Expand All @@ -491,10 +492,12 @@ public MRESReturn DHook_DoClassSpecialSkillPre(int iClient, DHookReturn hReturn)

public MRESReturn DHook_DoClassSpecialSkillPost(int iClient, DHookReturn hReturn)
{
if (g_bDoClassSpecialSkill[iClient])
if (g_bDoClassSpecialSkillClass[iClient])
{
RevertClientClass(iClient);
g_bDoClassSpecialSkillClass[iClient] = false;
}

g_bDoClassSpecialSkill[iClient] = true; // To stop DHook_SecondaryWeaponPost from calling this again
return MRES_Ignored;
}

Expand Down
3 changes: 3 additions & 0 deletions scripting/randomizer/event.sp
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,8 @@ public void Event_WeaponJump(Event event, const char[] sName, bool bDontBroadcas
{
//Class check should be done by this point, revert class so pain sound can be played as actual class
if (g_bOnTakeDamage)
{
RevertClientClass(GetClientOfUserId(event.GetInt("userid")));
g_bOnTakeDamageClass = false;
}
}
9 changes: 7 additions & 2 deletions scripting/randomizer/sdkhook.sp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public Action Client_OnTakeDamage(int iVictim, int &iAttacker, int &iInflictor,
// IsPlayerClass not always called on linux,
// and some class checks don't even use IsPlayerClass.
SetClientClass(iAttacker, TF2_GetDefaultClassFromItem(iWeapon));
g_bOnTakeDamageClass = true;

Properties_LoadWeaponPropInt(iAttacker, iWeapon, "m_iDecapitations");
g_bWeaponDecap[iAttacker] = true;
Expand All @@ -83,12 +84,16 @@ public void Client_OnTakeDamagePost(int iVictim, int iAttacker, int iInflictor,
g_bOnTakeDamage = false;
g_bFeignDeath[iVictim] = false;

if (g_bOnTakeDamageClass)
{
RevertClientClass(iAttacker);
g_bOnTakeDamageClass = false;
}

if (0 < iAttacker <= MaxClients)
{
if (iWeapon != INVALID_ENT_REFERENCE && HasEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex"))
{
RevertClientClass(iAttacker);

Properties_SaveWeaponPropInt(iAttacker, iWeapon, "m_iDecapitations");
g_bWeaponDecap[iAttacker] = false;

Expand Down

0 comments on commit 62caa28

Please sign in to comment.