Skip to content

Commit 8c12761

Browse files
committed
Fix damage event for grenades
1 parent f496a0c commit 8c12761

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

amxmodx/scripting/CWAPI-A-Test.sma

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public CWAPI_OnLoad() {
9696
new iTestInteger = 0;
9797
TrieGetCell(tAbilityParams, "TestInteger", iTestInteger);
9898

99-
PrintMessage(iWeapon, ItemId, "@OnDamage(%d, %d, %d, %d, %d, %.2f, %d, %d): %d", iWeapon, ItemId, VictimId, InflictorId, AttackerId, fDamage, iDamageBits, tAbilityParams, iTestInteger);
99+
PrintMessage(iWeapon, AttackerId, "@OnDamage(%d, %d, %d, %d, %d, %.2f, %d, %d): %d", iWeapon, ItemId, VictimId, InflictorId, AttackerId, fDamage, iDamageBits, tAbilityParams, iTestInteger);
100100
}
101101

102102
@OnReload(const T_CustomWeapon:iWeapon, const ItemId, &iClipSize, &iAnim, &Float:fDelay, const Trie:tAbilityParams) {
@@ -135,8 +135,15 @@ public CWAPI_OnLoad() {
135135
}
136136

137137

138-
PrintMessage(const T_CustomWeapon:iWeapon, const ItemId, const sMsg[], const any:...) {
139-
new UserId = get_member(ItemId, m_pPlayer);
138+
PrintMessage(const T_CustomWeapon:iWeapon, const fromIndex, const sMsg[], const any:...) {
139+
new UserId = 0;
140+
if (!is_nullent(fromIndex)) {
141+
if (FClassnameIs(fromIndex, "player")) {
142+
UserId = fromIndex;
143+
} else {
144+
UserId = get_member(fromIndex, m_pPlayer);
145+
}
146+
}
140147

141148
new sFmtMsg[256];
142149
vformat(sFmtMsg, charsmax(sFmtMsg), sMsg, 4);

amxmodx/scripting/Cwapi/Core/CWeapons/Hooks.inc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ public Hook_PlayerThrowGrenade_Post(const playerIndex, const grenadeItemIndex, F
132132
if (!CWeapons_GetByItem(grenadeItemIndex, weaponObject, weaponIndex)) {
133133
return HC_CONTINUE;
134134
}
135-
136-
set_entvar(grenadeItemIndex, var_impulse, CWeapons_GetImpulse(weaponIndex));
135+
136+
new grenadeEntityIndex = GetHookChainReturn(ATYPE_INTEGER);
137+
set_entvar(grenadeEntityIndex, var_impulse, CWeapons_GetImpulse(weaponIndex));
138+
139+
Dbg_Log("Hook_PlayerThrowGrenade_Post(%n, %d): grenadeEntityIndex = %d.", playerIndex, grenadeItemIndex, grenadeEntityIndex);
140+
Dbg_Log("Hook_PlayerThrowGrenade_Post(%n, %d): Set impulse = %d (%d).", playerIndex, grenadeItemIndex, CWeapons_GetImpulse(weaponIndex), weaponIndex);
137141

138142
return HC_CONTINUE;
139143
}
@@ -339,26 +343,32 @@ public Hook_PlayerTakeDamage_Post(const VictimId, InflictorId, AttackerId, Float
339343
return HC_CONTINUE;
340344
}
341345

346+
Dbg_Log("Hook_PlayerTakeDamage_Post(%d, %d, %d, %.2f, %d)", VictimId, InflictorId, AttackerId, fDamage, iDamageBits);
347+
342348
new itemIndex = 0;
343349
if (FClassnameIs(InflictorId, "player")) {
344350
itemIndex = get_member(InflictorId, m_pActiveItem);
345351
}
352+
Dbg_Log(" itemIndex = %d", itemIndex);
346353

347354
/**
348355
* Для ножа почему-то вызывается хук дамага для тиммейтов,
349356
* хотя по факту урон не наносится.
350357
*/
351358
if (
352-
IsKnife(itemIndex)
359+
(is_nullent(itemIndex) || IsKnife(itemIndex))
353360
&& !rg_is_player_can_takedamage(VictimId, AttackerId)
354361
) {
362+
Dbg_Log(" knife, cant dmg");
355363
return HC_CONTINUE;
356364
}
357365

358366
new weaponObject[S_CustomWeapon], T_CustomWeapon:weapon;
359367
if (!CWeapons_GetByInflictor(InflictorId, weaponObject, weapon)) {
368+
Dbg_Log(" inflictor weapon not found");
360369
return HC_CONTINUE;
361370
}
371+
Dbg_Log(" weaponObject = %d", weaponObject);
362372

363373
CWeapons_Call(weaponObject, CWeapon_OnDamage, [weapon, itemIndex, VictimId, InflictorId, AttackerId, fDamage, iDamageBits]);
364374
if (Events_IsRet(CWAPI_STOP_MAIN)) {

amxmodx/scripting/Cwapi/Core/CustomWeapons.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,12 @@ T_CustomWeapon:CWeapons_FindByInflictor(const inflictorIndex) {
218218
new entityIndex = 0;
219219
if (FClassnameIs(inflictorIndex, "player")) {
220220
entityIndex = get_member(inflictorIndex, m_pActiveItem);
221+
Dbg_Log("CWeapons_FindByInflictor: Player %d has active item %d", inflictorIndex, entityIndex);
221222
} else if (FClassnameIs(inflictorIndex, "grenade")) {
222223
entityIndex = inflictorIndex;
224+
Dbg_Log("CWeapons_FindByInflictor: Grenade %d", inflictorIndex);
225+
} else {
226+
Dbg_Log("CWeapons_FindByInflictor: Unknown inflictor %d", inflictorIndex);
223227
}
224228

225229
return CWeapons_GetWeaponFromEntity(entityIndex);

0 commit comments

Comments
 (0)