From 823eb10f2fecb74a83253584ae4f409cd25ca237 Mon Sep 17 00:00:00 2001 From: Shorohov Sergey Date: Fri, 7 Jun 2019 21:07:12 +0300 Subject: [PATCH] Add CVar: mp_afk_bomb_drop_time. (#369) * Add CVar: mp_afk_bomb_drop_time. Player that have never moved sience they last move will drop the bomb after this amount of time. (in seconds) --- README.md | 1 + dist/game.cfg | 9 +++++++++ regamedll/dlls/API/CSPlayer.cpp | 12 ++++++++++++ regamedll/dlls/game.cpp | 2 ++ regamedll/dlls/game.h | 1 + regamedll/dlls/player.cpp | 16 ++++++++++++++++ regamedll/public/regamedll/API/CSPlayer.h | 2 ++ 7 files changed, 43 insertions(+) diff --git a/README.md b/README.md index 40b61ac2..33886566 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Archive's bin directory contains 2 subdirectories, 'bugfixed' and 'pure' | ff_damage_reduction_grenade | 0.25 | 0.0 | 1.0 | How much to reduce damage done to teammates by a thrown grenade.
Range is from `0` - `1` (with 1 being damage equal to what is done to an enemy) | | ff_damage_reduction_grenade_self | 1.0 | 0.0 | 1.0 | How much to damage a player does to himself with his own grenade.
Range is from `0` - `1` (with 1 being damage equal to what is done to an enemy) | | ff_damage_reduction_other | 0.35 | 0.0 | 1.0 | How much to reduce damage done to teammates by things other than bullets and grenades.
Range is from `0` - `1` (with 1 being damage equal to what is done to an enemy) | +| mp_afk_bomb_drop_time | 1 | 0 | `999999` | Player that have never moved sience they last move will drop the bomb after this amount of time. (in seconds).
`0` disabled
`>0.00001` delay to drop | ## How to install zBot for CS 1.6? * Extract all the files from an [archive](regamedll/extra/zBot/bot_profiles.zip?raw=true) diff --git a/dist/game.cfg b/dist/game.cfg index 435505ac..11b68249 100644 --- a/dist/game.cfg +++ b/dist/game.cfg @@ -253,3 +253,12 @@ ff_damage_reduction_grenade_self "1.0" // // Default value: "0.35" ff_damage_reduction_other "0.35" + +// Player that have never moved sience they last move +// will drop the bomb after this amount of time. (in seconds). +// 0 - disabled +// >0.00001 - delay to drop +// +// Default value: "0" +mp_afk_bomb_drop_time "0" + diff --git a/regamedll/dlls/API/CSPlayer.cpp b/regamedll/dlls/API/CSPlayer.cpp index b33d54fc..f021870a 100644 --- a/regamedll/dlls/API/CSPlayer.cpp +++ b/regamedll/dlls/API/CSPlayer.cpp @@ -504,3 +504,15 @@ EXT_FUNC bool CCSPlayer::HintMessageEx(const char *pMessage, float duration, boo { return BasePlayer()->HintMessageEx(pMessage, duration, bDisplayIfPlayerDead, bOverride); } + +EXT_FUNC bool CCSPlayer::CheckActivityInGame() +{ + const CBasePlayer* pPlayer = BasePlayer(); + + const float deltaYaw = (m_vecOldvAngle.y - pPlayer->pev->v_angle.y); + const float deltaPitch = (m_vecOldvAngle.x - pPlayer->pev->v_angle.x); + + m_vecOldvAngle = pPlayer->pev->v_angle; + + return (fabs(deltaYaw) >= 0.1f && fabs(deltaPitch) >= 0.1f); +} diff --git a/regamedll/dlls/game.cpp b/regamedll/dlls/game.cpp index e104d737..07e638d7 100644 --- a/regamedll/dlls/game.cpp +++ b/regamedll/dlls/game.cpp @@ -118,6 +118,7 @@ cvar_t item_staytime = { "mp_item_staytime", "300", FCVAR_SERVER, 300. cvar_t legacy_bombtarget_touch = { "mp_legacy_bombtarget_touch", "1", 0, 1.0f, nullptr }; cvar_t respawn_immunitytime = { "mp_respawn_immunitytime", "0", FCVAR_SERVER, 0.0f, nullptr }; cvar_t kill_filled_spawn = { "mp_kill_filled_spawn", "1", 0, 0.0f, nullptr }; +cvar_t afk_bomb_drop_time = { "mp_afk_bomb_drop_time", "0", FCVAR_SERVER, 0.0f, nullptr }; cvar_t allow_point_servercommand = { "mp_allow_point_servercommand", "0", 0, 0.0f, nullptr }; cvar_t hullbounds_sets = { "mp_hullbounds_sets", "1", 0, 0.0f, nullptr }; @@ -304,6 +305,7 @@ void EXT_FUNC GameDLLInit() CVAR_REGISTER(&legacy_bombtarget_touch); CVAR_REGISTER(&respawn_immunitytime); CVAR_REGISTER(&kill_filled_spawn); + CVAR_REGISTER(&afk_bomb_drop_time); CVAR_REGISTER(&allow_point_servercommand); CVAR_REGISTER(&hullbounds_sets); diff --git a/regamedll/dlls/game.h b/regamedll/dlls/game.h index c7ce2458..2ac62a2c 100644 --- a/regamedll/dlls/game.h +++ b/regamedll/dlls/game.h @@ -155,6 +155,7 @@ extern cvar_t item_staytime; extern cvar_t legacy_bombtarget_touch; extern cvar_t respawn_immunitytime; extern cvar_t kill_filled_spawn; +extern cvar_t afk_bomb_drop_time; extern cvar_t allow_point_servercommand; extern cvar_t hullbounds_sets; extern cvar_t ff_damage_reduction_bullets; diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index fb9bd12a..fa560e9d 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -4231,6 +4231,13 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() // check every 5 seconds m_flIdleCheckTime = gpGlobals->time + 5.0; +#ifdef REGAMEDLL_ADD + if (CSPlayer()->CheckActivityInGame()) + { + m_fLastMovement = gpGlobals->time; + } +#endif + real_t flLastMove = gpGlobals->time - m_fLastMovement; //check if this player has been inactive for 2 rounds straight @@ -4246,6 +4253,15 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() m_fLastMovement = gpGlobals->time; } } +#ifdef REGAMEDLL_ADD + if (afk_bomb_drop_time.value > 0.0 && IsBombGuy()) + { + if (flLastMove > afk_bomb_drop_time.value && !CSGameRules()->IsFreezePeriod()) + { + DropPlayerItem("weapon_c4"); + } + } +#endif } if (g_pGameRules && g_pGameRules->FAllowFlashlight()) diff --git a/regamedll/public/regamedll/API/CSPlayer.h b/regamedll/public/regamedll/API/CSPlayer.h index debe0bc7..cbf6a999 100644 --- a/regamedll/public/regamedll/API/CSPlayer.h +++ b/regamedll/public/regamedll/API/CSPlayer.h @@ -95,12 +95,14 @@ public: }; EProtectionState GetProtectionState() const; + bool CheckActivityInGame(); public: char m_szModel[32]; bool m_bForceShowMenu; float m_flRespawnPending; float m_flSpawnProtectionEndTime; + Vector m_vecOldvAngle; }; // Inlines