From 99bf170e7e0db61043a3118df6a9cc303893ddba Mon Sep 17 00:00:00 2001 From: pierow Date: Tue, 8 Aug 2023 03:12:18 -0400 Subject: [PATCH] Weapon/item drop rework -Fix crash from plugins. -Add spawn offsets for items. -Improvements to anti-stuck falling weapon code. --- main/source/dlls/client.cpp | 2 +- main/source/dlls/weapons.cpp | 14 +++++-------- main/source/mod/AvHGamerules.cpp | 2 +- main/source/mod/AvHPlayer.cpp | 36 ++++++++++++++++++++++++++------ main/source/mod/AvHPlayer.h | 5 +++-- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/main/source/dlls/client.cpp b/main/source/dlls/client.cpp index 21c242a1..4481cf0a 100644 --- a/main/source/dlls/client.cpp +++ b/main/source/dlls/client.cpp @@ -588,7 +588,7 @@ void ClientCommand( edict_t *pEntity ) if (thePlayerCanAct) { // player is dropping an item. - GetClassPtr((AvHPlayer *)pev)->DropItem((char *)CMD_ARGV(1)); + GetClassPtr((AvHPlayer *)pev)->DropItem((char *)CMD_ARGV(1), Vector(0, 0, 0)/*, true*/); } } else if ( FStrEq(pcmd, "fov" ) ) diff --git a/main/source/dlls/weapons.cpp b/main/source/dlls/weapons.cpp index d651e932..de3e078b 100644 --- a/main/source/dlls/weapons.cpp +++ b/main/source/dlls/weapons.cpp @@ -757,8 +757,7 @@ CBasePlayerItem::IsUseable( void ) void CBasePlayerItem :: FallInit( void ) { pev->movetype = MOVETYPE_TOSS; - //SOLID_BBOX caused weapons to get stuck on eachother and float in air - pev->solid = SOLID_BSP; + pev->solid = SOLID_BBOX; UTIL_SetOrigin( pev, pev->origin ); UTIL_SetSize(pev, Vector( 0, 0, 0), Vector(0, 0, 0) );//pointsize until it lands on the ground. @@ -779,8 +778,6 @@ void CBasePlayerItem :: FallInit( void ) void CBasePlayerItem::FallThink ( void ) { pev->nextthink = gpGlobals->time + 0.1; - //timer for weapons stuck floating in air - pev->fuser4 += 0.1; if ( pev->flags & FL_ONGROUND ) { @@ -789,7 +786,7 @@ void CBasePlayerItem::FallThink ( void ) if ( !FNullEnt( pev->owner ) ) { int pitch = 95 + RANDOM_LONG(0,29); - EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "items/weapondrop1.wav", 1, ATTN_NORM, 0, pitch); + EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "items/weapondrop1.wav", 1, ATTN_NORM, 0, pitch); } // lie flat @@ -797,13 +794,12 @@ void CBasePlayerItem::FallThink ( void ) pev->angles.z = 0; Materialize(); - pev->fuser4 = 0; } - //weapons in air for too long from collision issues with other entities change to SOLID_TRIGGER to fall to ground - else if ((pev->fuser4 > 0.7)) + //Weapons in air for too long from collision issues with other entities. Change to SOLID_TRIGGER to fall to ground. + else if (fabs(pev->velocity.x) < 0.1f && fabs(pev->velocity.y) < 0.1f && fabs(pev->velocity.z) < 3.0f) { pev->solid = SOLID_TRIGGER; - pev->fuser4 = 0; + //ALERT(at_console, "stuck x=%f y=%f z=%f \n", pev->velocity.x, pev->velocity.y, pev->velocity.z); } } diff --git a/main/source/mod/AvHGamerules.cpp b/main/source/mod/AvHGamerules.cpp index 0096872c..523b14d2 100644 --- a/main/source/mod/AvHGamerules.cpp +++ b/main/source/mod/AvHGamerules.cpp @@ -1781,7 +1781,7 @@ void AvHGamerules::PlayerGotWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapo } else { - thePlayer->DropItem(theWeaponName); + thePlayer->DropItem(theWeaponName, Vector(0, 0, 0)/*, true*/); } } //theDroppedWeapon = true; diff --git a/main/source/mod/AvHPlayer.cpp b/main/source/mod/AvHPlayer.cpp index 17b14c24..39715173 100644 --- a/main/source/mod/AvHPlayer.cpp +++ b/main/source/mod/AvHPlayer.cpp @@ -882,11 +882,15 @@ int AvHPlayer::GetScore() const return this->mScore; } -CBaseEntity* AvHPlayer::CreateAndDrop(const char* inItemName) +CBaseEntity* AvHPlayer::CreateAndDrop(const char* inItemName, const Vector spawnOffset) { UTIL_MakeVectors(pev->v_angle); - CBaseEntity* theEntity = CBaseEntity::Create(inItemName, pev->origin + gpGlobals->v_forward * 10, pev->angles, edict() ); + Vector spawnLoc = pev->origin + gpGlobals->v_forward * 10; + Vector adjustedSpawnOffset = (gpGlobals->v_right * spawnOffset.x) + (gpGlobals->v_forward * spawnOffset.y) + (gpGlobals->v_up * spawnOffset.z); + spawnLoc = spawnLoc + adjustedSpawnOffset; + + CBaseEntity* theEntity = CBaseEntity::Create(inItemName, spawnLoc, pev->angles, edict()); theEntity->pev->angles.x = 0; theEntity->pev->angles.z = 0; @@ -896,6 +900,23 @@ CBaseEntity* AvHPlayer::CreateAndDrop(const char* inItemName) return theEntity; } +//CBaseEntity* AvHPlayer::CreateAndPlace(const char* inItemName, const Vector spawnOffset) +//{ +// Vector spawnLoc = pev->origin + (gpGlobals->v_right * spawnOffset.x) + (gpGlobals->v_forward * spawnOffset.y) + (gpGlobals->v_up * spawnOffset.z); +// +// CBaseEntity* theEntity = CBaseEntity::Create(inItemName, spawnLoc, pev->angles, edict()); +// +// if (theEntity) +// { +// theEntity->pev->angles.x = 0; +// theEntity->pev->angles.z = 0; +// //theEntity->PackWeapon( pWeapon ); +// theEntity->pev->velocity = Vector(0, 0, 0); +// } +// +// return theEntity; +//} + void AvHPlayer::DeployCurrent() { if(this->m_pActiveItem /*&& !this->GetIsBeingDigested()*/) @@ -915,7 +936,7 @@ void AvHPlayer::DeployCurrent() // Drop the current item, not weapon, if any. -bool AvHPlayer::DropItem(const char* inItemName) +bool AvHPlayer::DropItem(const char* inItemName, const Vector spawnOffset/*, bool bToss*/) { bool theSuccess = false; @@ -964,7 +985,9 @@ bool AvHPlayer::DropItem(const char* inItemName) GetGameRules()->GetNextBestWeapon(this, theItem); } - CBaseEntity* theDroppedEntity = this->CreateAndDrop(STRING(theItem->pev->classname)); + //CBaseEntity* theDroppedEntity = (bToss) ? this->CreateAndDrop(STRING(theItem->pev->classname), spawnOffset) : this->CreateAndPlace(STRING(theItem->pev->classname), spawnOffset); + CBaseEntity* theDroppedEntity = this->CreateAndDrop(STRING(theItem->pev->classname), spawnOffset); + if(theAmmoLeft != -1) { CBasePlayerWeapon* theNewlyDroppedWeapon = dynamic_cast(theDroppedEntity); @@ -4777,8 +4800,9 @@ void AvHPlayer::PackDeadPlayerItems(void) this->DropItem(kwsShotGun); this->DropItem(kwsHeavyMachineGun); this->DropItem(kwsGrenadeGun); - this->DropItem(kwsMine); - this->DropItem(kwsWelder); + //Offset items so they don't get stuck in weapons and for visibility. + this->DropItem(kwsMine, Vector(10, 0, -12)/*, true*/); + this->DropItem(kwsWelder, Vector(-10, 0, -12)/*, true*/); } void AvHPlayer::PlayRandomRoleSound(string inSoundListName, int inChannel, float inVolume) diff --git a/main/source/mod/AvHPlayer.h b/main/source/mod/AvHPlayer.h index bcf2e7e9..4038ccc0 100644 --- a/main/source/mod/AvHPlayer.h +++ b/main/source/mod/AvHPlayer.h @@ -208,7 +208,7 @@ public: bool BuildTech(AvHMessageID inBuildID, const Vector& inWorldPos); void ClearBlips(); void ClientDisconnected(); - bool DropItem(const char* inItemName = NULL); + bool DropItem(const char* inItemName = NULL, const Vector spawnOffset = Vector(0, 0, 0)/*, bool bToss = true*/); bool GroupMessage(AvHMessageID inGroupMessage); bool GetCenterPositionForGroup(int inGroupNumber, float& outX, float& outY); @@ -487,7 +487,8 @@ private: bool AttemptToBuildAlienStructure(AvHMessageID inMessageID); void ClearRoleAbilities(); void ClearUserVariables(); - CBaseEntity* CreateAndDrop(const char* inItemName); + CBaseEntity* CreateAndDrop(const char* inItemName, const Vector spawnOffset = Vector(0, 0, 0)); + //CBaseEntity* CreateAndPlace(const char* inItemName, const Vector spawnOffset = Vector(0, 0, 0)); void DeployCurrent(); bool ExecuteAlienMorphMessage(AvHMessageID inMessageID, bool inInstantaneous); bool ExecuteCombatMessage(AvHMessageID inMessageID, bool& outIsAvailable, bool inForce = false);