Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rg_transfer_c4): prevent C4 destruction on arg receiver = 0 #291

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ native rg_get_user_footsteps(const index);
* @param index Client index
* @param receiver Receiver index, if 0 it will transfer to a random player
*
* @return 1 on success, 0 otherwise
* @return Index of player entity if successfull, 0 otherwise
*/
native rg_transfer_c4(const index, const receiver = 0);

Expand Down
2 changes: 1 addition & 1 deletion reapi/include/cssdk/dlls/gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class CHalfLifeMultiplay: public CGameRules
// check if the scenario has been won/lost
virtual void CheckWinConditions() = 0;
virtual void RemoveGuns() = 0;
virtual void GiveC4() = 0;
virtual CBasePlayer *GiveC4() = 0;
virtual void ChangeLevel() = 0;
virtual void GoToIntermission() = 0;

Expand Down
46 changes: 34 additions & 12 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,10 +1575,11 @@ cell AMX_NATIVE_CALL rg_get_user_footsteps(AMX *amx, cell *params)
* @param index Client index
* @param receiver Receiver index, if 0 it will transfer to a random player
*
* @return 1 on success, 0 otherwise
* @return Index of player entity if successfull, 0 otherwise
*
* native rg_transfer_c4(const index, const receiver = 0);
*/

cell AMX_NATIVE_CALL rg_transfer_c4(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_receiver };
Expand All @@ -1589,29 +1590,50 @@ cell AMX_NATIVE_CALL rg_transfer_c4(AMX *amx, cell *params)
CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

if (!pPlayer->m_bHasC4 || !pPlayer->CSPlayer()->RemovePlayerItem("weapon_c4"))
if (!pPlayer->m_bHasC4) {
return FALSE;
}

pPlayer->pev->body = 0;
pPlayer->m_bHasC4 = false;
pPlayer->CSPlayer()->SetBombIcon();
pPlayer->CSPlayer()->SetProgressBarTime(0);
CBasePlayer *pReceiver = nullptr;

if (params[arg_receiver] != 0 && params[arg_receiver] <= gpGlobals->maxClients) {
CBasePlayer *pReceiver = UTIL_PlayerByIndex(params[arg_receiver]);
if (params[arg_receiver] > 0 && params[arg_receiver] <= gpGlobals->maxClients) {
pReceiver = UTIL_PlayerByIndex(params[arg_receiver]);
CHECK_CONNECTED(pReceiver, arg_receiver);

if (!pReceiver->CSPlayer()->MakeBomber())
if (!pPlayer->CSPlayer()->RemovePlayerItemEx("weapon_c4", true)) {
return FALSE;
}

if (!pReceiver->CSPlayer()->MakeBomber()) {
return FALSE;
}
}
else {
int NumDeadCT, NumDeadTerrorist, NumAliveTerrorist, NumAliveCT;
CSGameRules()->InitializePlayerCounts(NumAliveTerrorist, NumAliveCT, NumDeadTerrorist, NumDeadCT);

if (pPlayer->m_iTeam == CT && NumAliveTerrorist < 1) {
return FALSE;
}

if (pPlayer->m_iTeam == TERRORIST && NumAliveTerrorist < 2) {
return FALSE;
}

if (!pPlayer->CSPlayer()->RemovePlayerItemEx("weapon_c4", true)) {
return FALSE;
}

} else {
auto flags = pPlayer->pev->flags;
pPlayer->pev->flags |= FL_DORMANT;
CSGameRules()->GiveC4();
pReceiver = CSGameRules()->GiveC4();
pPlayer->pev->flags = flags;
}

return TRUE;
if (pReceiver)
return indexOfPDataAmx(pReceiver);

return FALSE;
}

/*
Expand Down