• Player touch other player
    6 replies, posted
Hi, Is it possible to check if a player is colliding another player -> do something like print his nick in ShouldCollide it doesn't do anything it just allows them to pass through each other thanks
[QUOTE=sebekpolak51;52222742]in ShouldCollide it doesn't do anything it just allows them to pass through each other[/QUOTE] What are you doing in ShouldCollide that makes players pass through each other? As long as you don't return anything, nothing out of the ordinary should happen. Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetCustomCollisionCheck]Entity:SetCustomCollisionCheck[/url] on all players then use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ShouldCollide]GM:ShouldCollide[/url] to check if 2 players are colliding. Remember that it will be called twice for each collision (For A colliding with B, and for B colliding with A) so if you need to count or anything like that, adjust the values accordingly
[QUOTE=JasonMan34;52222788]What are you doing in ShouldCollide that makes players pass through each other? As long as you don't return anything, nothing out of the ordinary should happen. Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetCustomCollisionCheck]Entity:SetCustomCollisionCheck[/url] on all players then use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ShouldCollide]GM:ShouldCollide[/url] to check if 2 players are colliding. Remember that it will be called twice for each collision (For A colliding with B, and for B colliding with A) so if you need to count or anything like that, adjust the values accordingly[/QUOTE] Changing collision rules within a callback is likely to cause crashes! ;-; halp
[QUOTE=sebekpolak51;52223001]Changing collision rules within a callback is likely to cause crashes! ;-; halp[/QUOTE] So don't change collision rules within a callback....
[QUOTE=JasonMan34;52223002]So don't change collision rules within a callback....[/QUOTE] init.lua [CODE]local function KillPlayer( ply ) ply:Kill() end function GM:ShouldCollide( ent1, ent2 ) if ent1:IsPlayer() and ent2:IsPlayer() then if ent1:Team() == 3 then return false end if ent1:Team() == 2 and ent2:Team() == 1 then KillPlayer( ent2 ) return false end end return true end[/CODE] shared.lua [CODE] function PlayerMetaTable:SetAbilities() if self:Team() == 1 then self:SetWalkSpeed( 180 ) self:SetRunSpeed( self:GetWalkSpeed() ) self:SetJumpPower( 200 ) self:SetMoveType( MOVETYPE_WALK ) self:SetMaterial( "none" ) self:DrawShadow( true ) self:SetCollisionGroup( COLLISION_GROUP_NONE ) elseif self:Team() == 2 then self:SetWalkSpeed( 200 ) self:SetRunSpeed( self:GetWalkSpeed() ) self:SetJumpPower( 240 ) self:SetMoveType( MOVETYPE_WALK ) self:SetMaterial( "none" ) self:DrawShadow( true ) self:SetCollisionGroup( COLLISION_GROUP_NONE ) elseif self:Team() == 3 then self:SetWalkSpeed( 220 ) self:SetRunSpeed( 260 ) self:SetJumpPower( 200 ) self:SetMoveType( MOVETYPE_NOCLIP ) self:DrawShadow( false ) self:SetCollisionGroup( COLLISION_GROUP_WORLD ) end self:SetCustomCollisionCheck( true ) // self:CollisionRulesChanged() end [/CODE]
You're calling CollisionRulesChanged for no reason Also the KillPlayer function is awfully redundant (It literally just calls another function)
[QUOTE=JasonMan34;52223018]You're calling CollisionRulesChanged for no reason Also the KillPlayer function is awfully redundant (It literally just calls another function)[/QUOTE] yea I will do more things there in the future like explosion [editline]13th May 2017[/editline] It reads this function even when players aren't really colliding, they are like 20 feets away from themselves ;/
Sorry, you need to Log In to post a reply to this thread.