Player Touch Player

I’'ve just started getting into lua coding, and I’m trying to make a simple tag gamemode.
Although I’m having trouble with figuring out how to make a functions that kills a player when a player from one team touches a player from a different team.

Could someone be nice enough to point me in the right direction of how i would go about this?
or even better give me a example and try and explain it?


You can use this:
It works for all entities and is mostly used to set up collisions, but you can use it this way without a problem.

Thanks Buddy :stuck_out_tongue_winking_eye:

[editline]24th February 2014[/editline]

I’ve quickly tried it and this is what i’ve come up with but it doesn’t seem to be working?
function GM:ShouldCollide( ply1, ply2 )
if (ply1:IsPlayer() and ply2:IsPlayer()) then
if ply1:Team() == 1 and ply2:Team() == 2 then

so im expecting that both players would die as a test, and nothing seems to be happening. Am i sopposed to use a hook or something?

Description says: “Called whenever the engine wants to poll two entities should be able to collide. Only works if at least one of the entities has had Entity:SetCustomCollisionCheck called on it.”

Yeah i noticed that, but there is no information on SetCustomCollisionCheck. So i have no idea how to use it -_- Filled it just for you

I think you might be better off just doing a hull trace of the player along their normalized velocity vector, it’s less hacky and will accomplish what you want without risking breaking source physics if you get a lua error.

Yeah i agree, i tried using ShouldCollide and it works but it seems to collide 2 players together from about 5 feet away lol. not really reliable.
Could you maybe give me an example of using a hull trace for a player?


The hook isn’t called when players collide… It’s called to check if they can collide. It’s used by the physics engine to determine collision rules etc. It’s not actually a collision check and much less a collision callback. It’s actually called before it even tries to determine if they are touching.

On the player/client-side, it’s spammed when you look at something, even if it’s far away.