• Anti Prop-Push Help
    5 replies, posted
I'm trying to write a script to stop prop pushing but it isn't working. I think the shouldcollide hook is broken. It seems to be getting run even when there's no collision. Any alternative ideas? [lua] hook.Add("PhysgunPickup", "NoPropPush", function(ply, ent) ent.IsPhysgunned = true ent:SetCustomCollisionCheck(true) end) hook.Add("PhysgunDrop", "NoPropPush", function(ply, ent) ent.IsPhysgunned = nil ent:SetCustomCollisionCheck(false) end) local function stopPropPush(prop, attacked) local owner = prop:CPPIGetOwner() local victim if attacked:IsPlayer() then victim = attacked else victim = attacked:CPPIGetOwner() end if IsValid(owner) and IsValid(victim) and owner~=victim then timer.Simple(0,function() if prop:IsValid() then local physobj = prop:GetPhysicsObject() if physobj:IsValid() then owner:PrintMessage(HUD_PRINTCENTER, "Your prop froze because it hit someone's stuff") physobj:EnableMotion(false) end end end) end end hook.Add("ShouldCollide","DontPropPush", function(ent1, ent2) if ent1.IsPhysgunned then stopPropPush(ent1, ent2) end if ent2.IsPhysgunned then stopPropPush(ent2, ent1) end end) [/lua]
You'd probably be better off hooking PhysgunPickup and PhysgunDrop and setting the entity's collision group to something that doesn't collide w/ players.
I want to also keep people from prop pushing props they don't own. The problem with making the prop not collide with anything is that it would be easy to move a prop inside someone or their stuff and trap them. Plus some people need their prop to collide against whatever theyre building for knowing where to place something or whatever. And I'd rather not change the functionality of the physgun.
Set the collision group to COLLISION_GROUP_DEBRIS_TRIGGER which will make it only collide with the world. On drop switch it back to what it was ( store collision group on pickup; also if currently picked up return false to avoid having collision group overwritten by someone else ). OnDrop, if the prop is inside someone prevent the prop from being dropped ( I'm sure there's a way to prevent the person from letting go of the prop; if none are integrated it could be coded )... You could also keep a prop ghosted if it is TraceHull'd inside of someone or something with a timer added to check every few seconds for it to unghost in that spot ( or get deleted after x seconds ).
I think what I'll do is use the shouldcollide hook to ghost the prop against things the owner doesn't own and make it solid against things he does own. And I'll do the de-ghost check like you mentioned. The problem with my code was the shouldcollide hook doesn't only get called when two things collide, it can get called at other times.
It can be called when a player looks at something, and, yes, other times too... Also, be careful switching the collide in ShouldCollide on entities because it can break other entities collision such as having all vehicles fall through the map which is why I suggested only switching the collision group instead of using the hook.
Sorry, you need to Log In to post a reply to this thread.