Update func_vehicle for multiplayer (#792)

* Update func_vehicle for multiplayer. Added mp_legacy_vehicle_block cvar.

* Update dist/game.cfg

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>

* Update regamedll/dlls/game.cpp

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>

* Fix default behavior

* Optimization

Thanks to https://github.com/s1lentq/ReGameDLL_CS/pull/737#issuecomment-1068038171 help!

* Update README.md

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>
This commit is contained in:
Unreal Karaulov 2022-12-06 22:11:25 +03:00 committed by GitHub
parent 86e7215bfd
commit cf8deb9cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 7 deletions

View File

@ -106,6 +106,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_plant_c4_anywhere | 0 | 0 | 1 | When set, players can plant anywhere, not only in bombsites.<br/>`0` disabled <br/>`1` enabled |
| mp_give_c4_frags | 3 | - | - | How many bonuses (frags) will get the player who defused or exploded the bomb. |
| mp_hostages_rescued_ratio | 1.0 | 0.0 | 1.0 | Ratio of hostages rescued to win the round. |
| mp_legacy_vehicle_block | 1 | 0 | 1 | Legacy func_vehicle behavior when blocked by another entity.<br/>`0` New behavior <br/>`1` Legacy behavior |
</details>
## How to install zBot for CS 1.6?

9
dist/game.cfg vendored
View File

@ -494,3 +494,12 @@ mp_give_c4_frags "3"
//
// Default value: "1.0"
mp_hostages_rescued_ratio "1.0"
// Legacy func_vehicle behavior when blocked by another entity.
// New one is more useful for playing multiplayer.
//
// 0 - New behavior
// 1 - Legacy behavior
//
// Default value: "1"
mp_legacy_vehicle_block "1"

View File

@ -166,6 +166,8 @@ cvar_t give_c4_frags = { "mp_give_c4_frags", "3", 0, 3.0f, n
cvar_t hostages_rescued_ratio = { "mp_hostages_rescued_ratio", "1.0", 0, 1.0f, nullptr };
cvar_t legacy_vehicle_block = { "mp_legacy_vehicle_block", "1", 0, 0.0f, nullptr };
void GameDLL_Version_f()
{
if (Q_stricmp(CMD_ARGV(1), "version") != 0)
@ -410,6 +412,8 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&hostages_rescued_ratio);
CVAR_REGISTER(&legacy_vehicle_block);
// print version
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");

View File

@ -191,6 +191,7 @@ extern cvar_t plant_c4_anywhere;
extern cvar_t give_c4_frags;
extern cvar_t hostages_rescued_ratio;
extern cvar_t legacy_vehicle_block;
#endif
extern cvar_t scoreboard_showmoney;

View File

@ -3926,7 +3926,11 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(PlayerKilled)(CBasePlayer *pVictim,
else if (ktmp && ktmp->Classify() == CLASS_VEHICLE)
{
CBasePlayer *pDriver = static_cast<CBasePlayer *>(((CFuncVehicle *)ktmp)->m_pDriver);
#ifdef REGAMEDLL_FIXES
if (pDriver && !pDriver->has_disconnected)
#else
if (pDriver)
#endif
{
pKiller = pDriver->pev;
peKiller = static_cast<CBasePlayer *>(pDriver);

View File

@ -4030,7 +4030,12 @@ void CBasePlayer::PlayerUse()
CBaseEntity *pTrain = Instance(pev->groundentity);
if (pTrain && pTrain->Classify() == CLASS_VEHICLE)
{
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#else
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#endif
}
return;
}
@ -4572,7 +4577,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)()
{
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = (TRAIN_NEW | TRAIN_OFF);
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#else
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#endif
return;
}
}
@ -4581,7 +4591,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)()
// Turn off the train if you jump, strafe, or the train controls go dead
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = (TRAIN_NEW | TRAIN_OFF);
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#else
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#endif
return;
}

View File

@ -109,7 +109,7 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther)
pevOther->velocity.z += 300;
pev->velocity = pev->velocity * 0.85;
ALERT(at_aiconsole, "TRAIN(%s): Blocked by %s (dmg:%.2f)\n", STRING(pev->targetname), STRING(pOther->pev->classname), pev->dmg);
ALERT(at_aiconsole, "TRAIN(%s): Blocked by %s (dmg:%.2f)\n", STRING(pev->targetname), STRING(pevOther->classname), pev->dmg);
UTIL_MakeVectors(pev->angles);
Vector forward, right, vOrigin;
@ -131,13 +131,42 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther)
float maxz = pev->origin.z + (2 * Q_abs(int(pev->mins.z - pev->maxs.z)));
#endif
if (pOther->pev->origin.x < minx
|| pOther->pev->origin.x > maxx
|| pOther->pev->origin.y < miny
|| pOther->pev->origin.y > maxy
|| pOther->pev->origin.z < minz
|| pOther->pev->origin.z > maxz)
if (pevOther->origin.x < minx
|| pevOther->origin.x > maxx
|| pevOther->origin.y < miny
|| pevOther->origin.y > maxy
|| pevOther->origin.z < minz
|| pevOther->origin.z > maxz)
{
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
{
pOther->TakeDamage(pev, pev, 150, DMG_CRUSH);
return;
}
CBasePlayer* playerDriver = static_cast<CBasePlayer*>(m_pDriver);
if (pOther->Classify() == CLASS_PLAYER)
{
CBasePlayer* playerOther = static_cast<CBasePlayer*>(pOther);
if (!playerDriver || (!friendlyfire.value && playerDriver->m_iTeam == playerOther->m_iTeam))
{
// Just kick player
return;
}
else
{
playerOther->TakeDamage(pev, playerDriver->pev, 150, DMG_CRUSH);
return;
}
}
else if (FClassnameIs(pevOther, "hostage_entity") && playerDriver)
{
pOther->TakeDamage(playerDriver->pev, playerDriver->pev, 150, DMG_CRUSH);
return;
}
#endif
pOther->TakeDamage(pev, pev, 150, DMG_CRUSH);
}
}