Skip to content

Held object issues #6331

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

Open
TankNut opened this issue May 9, 2025 · 0 comments
Open

Held object issues #6331

TankNut opened this issue May 9, 2025 · 0 comments

Comments

@TankNut
Copy link

TankNut commented May 9, 2025

Details

Held objects triggered by either Player:PickupObject or the normal +use method have a few issues:

When dropping or releasing an object by either left or right click, SWEP:PrimaryAttack or SWEP:SecondaryAttack is triggered on the previously held weapon on the server only

Recreated by inserting a print into either function and comparing between server and client

Workaround:

function GM:OnPlayerPhysicsDrop(ply, ent, thrown)
    ply.DroppedPhysicsFrame = FrameNumber()
end

function SWEP:PrimaryAttack()
    if SERVER and FrameNumber() == self:GetOwner().DroppedPhysicsFrame then
        return
    end
end

Picking up an object triggers it's compiled physgun interactions as if they were picked up by the gravity gun/super gravity gun

This is mostly an issue when trying to pick up ragdolls belonging to combine soldiers/elites through PickupObject, as they're compiled with the boogie interaction which causes them to flail around wildly and throw out tesla effects when dropped

Relevant code from the SDK:

void CRagdollProp::OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason )
{
    CDefaultPlayerPickupVPhysics::OnPhysGunDrop( pPhysGunUser, Reason );
    m_hPhysicsAttacker = pPhysGunUser;
    m_flLastPhysicsInfluenceTime = gpGlobals->curtime;

    if( HasPhysgunInteraction( "onpickup", "boogie" ) )
    {
        CRagdollBoogie::Create( this, 150, gpGlobals->curtime, 3.0f, SF_RAGDOLL_BOOGIE_ELECTRICAL );
    }

Workaround:

function GM:OnEntityCreated(ent)
	if ent:GetClass() == "env_ragdoll_boogie" then
        ent:Remove()
    end
end

Calling Player:PickupObject from SWEP:PrimaryAttack or SWEP:SecondaryAttack causes it to immediately be thrown/dropped

Took a moment to figure out what was going on here, from what I can tell it ends up checking whether the player is holding down either button on the same frame as the object was picked up, thus immediately causing it to be dropped

Workaround:

function SWEP:SecondaryAttack()
	local ply = self:GetOwner()

	if CLIENT or FrameNumber() == ply.DroppedPhysicsFrame then
		return
	end

	local ent = ply:GetUseEntity()

	timer.Simple(0, function()
		if not IsValid(ply) or not IsValid(ent) then
			return
		end

		ply:PickupObject(ent)
	end)

	ply:ConCommand("-attack2")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant