• Collision with player and props
    25 replies, posted
Hello there :) I really wanna no-colide a player with all entities, but how can i do that? So if i do <lua_run sv_nocollideme> it well then do something like no collide localplayer() with ents.getall
I'm not sure you want to do that but try here: [url]http://wiki.garrysmod.com/page/Special:Search?search=collision&fulltext=Search[/url]
Have a look into [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/constraint/NoCollide]constraint.NoCollide[/url]
I think Entity:GetCollisionGroup is the way to go, but how do i setup. Can someone maybe give me an example?
[QUOTE=RazMouze;50453659]I think Entity:GetCollisionGroup is the way to go, but how do i setup. Can someone maybe give me an example?[/QUOTE] [CODE]Entity:SetCollisionGroup( 1 )[/CODE] This should do it.
Wouldn't that change the collision of the entity to not collide with ANYTHING, rather than just not colliding with the player?
[QUOTE=Bubbie;50453671][CODE]Entity:SetCollisionGroup( 1 )[/CODE] This should do it.[/QUOTE] Yeah but how do i set the entity to localplayer?
[QUOTE=MPan1;50453673]Wouldn't that change the collision of the entity to not collide with ANYTHING, rather than just not colliding with the player?[/QUOTE] Read the OP again. He wants the player to not collide with anything.
[QUOTE=MPan1;50453673]Wouldn't that change the collision of the entity to not collide with ANYTHING, rather than just not colliding with the player?[/QUOTE] Yea but i could just use COLLISION_GROUP_WORLD 20
[QUOTE=RazMouze;50453679]Yeah but how do i set the entity to localplayer?[/QUOTE] Replace Entity with LocalPlayer() [editline]4th June 2016[/editline] [QUOTE=RazMouze;50453682]Yea but i could just use COLLISION_GROUP_WORLD 20[/QUOTE] That could work too.
[QUOTE=Bubbie;50453684]Replace Entity with LocalPlayer()[/QUOTE] Can u set the collision group of a player clientside? pretty sure you cant.
[QUOTE=rtm516;50453688]Can u set the collision group of a player clientside? pretty sure you cant.[/QUOTE] It's a shared function, but I seriously doubt it can be called clientside.
[QUOTE=Bubbie;50453684]Replace Entity with LocalPlayer() [editline]4th June 2016[/editline] That could work too.[/QUOTE] This is the problem [ERROR] lua/autorun/sv_collide.lua:1: attempt to call global 'LocalPlayer' (a nil value) 1. unknown - lua/autorun/sv_collide.lua:1
[QUOTE=RazMouze;50453690]This is the problem [ERROR] lua/autorun/sv_collide.lua:1: attempt to call global 'LocalPlayer' (a nil value) 1. unknown - lua/autorun/sv_collide.lua:1[/QUOTE] Run it serverside. Use Entity(1) or something instead of LocalPlayer().
I really don't think using SetCollisionGroup is a good idea, some entities may need a certain collision group to function properly, such as debris or anything really, so changing every single collision type to be the same could cause a ton of problems, and also that'd make it so every single player on the server have collisions disabled with every single entity on the server, rather than JUST the local player. [editline]4th June 2016[/editline] I think something like this would be safer: [CODE] local ply = Entity(1) -- or any player hook.Add( 'ShouldCollide', 'NoCollidePlayer', function( ent1, ent2 ) if ent1 == ply or ent2 == ply then return false end end ) ply:SetCustomCollisionCheck( true ) [/CODE] [editline]4th June 2016[/editline] You could then turn that into a console command like you wanted by doing something like this: [CODE] local nocollideplys = {} hook.Add( 'ShouldCollide', 'NoCollidePlayer', function( ent1, ent2 ) if nocollideplys[ ent1 ] or nocollideplys[ ent2 ] then return false end end ) concommand.Add( 'sv_nocollideme', function( ply, cmd, args, argstr ) nocollideplys[ ply ] = true ply:SetCustomCollisionCheck( true ) end ) [/CODE]
[QUOTE=Bubbie;50453693]Run it serverside. Use Entity(1) or something instead of LocalPlayer().[/QUOTE] It is running, but i still can't go through props still. [editline]4th June 2016[/editline] [QUOTE=MPan1;50453700]I really don't think using SetCollisionGroup is a good idea, some entities may need a certain collision group to function properly, such as debris or anything really, so changing every single collision type to be the same could cause a ton of problems, and also that'd make it so every single player on the server have collisions disabled with every single entity on the server, rather than JUST the local player. [editline]4th June 2016[/editline] I think something like this would be safer: [CODE] local ply = Entity(1) -- or any player hook.Add( 'ShouldCollide', 'NoCollidePlayer', function( ent1, ent2 ) if ent1 == ply or ent2 == ply then return false end end ) ply:SetCustomCollisionCheck( true ) [/CODE] [editline]4th June 2016[/editline] You could then turn that into a console command like you wanted by doing something like this: [CODE] local nocollideplys = {} hook.Add( 'ShouldCollide', 'NoCollidePlayer', function( ent1, ent2 ) for _, ply in ipairs( nocollideplys ) do if ent1 == ply or ent2 == ply then return false end end end ) concommand.Add( 'sv_nocollideme', function( ply, cmd, args, argstr ) table.insert( nocollideplys, ply ) ply:SetCustomCollisionCheck( true ) end ) [/CODE][/QUOTE] Thank you! But if i wanna turn it off again is it just return true?
If you want to turn it off, just remove the player from the nocollideplys table
[QUOTE=MPan1;50453728]If you want to turn it off, just remove the player from the nocollideplys table[/QUOTE] hmm.. I can't use my physgun?
I changed the code I posted before so it's easier to do that. You just have to do [CODE] nocollideplys[ SOME PLAYER ] = nil [/CODE] [editline]4th June 2016[/editline] damn automerge Also, yeah, not being able to physgun props is a result of the code from before, I'm not sure why though. I guess using another function would stop that from happening
[QUOTE=MPan1;50453737]I changed the code I posted before so it's easier to do that. You just have to do [CODE] nocollideplys[ SOME PLAYER ] = nil [/CODE] [editline]4th June 2016[/editline] damn automerge Also, yeah, not being able to physgun props is a result of the code from before, I'm not sure why though. I guess using another function would stop that from happening[/QUOTE] Why run through the table when you can just check if the key exists.
[QUOTE=bigdogmat;50453751]Why run through the table when you can just check if the key exists.[/QUOTE] Good point, updated my original code Not quite sure what to do about the physgun thing though, I guess you can't physgun props if you can't collide with them
Maybe you can physgun if you use the Entity:SetCollisionGroup( number group )
Wow, I'm stupid. All this time I thought people on this thread were talking about using SetCollsionGroup on EVERY ENTITY on the server, rather than just on the PLAYER. Nevermind about all the garbage I said before then, sorry
[QUOTE=MPan1;50453779]Wow, I'm stupid. All this time I thought people on this thread were talking about using SetCollsionGroup on EVERY ENTITY on the server, rather than just on the PLAYER. Nevermind about all the garbage I said before then, sorry[/QUOTE] Haha! No no... It's okay. But do you know how to do it with the group then?
I'm trying some stuff, but nothing seems to be working, so far I've tried PhysicsInit and SetSolid and SetCollisionGroup on the player, but none seem to give any results. I'll try playing around with the player's flags next [editline]4th June 2016[/editline] I give up, nothing seems to be working :(
It's okay i think i got it. It was to prevent propkilling and it seems like set solid is working for me. All i need is just away to reset setsolid
Sorry, you need to Log In to post a reply to this thread.