Skip to content
12 changes: 12 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1233,3 +1233,15 @@ native rg_player_relationship(const player, const target);
* @noreturn
*/
native rg_send_death_message(const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill);

/*
* Adds impulse to the player.
*
* @param player Player index.
* @param attacker Attacker index.
* @param flKnockbackForce Knockback force.
* @param flVelModifier Velocity modifier.
*
* @noreturn
*/
native rg_player_takedamage_impulse(const player, const attacker, const Float:flKnockbackForce, const Float:flVelModifier);
6 changes: 6 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,12 @@ enum GamedllFunc_CBasePlayer
* Params: (const this)
*/
RG_CBasePlayer_UpdateStatusBar,

/*
* Description: Called for the victim player after taking damage, when "knockback" and "pain shock" are applied.
* Params: (const this, attacker, Float:flKnockbackForce, Float:flVelModifier)
*/
RG_CBasePlayer_TakeDamageImpulse,
};

/**
Expand Down
1 change: 1 addition & 0 deletions reapi/include/cssdk/dlls/API/CSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class CCSPlayer: public CCSMonster
virtual void OnSpawnEquip(bool addDefault = true, bool equipGame = true) = 0;
virtual void SetScoreboardAttributes(CBasePlayer *destination = nullptr) = 0;
virtual void Observer_FindNextPlayer(bool bReverse, const char *name = nullptr) = 0;
virtual void TakeDamageImpulse(CBasePlayer *pAttacker, float flKnockbackForce, float flVelModifier) = 0;

CBasePlayer *BasePlayer() const;

Expand Down
7 changes: 6 additions & 1 deletion reapi/include/cssdk/dlls/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <API/CSInterfaces.h>

#define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 29
#define REGAMEDLL_API_VERSION_MINOR 30

// CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
Expand Down Expand Up @@ -634,6 +634,10 @@ typedef IHookChainRegistryClass<void, class CBasePlayer, BOOL> IReGameHookRegist
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_UpdateStatusBar;
typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBasePlayer_UpdateStatusBar;

// CBasePlayer::TakeDamageImpulse hook
typedef IHookChainClass<void, class CBasePlayer, class CBasePlayer *, float, float> IReGameHook_CBasePlayer_TakeDamageImpulse;
typedef IHookChainRegistryClass<void, class CBasePlayer, class CBasePlayer *, float, float> IReGameHookRegistry_CBasePlayer_TakeDamageImpulse;

class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
Expand Down Expand Up @@ -797,6 +801,7 @@ class IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think() = 0;
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems() = 0;
virtual IReGameHookRegistry_CBasePlayer_UpdateStatusBar *CBasePlayer_UpdateStatusBar() = 0;
virtual IReGameHookRegistry_CBasePlayer_TakeDamageImpulse *CBasePlayer_TakeDamageImpulse() = 0;
};

struct ReGameFuncs_t {
Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,16 @@ void CBasePlayer_UpdateStatusBar(IReGameHook_CBasePlayer_UpdateStatusBar *chain,
callVoidForward(RG_CBasePlayer_UpdateStatusBar, original, indexOfEdict(pthis->pev));
}

void CBasePlayer_TakeDamageImpulse(IReGameHook_CBasePlayer_TakeDamageImpulse *chain, CBasePlayer *pthis, CBasePlayer *pAttacker, float flKnockbackForce, float flVelModifier)
{
auto original = [chain](int _pthis, int _pAttacker, float _flKnockbackForce, float _flVelModifier)
{
chain->callNext(getPrivate<CBasePlayer>(_pthis), getPrivate<CBasePlayer>(_pAttacker), _flKnockbackForce, _flVelModifier);
};

callVoidForward(RG_CBasePlayer_TakeDamageImpulse, original, indexOfEdict(pthis->pev), indexOfEdict(pAttacker->pev), flKnockbackForce, flVelModifier);
}

/*
* VTC functions
*/
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, C
void CBasePlayer_RemoveAllItems(IReGameHook_CBasePlayer_RemoveAllItems *chain, CBasePlayer *pthis, BOOL removeSuit);
void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill);
void CBasePlayer_UpdateStatusBar(IReGameHook_CBasePlayer_UpdateStatusBar *chain, CBasePlayer *pthis);
void CBasePlayer_TakeDamageImpulse(IReGameHook_CBasePlayer_TakeDamageImpulse *chain, CBasePlayer *pthis, CBasePlayer *pAttacker, float flKnockbackForce, float flVelModifier);

/*
* VTC functions
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ hook_t hooklist_player[] = {
DLL(CBasePlayer_Observer_Think),
DLL(CBasePlayer_RemoveAllItems),
DLL(CBasePlayer_UpdateStatusBar),
DLL(CBasePlayer_TakeDamageImpulse),
};

hook_t hooklist_gamerules[] = {
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_Observer_Think,
RG_CBasePlayer_RemoveAllItems,
RG_CBasePlayer_UpdateStatusBar,
RG_CBasePlayer_TakeDamageImpulse,

// [...]
};
Expand Down
42 changes: 42 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3375,6 +3375,47 @@ cell AMX_NATIVE_CALL rg_send_death_message(AMX *amx, cell *params)
return TRUE;
}

/*
* Adds impulse to the player.
*
* @param player Player index.
* @param attacker Attacker index.
* @param flKnockbackForce Knockback force.
* @param flVelModifier Velocity modifier.
*
* @noreturn
*/
cell AMX_NATIVE_CALL rg_player_takedamage_impulse(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_attacker, arg_knockback_force, arg_vel_modifier };

CHECK_ISPLAYER(arg_index);
CHECK_ISPLAYER(arg_attacker);

CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

if (!pPlayer->IsAlive())
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: player %d not alive", __FUNCTION__, params[arg_index]);
return FALSE;
}

CBasePlayer *pAttacker = UTIL_PlayerByIndex(params[arg_attacker]);
CHECK_CONNECTED(pAttacker, arg_attacker);

if (!pAttacker->IsAlive())
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: attacker %d not alive", __FUNCTION__, params[arg_attacker]);
return FALSE;
}

CAmxArgs args(amx, params);
pPlayer->CSPlayer()->TakeDamageImpulse(pAttacker, args[arg_knockback_force], args[arg_vel_modifier]);

return TRUE;
}

AMX_NATIVE_INFO Misc_Natives_RG[] =
{
{ "rg_set_animation", rg_set_animation },
Expand Down Expand Up @@ -3490,6 +3531,7 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =
{ "rg_player_relationship", rg_player_relationship },

{ "rg_send_death_message", rg_send_death_message },
{ "rg_player_takedamage_impulse", rg_player_takedamage_impulse },

{ nullptr, nullptr }
};
Expand Down
2 changes: 1 addition & 1 deletion reapi/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
#pragma once

#define VERSION_MAJOR 5
#define VERSION_MINOR 28
#define VERSION_MINOR 29
#define VERSION_MAINTENANCE 0