• Making players invisible only for local player?
    13 replies, posted
I'm trying to make it so that only players in a certain 'state' can see players in that 'state'. I'm not even going to post what I got, it's an embarrassing edit of someone elses code.
PrePlayerDraw, return true to prevent the player from rendering. It is a clientside hook. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/gm_functions_and_hooks/gm_preplayerdraw_making_players_invisible.lua.html[/url]
I'm actually wondering about uh, like. Two different groups can't see each other, but people of the same group can see each other. That's useful information right there though, I'm working with it right now.
Something like this should work [lua] hook.Add( "PrePlayerDraw", "HidePlayers", function( ply ) return ply:Team() ~= LocalPlayer():Team() -- If player's team is not local player's team then don't draw them end ) [/lua]
[QUOTE=Internet1001;46892387]Something like this should work [lua] hook.Add( "PrePlayerDraw", "HidePlayers", function( ply ) return ply:Team() ~= LocalPlayer():Team() -- If player's team is not local player's team then don't draw them end ) [/lua][/QUOTE] You don't want to do hooks like that. You are fucking up every other addon that might use it. [lua] hook.Add( "PrePlayerDraw", "HidePlayers", function( ply ) if ( ply:Team() ~= LocalPlayer():Team() ) then return true end end ) [/lua]
I thought that he'd want to override it completely. I assumed he was making a gamemode.
okay, so how do I get the local players meta table? I think that's prob my biggest issue right now. thanks in advance!! [editline]9th January 2015[/editline] [QUOTE=Internet1001;46892468]I thought that he'd want to override it completely. I assumed he was making a gamemode.[/QUOTE] im actually modifying a gamemode to make a 'cyberspace' type thing in the same map. just kidding, got it to work, thanks guys, robotbots method made the metatable calling work on my end. ty ty thanks so much
What do you need it for? There is no specific metatable for the LocalPlayer, just one for all Player objects. You can get it and add to it using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/FindMetaTable]Global.FindMetaTable[/url], specifiying "Player" [lua]local Player = FindMetaTable( "Player" ) function Player:MyFunction( arg1 ) print( arg1 ) end[/lua]
If he was making a game-mode, why use a hook instead of overwriting the GM function? That way hooks would still work but for the purpose of the game-mode, the gm function would take care of things? Robot is right; you only return non-nil in a hook for very specific behavior. If you return each and every time you disrupt the entire cycle of the hook system.
Does anyone of a way to do that with collisions? I'm looking through the wiki right now.
Do what with collisions? If you want to prevent collisions for players that would be invisible to each other you'd use the ShouldCollide hook and enable custom collision on initial spawn of the player. Here's what I use in my game-mode: [code]function GM:ShouldCollide( _e1, _e2 ) // Allow Physgunned players to be pulled through objects... if ( ( _e1:IsPlayer( ) && ( ( _e1:IsAdmin( ) && _e1:Invisible( ) ) || _e1:GetMoveType( ) == MOVETYPE_NOCLIP ) ) && ( _e2:IsNPC( ) || _e2:IsDoor( ) || _e2:IsVehicle( ) || _e2:IsProp( ) ) ) then return false; end end [/code] It allows physgunned players ( by admins ), whose movetypes are set to noclip, to move through objects. Additionally it allows invisible admins to move through the objects too. Be careful with ShouldCollide; if you have the behavior change based on dynamic situations it can cause physics to break ( the code above was modified many times over to get to a some-what stable point. I'm still testing the code above to be sure it won't cause crashing the 500th time running it or changing from invis to visible in a prop / vehicle )..
[QUOTE=Acecool;46892591] enable custom collision[/QUOTE] How do I do this? jk i got it to work
[QUOTE=Acecool;46892591]Do what with collisions? If you want to prevent collisions for players that would be invisible to each other you'd use the ShouldCollide hook and enable custom collision on initial spawn of the player. Here's what I use in my game-mode: [code]function GM:ShouldCollide( _e1, _e2 ) // Allow Physgunned players to be pulled through objects... if ( ( _e1:IsPlayer( ) && ( ( _e1:IsAdmin( ) && _e1:Invisible( ) ) || _e1:GetMoveType( ) == MOVETYPE_NOCLIP ) ) && ( _e2:IsNPC( ) || _e2:IsDoor( ) || _e2:IsVehicle( ) || _e2:IsProp( ) ) ) then return false; end end [/code] It allows physgunned players ( by admins ), whose movetypes are set to noclip, to move through objects. Additionally it allows invisible admins to move through the objects too. Be careful with ShouldCollide; if you have the behavior change based on dynamic situations it can cause physics to break ( the code above was modified many times over to get to a some-what stable point. I'm still testing the code above to be sure it won't cause crashing the 500th time running it or changing from invis to visible in a prop / vehicle )..[/QUOTE] Out of curiosity, why does't just setting the player's movetype to noclip allow this? I tried for a long while to do what you are before I came to a similar solution, and I never fully understood why changing movetype, collision group, or a combination thereof doesn't work. Sorry for off-topic.
Well... For example... When you enter a vehicle your movetype is set to noclip but instead of noclipping around you drive the vehicle but the movetype prevents you from colliding with the vehicle and being knocked out of the seat ( try changing movetype to normal in a vehicle then crashing the vehicle at varying speeds; you'll be knocked out of the seat and will end up floating while colliding with the world and being held back by the world ). MoveTypes appear to only define very basic collision attributes while the noclip system defines that when you're in noclip mode you can fly around without colliding with anything ( ie it adjusts position using SetPos without checking collision ). A basic "fly" system with collision could be defined by using the NoClip system, checking permission and if can fly return false while changing movetype between normal and fly then in SetupMove, if movetype fly, adjust position or velocity based on keys... All systems are separate from each other... Camera vs player vs controls so by defining the bare minimum for different settings / attributes you can extend their use to apply to many different scenarios and systems!
Sorry, you need to Log In to post a reply to this thread.