Weapon/item drop rework

-Fix crash from plugins.
-Add spawn offsets for items.
-Improvements to anti-stuck falling weapon code.
This commit is contained in:
pierow 2023-08-08 03:12:18 -04:00
parent 1758eadb55
commit 99bf170e7e
5 changed files with 40 additions and 19 deletions

View file

@ -588,7 +588,7 @@ void ClientCommand( edict_t *pEntity )
if (thePlayerCanAct) if (thePlayerCanAct)
{ {
// player is dropping an item. // 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" ) ) else if ( FStrEq(pcmd, "fov" ) )

View file

@ -757,8 +757,7 @@ CBasePlayerItem::IsUseable( void )
void CBasePlayerItem :: FallInit( void ) void CBasePlayerItem :: FallInit( void )
{ {
pev->movetype = MOVETYPE_TOSS; pev->movetype = MOVETYPE_TOSS;
//SOLID_BBOX caused weapons to get stuck on eachother and float in air pev->solid = SOLID_BBOX;
pev->solid = SOLID_BSP;
UTIL_SetOrigin( pev, pev->origin ); UTIL_SetOrigin( pev, pev->origin );
UTIL_SetSize(pev, Vector( 0, 0, 0), Vector(0, 0, 0) );//pointsize until it lands on the ground. 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 ) void CBasePlayerItem::FallThink ( void )
{ {
pev->nextthink = gpGlobals->time + 0.1; pev->nextthink = gpGlobals->time + 0.1;
//timer for weapons stuck floating in air
pev->fuser4 += 0.1;
if ( pev->flags & FL_ONGROUND ) if ( pev->flags & FL_ONGROUND )
{ {
@ -789,7 +786,7 @@ void CBasePlayerItem::FallThink ( void )
if ( !FNullEnt( pev->owner ) ) if ( !FNullEnt( pev->owner ) )
{ {
int pitch = 95 + RANDOM_LONG(0,29); 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 // lie flat
@ -797,13 +794,12 @@ void CBasePlayerItem::FallThink ( void )
pev->angles.z = 0; pev->angles.z = 0;
Materialize(); Materialize();
pev->fuser4 = 0;
} }
//weapons in air for too long from collision issues with other entities change to SOLID_TRIGGER to fall to ground //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)) 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->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);
} }
} }

View file

@ -1781,7 +1781,7 @@ void AvHGamerules::PlayerGotWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapo
} }
else else
{ {
thePlayer->DropItem(theWeaponName); thePlayer->DropItem(theWeaponName, Vector(0, 0, 0)/*, true*/);
} }
} }
//theDroppedWeapon = true; //theDroppedWeapon = true;

View file

@ -882,11 +882,15 @@ int AvHPlayer::GetScore() const
return this->mScore; return this->mScore;
} }
CBaseEntity* AvHPlayer::CreateAndDrop(const char* inItemName) CBaseEntity* AvHPlayer::CreateAndDrop(const char* inItemName, const Vector spawnOffset)
{ {
UTIL_MakeVectors(pev->v_angle); 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.x = 0;
theEntity->pev->angles.z = 0; theEntity->pev->angles.z = 0;
@ -896,6 +900,23 @@ CBaseEntity* AvHPlayer::CreateAndDrop(const char* inItemName)
return theEntity; 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() void AvHPlayer::DeployCurrent()
{ {
if(this->m_pActiveItem /*&& !this->GetIsBeingDigested()*/) if(this->m_pActiveItem /*&& !this->GetIsBeingDigested()*/)
@ -915,7 +936,7 @@ void AvHPlayer::DeployCurrent()
// Drop the current item, not weapon, if any. // 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; bool theSuccess = false;
@ -964,7 +985,9 @@ bool AvHPlayer::DropItem(const char* inItemName)
GetGameRules()->GetNextBestWeapon(this, theItem); 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) if(theAmmoLeft != -1)
{ {
CBasePlayerWeapon* theNewlyDroppedWeapon = dynamic_cast<CBasePlayerWeapon*>(theDroppedEntity); CBasePlayerWeapon* theNewlyDroppedWeapon = dynamic_cast<CBasePlayerWeapon*>(theDroppedEntity);
@ -4777,8 +4800,9 @@ void AvHPlayer::PackDeadPlayerItems(void)
this->DropItem(kwsShotGun); this->DropItem(kwsShotGun);
this->DropItem(kwsHeavyMachineGun); this->DropItem(kwsHeavyMachineGun);
this->DropItem(kwsGrenadeGun); this->DropItem(kwsGrenadeGun);
this->DropItem(kwsMine); //Offset items so they don't get stuck in weapons and for visibility.
this->DropItem(kwsWelder); 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) void AvHPlayer::PlayRandomRoleSound(string inSoundListName, int inChannel, float inVolume)

View file

@ -208,7 +208,7 @@ public:
bool BuildTech(AvHMessageID inBuildID, const Vector& inWorldPos); bool BuildTech(AvHMessageID inBuildID, const Vector& inWorldPos);
void ClearBlips(); void ClearBlips();
void ClientDisconnected(); 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 GroupMessage(AvHMessageID inGroupMessage);
bool GetCenterPositionForGroup(int inGroupNumber, float& outX, float& outY); bool GetCenterPositionForGroup(int inGroupNumber, float& outX, float& outY);
@ -487,7 +487,8 @@ private:
bool AttemptToBuildAlienStructure(AvHMessageID inMessageID); bool AttemptToBuildAlienStructure(AvHMessageID inMessageID);
void ClearRoleAbilities(); void ClearRoleAbilities();
void ClearUserVariables(); 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(); void DeployCurrent();
bool ExecuteAlienMorphMessage(AvHMessageID inMessageID, bool inInstantaneous); bool ExecuteAlienMorphMessage(AvHMessageID inMessageID, bool inInstantaneous);
bool ExecuteCombatMessage(AvHMessageID inMessageID, bool& outIsAvailable, bool inForce = false); bool ExecuteCombatMessage(AvHMessageID inMessageID, bool& outIsAvailable, bool inForce = false);