When I use ShouldCollide hook, my server's physics get crashed. Entire server is not crashed, but props are floating and falling through floor. This is my code:
[CODE]local PlayerNoCollide = true
function GM:ShouldCollide( ent1, ent2 )
if IsValid( ent1 ) and IsValid( ent2 ) then //yeah, I've tried IsValid check, but... physics is still crashing ;(
if ( ent1.Walkthrough == true and ent2.CanBeWalkthroughed != nil ) or ( ent2.Walkthrough == true and ent1.CanBeWalkthroughed != nil ) or ( ent1:IsPlayer() and ent2:IsPlayer() and PlayerNoCollide ) or ent1:GetModel() == "models/props_c17/shelfunit01a.mdl" or ent2:GetModel() == "models/props_c17/shelfunit01a.mdl" then
return false
end
end
return true
end
if CLIENT then
hook.Add( "PlayerBindPress", "WalkthroughToggle", function( ply, bind, pressed )
if bind == "+menu" and pressed then
net.Start( "WannaWalkthrough" )
net.SendToServer()
end
end)
net.Receive( "WannaWalkthroughBroadcast", function()
local ply = net.ReadEntity()
if !ply.Walkthrough then
ply.Walkthrough = true
else
ply.Walkthrough = nil
end
end)
else
net.Receive( "WannaWalkthrough", function( len, ply )
if !ply.Walkthrough then
ply.Walkthrough = true
else
ply.Walkthrough = nil
end
net.Start( "WannaWalkthroughBroadcast" )
net.WriteEntity( ply )
net.Broadcast()
end)
end[/CODE]
There is no any errors (including Lua-errors). This is not full code - remaining part iterates through ents.GetAll and chooses needed entities.
Why are you overriding the entire ShouldCollide method? Also, why not use a bunch of elseifs instead of that mess?
[QUOTE=code_gs;50453903]Why are you overriding the entire ShouldCollide method? Also, why not use a bunch of elseifs instead of that mess?[/QUOTE]
Because I'm making a gamemode. I'll think about eleif's.
You should use hook.Add instead of defining the function GM:ShouldCollide. When you use hook.Add, [b]don't ever return true.[/b] Only return false if you don't want them to collide, otherwise, don't return anything.
That should fix it.
[QUOTE=NeatNit;50453977]You should use hook.Add instead of defining the function GM:ShouldCollide. When you use hook.Add, [b]don't ever return true.[/b] Only return false if you don't want them to collide, otherwise, don't return anything.
That should fix it.[/QUOTE]
This is default ShouldCollide function:
[QUOTE]function GM:ShouldCollide return true end[/QUOTE]
Take a look at "base" gamemode. Anyway, I've tried to make this using hook.Add previously, and physics still crashing.
ShouldCollide will currently break if you return different results for any entities without a call to Entity:CollisionRulesChanged() or Entity:SetCollisionGroup() in between. You also shouldn't call either of those functions from inside ShouldCollide.
It's pretty simple, but keep all of your complicated logic outside the hook (it looks like you've already achieved this) and call CollisionRulesChanged on your entity when the conditions have changed.
Hopefully that'll be automated in the future, but it isn't atm. Your model checks are probably going to bite you in the ass too. Move everything you can except for simple boolean checks outside of the hook. It's easier to do your logic in a hook like Think or PlayerTick and to just fetch your results in ShouldCollide.
-snip, dumb-
Sorry, you need to Log In to post a reply to this thread.