2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-05-03 02:09:25 +03:00

API: Knockback (#348)

This commit is contained in:
GLoOoccK 2025-04-20 11:33:24 -03:00 committed by GitHub
parent 5c06c04fa7
commit 66f6096160
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 81 additions and 2 deletions

View File

@ -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);

View File

@ -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,
};
/**

View File

@ -119,6 +119,7 @@ public:
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;

View File

@ -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;
@ -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() {}
@ -797,6 +801,7 @@ public:
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 {

View File

@ -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
*/

View File

@ -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

View File

@ -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[] = {

View File

@ -241,6 +241,7 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_Observer_Think,
RG_CBasePlayer_RemoveAllItems,
RG_CBasePlayer_UpdateStatusBar,
RG_CBasePlayer_TakeDamageImpulse,
// [...]
};

View File

@ -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 },
@ -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 }
};

View File

@ -6,5 +6,5 @@
#pragma once
#define VERSION_MAJOR 5
#define VERSION_MINOR 28
#define VERSION_MINOR 29
#define VERSION_MAINTENANCE 0