Skip to content

Commit

Permalink
update PackageScript, clean up checking hitgroup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearsilo583 committed May 13, 2024
1 parent 2a15c13 commit 1d14e44
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 34 deletions.
1 change: 1 addition & 0 deletions PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ builder.AddCopy(os.path.join(builder.sourcePath, 'cfg', MMSPlugin.plugin_name, '
builder.AddCopy(os.path.join(builder.sourcePath, 'cfg', MMSPlugin.plugin_name, 'maps', 'de_somemap.cfg'), mapcfg_folder)
builder.AddCopy(os.path.join(builder.sourcePath, 'configs', 'zr', 'playerclass.jsonc.example'), zr_folder)
builder.AddCopy(os.path.join(builder.sourcePath, 'configs', 'zr', 'weapons.cfg.example'), zr_folder)
builder.AddCopy(os.path.join(builder.sourcePath, 'configs', 'zr', 'hitgroups.cfg.example'), zr_folder)
builder.AddCopy(os.path.join('gamedata', 'cs2fixes.games.txt'), gamedata_folder)

# Add CS2Fixes-specific compiled asset files
Expand Down
130 changes: 130 additions & 0 deletions configs/zr/hitgroups.cfg.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// SHORT DESCRIPTIONS
//
// Attribute: Values: Description:
// ----------------------------------------------------------------------------
// index number The hitgroup index.
// enabled 1/0 If enabled. The knockback will apply multiplier from knockback config.
// knockback decimal The knockback multiplier for this hitgroup.

"Hitgroups"
{
"Generic"
{
// enabled
"enabled" "1"

// General
"index" "0"

// Knockback
"knockback" "1.0"
}

"Head"
{
// enabled
"enabled" "1"

// General
"index" "1"

// Knockback
"knockback" "1.0"
}

"Chest"
{
// enabled
"enabled" "1"

// General
"index" "2"

// Knockback
"knockback" "1.0"
}

"Stomach"
{
// enabled
"enabled" "1"

// General
"index" "3"

// Knockback
"knockback" "1.0"
}

"LeftArm"
{
// enabled
"enabled" "1"

// General
"index" "4"

// Knockback
"knockback" "1.0"
}

"RightArm"
{
// enabled
"enabled" "1"

// General
"index" "5"

// Knockback
"knockback" "1.0"
}

"LeftLeg"
{
// enabled
"enabled" "1"

// General
"index" "6"

// Knockback
"knockback" "1.0"
}

"RightLeg"
{
// enabled
"enabled" "1"

// General
"index" "7"

// Knockback
"knockback" "1.0"
}

"Neck"
{
// enabled
"enabled" "1"

// General
"index" "8"

// Knockback
"knockback" "1.0"
}

"Gear"
{
// enabled
"enabled" "1"

// General
"index" "10"

// Knockback
"knockback" "1.0"
}
}
46 changes: 14 additions & 32 deletions src/zombiereborn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,49 +949,38 @@ void ZRHitgroupConfig::LoadHitgroupConfig()
{
const char *pszHitgroupName = pKey->GetName();
bool bEnabled = pKey->GetBool("enabled", false);
const char *sIndex = pKey->GetString("index", "0");
int iIndex = pKey->GetInt("index");
float flKnockback= pKey->GetFloat("knockback", .2f);

ZRHitgroup *hitgroup = new ZRHitgroup;
//if (!bEnabled)
// continue;
if (!bEnabled)
continue;

//hitgroup->sIndex = sIndex;
hitgroup->flKnockback = flKnockback;

m_HitgroupMap.Insert(hash_32_fnv1a_const(sIndex), hitgroup);
m_HitgroupMap.Insert(iIndex, hitgroup);

Message("Hitgroup: %s with index: %s and knockback: %f and hash_32_fnv1a_const: %d\n", pszHitgroupName, sIndex, hitgroup->flKnockback, hash_32_fnv1a_const(sIndex));

Message("Hitgroup: %s with index: %d and knockback: %f and enable: %d and ?: %d\n", pszHitgroupName, iIndex, hitgroup->flKnockback, bEnabled,
m_HitgroupMap[iIndex]);
}

return;
}

ZRHitgroup* ZRHitgroupConfig::FindHitgroupIndex(const char *pszHitgroupName)
ZRHitgroup* ZRHitgroupConfig::FindHitgroupIndex(int iIndex)
{
uint16 index = m_HitgroupMap.Find(hash_32_fnv1a_const(pszHitgroupName));
Message("We are finding hitgroup index with pszHitgroupName: %s and index is: %d\n", pszHitgroupName, index);
uint16 index = m_HitgroupMap.Find(iIndex);
//Message("We are finding hitgroup index with index: %d and index is: %d\n", iIndex, index);

if (m_HitgroupMap.IsValidIndex(index))
{
Message("We found valid index with dunno what to call (m_HitgroupMap[index]): %d\n", m_HitgroupMap[index]);
//Message("We found valid index with (m_HitgroupMap[index]): %d\n", m_HitgroupMap[index]);
return m_HitgroupMap[index];
}

return nullptr;
}

/*
ZRHitgroup* ZRHitgroupConfig::FindHitgroupIndex(int iIndex)
{
uint16 index = m_HitgroupMap.Find(iIndex);
if (m_HitgroupMap.IsValidIndex(index))
return m_HitgroupMap[index];
return 0;
}*/

void ZR_RespawnAll()
{
for (int i = 0; i < gpGlobals->maxClients; i++)
Expand Down Expand Up @@ -1127,7 +1116,7 @@ void ZR_OnPlayerSpawn(IGameEvent* pEvent)
});
}

