Team No Collide Not Working | Please Assist!

Background:

I’m am developing a deathrun server for the latest version of GMOD (13) and it seem’s that none of the the previous code for Team No Collide works with the gamemode. Here are some of the code I have tried



function NoCollidePeople( teamID )
    for _, ply in pairs( team.GetPlayers( teamID ) ) do
        ply:SetNoCollideWithTeammates( true )
    end
end




function GM:ShouldCollide( ent1, ent2 )

    if ent1:IsPlayer() and ent2:IsPlayer() then 
        return (ent1:Team() != ent2:Team())
    end

    return true

end


Resolved:

Still not resolved, if anyone could please help me with this problem that would be much appreciated!

If that’s not working you can try this to make all players not collide, although it’s not team specific.


for _, ply in pairs(player.GetAll()) do
    ply:SetCollisionGroup(COLLISION_GROUP_WEAPON)
end

Still didn’t resolve the issue :confused:

In order for the ShouldCollide hook to be called for an entity, you need to do this:

[lua]
ent:SetCustomCollisionCheck( true ) – in this case ent would be the player entity
[/lua]

Sorry ahead of time if im causing problems… Here is the code I have in the shared.lua file


    function GM:ShouldCollide( ent1, ent2 )

	player:SetCustomCollisionCheck( true ) -- in this case ent would be the player entity

    if ent1:IsPlayer() and ent2:IsPlayer() then 
        return (ent1:Team() != ent2:Team())
    end

    return true

end


Still not causing players to no collide…

How do you expect the custom collision to work if you are enabling custom collision inside the custom collision function :v:

Just add it to the load out hook or something.

As far as we know player is not defined there, and even if it was that still wouldn’t work.

What you want to do is use SetCustomCollisionCheck on the player the first time they spawn (PlayerInitialSpawn).

Can someone just give me the entire line of code and where to put it, i’m new to lua and this is confusing the heck out of me…

[lua]function GM:PlayerInitialSpawn(pl)
pl:SetCustomCollisionCheck(true)
end
function GM:ShouldCollide( ent1, ent2 )
if ent1:IsPlayer() and ent2:IsPlayer() then
return (ent1:Team() != ent2:Team())
end
end[/lua]

Only return false if necessary, don’t always return something.

Right. Copied/pasted his code without looking at it.

You’re still doing it.

That would only apply if you were adding hooks since it will jut call the gamemode function in the end.

It’s necessary to return true there. Scenario: Player A and Player B are both on Team A. Hook returns false so they don’t collide. Player A switches to Team B so collision is necessary.

If it didn’t return anything then collision would remain ignored between the two. Given the gamemode doesn’t handle it like it needs to.

[lua]
hook.Add( “PlayerSpawn”, “nocollidewithteam”, function( ply )

ply:SetNoCollideWithTeammates( true )

end )[/lua]

This Worked!!

Thanks so much!!