void ZR_ApplyKnockback(CCSPlayerPawn *pHuman, CCSPlayerPawn *pVictim, int iDamage, const char *szWeapon, const char *hitgroup)
void ZR_ApplyKnockback(CCSPlayerPawn *pHuman, CCSPlayerPawn *pVictim, int iDamage, const char *szWeapon, int hitgroup)
{
ZRWeapon *pWeapon = g_pZRWeaponConfig->FindWeapon(szWeapon);
ZRHitgroup *pHitgroup = g_pZRHitgroupConfig->FindHitgroupIndex(hitgroup);
Expand All @@ -1137,14 +1126,12 @@ void ZR_ApplyKnockback(CCSPlayerPawn *pHuman, CCSPlayerPawn *pVictim, int iDamag
float flWeaponKnockbackScale = pWeapon->flKnockback;
float flHitgroupKnockbackScale;

if(pHitgroup != nullptr)
if(pHitgroup)
{
Message("We are setting knockback hg scale with kb scale is: %.2f and wp kb scale: %.2f\n", pHitgroup->flKnockback, pWeapon->flKnockback);
flHitgroupKnockbackScale = pHitgroup->flKnockback;
}
else flHitgroupKnockbackScale = 1.0;

Message("We are hitting hitgroup: %s and found hit group index: %d with kb scale: %.2f\n", hitgroup, pHitgroup, flHitgroupKnockbackScale);

Vector vecKnockback;
AngleVectors(pHuman->m_angEyeAngles(), &vecKnockback);
vecKnockback *= (iDamage * g_flKnockbackScale * flWeaponKnockbackScale * flHitgroupKnockbackScale);
Expand Down Expand Up @@ -1643,17 +1630,12 @@ void ZR_OnPlayerHurt(IGameEvent* pEvent)

int iHitGroup = pEvent->GetInt("hitgroup");

std::string hg = std::to_string(iHitGroup);
const char* myCharPointer = hg.c_str();

Message("My HG: %s and myCharPointer: %s\n", hg, myCharPointer);

// grenade and molotov knockbacks are handled by TakeDamage detours
if (!pAttackerController || !pVictimController || !V_strncmp(szWeapon, "inferno", 7) || !V_strncmp(szWeapon, "hegrenade", 9))
return;

if (pAttackerController->m_iTeamNum() == CS_TEAM_CT && pVictimController->m_iTeamNum() == CS_TEAM_T)
ZR_ApplyKnockback((CCSPlayerPawn*)pAttackerController->GetPawn(), (CCSPlayerPawn*)pVictimController->GetPawn(), iDmgHealth, szWeapon, myCharPointer);
ZR_ApplyKnockback((CCSPlayerPawn*)pAttackerController->GetPawn(), (CCSPlayerPawn*)pVictimController->GetPawn(), iDmgHealth, szWeapon, iHitGroup);
}

void ZR_OnPlayerDeath(IGameEvent* pEvent)
Expand Down
3 changes: 1 addition & 2 deletions src/zombiereborn.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ struct ZRWeapon

struct ZRHitgroup
{
//const char *sIndex;
float flKnockback;
};

Expand All @@ -269,7 +268,7 @@ class ZRHitgroupConfig
m_HitgroupMap.SetLessFunc(DefLessFunc(uint32));
};
void LoadHitgroupConfig();
ZRHitgroup* FindHitgroupIndex(const char *pszHitgroupname);
ZRHitgroup* FindHitgroupIndex(int iIndex);
private:
CUtlMap<uint32, ZRHitgroup*> m_HitgroupMap;
};
Expand Down

0 comments on commit 1d14e44

Please sign in to comment.