• Turning off net_graph while taking camera?
    46 replies, posted
Hello, I play everytime on my server, so I keep the net_graph 4 up everytime. But sometimes I want to take screenshots, but I would like to have the net_graph turned off. I know I can make a bind, but it's really boring to press a touch everytime I want to take one, especially in a fast moment. I know someone can make a script to detect when I have the camera tool, and disable my net_graph automatically, I would like to have it as a server script, making clients auto download it to help them. Thanks in advance. Edit : I'm an idiot, could a moderator move this thread into " Requests "... Sorry.
[lua] defaultnetgraph = GetConVar("net_graph"):GetInt() timer.Create( "nicehud_timer", 0.5, 0, function() local wep = LocalPlayer():GetActiveWeapon( ) if wep == "gmod_camera" then LocalPlayer():ConCommand("net_graph 0") else LocalPlayer():ConCommand("net_graph "..defaultnetgraph) end end ) [/lua] Ehhh there is probably a better what to do this but I'm lazy and that should work.
[QUOTE=mcd1992;16608814][lua] defaultnetgraph = GetConVar("net_graph"):GetInt() timer.Create( "nicehud_timer", 0.5, 0, function() local wep = LocalPlayer():GetActiveWeapon( ) if wep == "gmod_camera" then LocalPlayer():ConCommand("net_graph 0") else LocalPlayer():ConCommand("net_graph "..defaultnetgraph) end end ) [/lua] Ehhh there is probably a better what to do this but I'm lazy and that should work.[/QUOTE] Ok, first time I tried with " script net_graph camera ", it didn't work. After I tried with " scriptnetgraphcamera ", I just learnt that spaces are not allowed, but I got this : [CODE]Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) Timer Error: autorun/scriptnetgraphcamera.lua:3: attempt to call global 'LocalPlayer' (a nil value) [/CODE] It was spamming this. I put the file in lua/autorun. I tested it in singleplayer, maybe I should have tested on my server?
its client side and i don't think LocalPlayer() works right in single player, if you want to make it server side put a addCSLuaFile() and Include() at the top ( i might of spelt those wrong )
[QUOTE=mcd1992;16609318]its client side and i don't think LocalPlayer() works right in single player, if you want to make it server side put a addCSLuaFile() and Include() at the top ( i might of spelt those wrong )[/QUOTE] So must I put it in lua/autorun/client on my server? It's really hard, it's one of those things I didn't understand. Putting a LUA in lua/autorun, means that the LUA will execute itself both server and client? Putting a LUA in lua/autorun/client but on a dedicated server, means that the server will do nothing with it?
put that code in your C:\Program Files\Steam\steamapps\*name*\garrysmod\garrysmod\lua\autorun\client for people that join your server you need to put that code in your autrun/server with addCSLuaFile() and Include() at the top so that they are forced to download and run it, or if you have ulx just put it in the ulib/modules/client folder and they will be forced to dl and run it
[lua] NG = GetConVar("net_graph"):GetInt() timer.Create("Think", 1, 0, function() local Weapon = LocalPlayer():GetActiveWeapon():GetClass() if Weapon == "gmod_camera" then LocalPlayer():ConCommand("net_graph 0") else LocalPlayer():ConCommand("net_graph " .. NG) end end) [/lua] Put it in garrysmod/garrysmod/autorun/client/FileNameHere.lua If you join someones server and script enforcer is on it will not work. [B][I]Edit:[/I][/B] Putting a .lua file in the autorun/client/ folder will run the file for the client. Putting a .lua file in the autorun/server/ folder will run the file for the server. Putting a .lua file in the autorun/ folder will run the file for the client and the server, in this case you use "if SERVER then" or "if CLIENT then" to stop one or the other from running a certain section of code.
just put it in autorun with the code [lua]if SERVER then AddCSLuaFile("NameOfFile.lua") else NG = GetConVar("net_graph"):GetInt() hook.Add("Think", "antinetgraph", function() local Weapon = LocalPlayer():GetActiveWeapon():GetClass() if Weapon == "gmod_camera" then LocalPlayer():ConCommand("net_graph 0") else LocalPlayer():ConCommand("net_graph " .. NG) end end) end[/lua] when the server tries to run it it will be forwarded to the clients automatically. actually hooking think instead of just naming a timer think is a lot smarter and better than what you guys originally did.
[QUOTE=ninjerss;16610345]just put it in autorun with the code [lua]if SERVER then AddCSLuaFile("NameOfFile.lua") else NG = GetConVar("net_graph"):GetInt() hook.Add("Think", "antinetgraph", function() local Weapon = LocalPlayer():GetActiveWeapon():GetClass() if Weapon == "gmod_camera" then LocalPlayer():ConCommand("net_graph 0") else LocalPlayer():ConCommand("net_graph " .. NG) end end) end[/lua] when the server tries to run it it will be forwarded to the clients automatically. actually hooking think instead of just naming a timer think is a lot smarter and better than what you guys originally did.[/QUOTE] Thanks, just tested and it works. :) [editline]01:44AM[/editline] Oops, I just got an error, once dead, I have this [CODE] Hook 'antinetgraph' Failed: autorun/scriptnetgraphcamera.lua:6: Tried to use a NULL entity! [/CODE] which prints at the top right hand corner, in yellow, and the script seems to stop working. :/
I'll write a script that works and is much cleaner and easier to read.. brb. [editline]02:47AM[/editline] Here's a good example that has been tested and documented nicely. [lua] if(SERVER) then --Check if this script is being ran by the server. --We're adding the lua file to the download unique here. AddCSLuaFile("The_Name_Of_this_Lua_File.lua") else --The script is not ran by the server, so it has to be the client. --I made this variable to make sure that the script only toggles the variable once when you switch to/from the camera. --This means that people can eventually turn it on again if they are making screenshots. It won't disable it every tick but only once. local bEnabled = false --This variable checks if the graph is enabled by default. This prevents the script from enabling the graph when people had it off in the beginning. local bInitialGraph = GetConVar("net_graph"):GetBool() --I'm creating a new local function here, it won't be available in other files. --So you don't need fancy function names to prevent conflicts with other scripts either. local function Think() --The graph was already disabled when the player joined, so we don't need to use this script. if(not bInitialGraph) then return end --I'm getting the local player's active weapon here, this is the weapon the player is holding. local objWeapon = LocalPlayer():GetActiveWeapon() --Check if the weapon is valid and has the gmod_camera class. if(ValidEntity(objWeapon) and objWeapon:GetClass() == "gmod_camera") then --Check if the graph is still enabled, if so, disable it. if(bEnabled) then RunConsoleCommand("net_graph", 0) end --Swap the boolean. Example: Variable = the opposite of Variable. bEnabled = not bEnabled --The weapon isn't valid or you aren't holding the camera, time to turn on the graph again. else --Check if the graph is disabled, if so, enable it again. if(not bEnabled) then RunConsoleCommand("net_graph", 1) --You can change the 1 to anything you want, 4 in this case. end --Swap the boolean. Example: Variable = the opposite of Variable. bEnabled = not bEnabled end end --Add the hook that runs the Think() function every tick. hook.Add("Tick", "GraphThink", Think) end [/lua] Put this script in garrysmod/garrysmod/lua/autorun/The_Name_Of_this_Lua_File.lua :biggrin: Replace The_Name_Of_this_Lua_File with your preferred filename of this lua file. Make sure you replace the The_Name_Of_this_Lua_File in the AddCSLuaFile function of the script too. [editline]02:48AM[/editline] Yea I have too much freetime. PS: The guy who rated me a box can have it back because it doesn't have a present in it. :frown:
[QUOTE=maurits150;16613132]I'll write a script that works and is much cleaner and easier to read.. brb. [editline]02:47AM[/editline] Here's a good example that has been tested and documented nicely. [lua] if(SERVER) then --Check if this script is being ran by the server. --We're adding the lua file to the download unique here. AddCSLuaFile("The_Name_Of_this_Lua_File.lua") else --The script is not ran by the server, so it has to be the client. --I made this variable to make sure that the script only toggles the variable once when you switch to/from the camera. --This means that people can eventually turn it on again if they are making screenshots. It won't disable it every tick but only once. local bEnabled = false --This variable checks if the graph is enabled by default. This prevents the script from enabling the graph when people had it off in the beginning. local bInitialGraph = GetConVar("net_graph"):GetBool() --I'm creating a new local function here, it won't be available in other files. --So you don't need fancy function names to prevent conflicts with other scripts either. local function Think() --The graph was already disabled when the player joined, so we don't need to use this script. if(not bInitialGraph) then return end --I'm getting the local player's active weapon here, this is the weapon the player is holding. local objWeapon = LocalPlayer():GetActiveWeapon() --Check if the weapon is valid and has the gmod_camera class. if(ValidEntity(objWeapon) and objWeapon:GetClass() == "gmod_camera") then --Check if the graph is still enabled, if so, disable it. if(bEnabled) then RunConsoleCommand("net_graph", 0) end --Swap the boolean. Example: Variable = the opposite of Variable. bEnabled = not bEnabled --The weapon isn't valid or you aren't holding the camera, time to turn on the graph again. else --Check if the graph is disabled, if so, enable it again. if(not bEnabled) then RunConsoleCommand("net_graph", 1) --You can change the 1 to anything you want, 4 in this case. end --Swap the boolean. Example: Variable = the opposite of Variable. bEnabled = not bEnabled end end --Add the hook that runs the Think() function every tick. hook.Add("Tick", "GraphThink", Think) end [/lua] Put this script in garrysmod/garrysmod/lua/autorun/The_Name_Of_this_Lua_File.lua :biggrin: Replace The_Name_Of_this_Lua_File with your preferred filename of this lua file. Make sure you replace the The_Name_Of_this_Lua_File in the AddCSLuaFile function of the script too. [editline]02:48AM[/editline] Yea I have too much freetime. PS: The guy who rated me a box can have it back because it doesn't have a present in it. :frown:[/QUOTE] Thank you so much. :)
why would you use the tick hook when it runs slower than the think hook.
[QUOTE=ninjerss;16614208]why would you use the tick hook when it runs slower than the think hook.[/QUOTE] I'm not much of a lua coder, but it seems rather absurd to run such a minor script every frame.
My crazy version is only called when it has to be and does not require any files to be sent to the client. It uses bandwidth unnecessarily for fun. It does not save the player's current net_graph value because that would be giving the player a choice, and you know better than they do. Place in autorun\server. [lua] local function netgraphToggle(wep) if wep:GetClass() == "gmod_camera" then function wep:Deploy() wep.Owner:DrawViewModel(false) wep.Owner:SendLua([[RunConsoleCommand("net_graph","0")]]) end function wep:Holster() wep.Owner:SendLua([[RunConsoleCommand("net_graph","4")]]) return true end end end hook.Add("WeaponEquip", "netgraphtoggle", netgraphToggle) [/lua]
I don't know which one choose now. :/ The two last seem to be ok, so I don't know which one choose. I'd rather choose the first because it won't spawn a net_graph if the player didn't have one. But... I don't know. Anyways I didn't have tested the first one because there were people on my server, and I'm really lazy about cleaning the cache and reuploading it on my fast download server. I'll do it in 8 hours, after a sleep.
just stick with what you already have. it's working apparently so why fuck with it.
To give him choice. I would say pick the last code seeing as it is not called as much.
But suddenly having that huge graph in your screen is very annoying, even more when you don't know how to turn it off.
[QUOTE=ers35.;16617350]My crazy version is only called when it has to be and does not require any files to be sent to the client. It uses bandwidth unnecessarily for fun. It does not save the player's current net_graph value because that would be giving the player a choice, and you know better than they do. Place in autorun\server. [lua] local function netgraphToggle(wep) if wep:GetClass() == "gmod_camera" then function wep:Deploy() wep.Owner:DrawViewModel(false) wep.Owner:SendLua([[RunConsoleCommand("net_graph","0")]]) end function wep:Holster() wep.Owner:SendLua([[RunConsoleCommand("net_graph","4")]]) return true end end end hook.Add("WeaponEquip", "netgraphtoggle", netgraphToggle) [/lua][/QUOTE] I am sure that the toogun uses those functions. [editline]11:36AM[/editline] Try this instead : [lua]if SERVER then AddCSLuaFile("NameOfFile.lua") else hook.Add("Think","antinetgraph",function() if LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera" then RunConsoleCommand("net_graph 0") else RunConsoleCommand("net_graph "..tostring(GetConVar("net_graph"):GetInt())) end end) end[/lua]
Problem is that it tries to run the command 60 times a second and when it has once turned 0, it'll stay at 0. [lua]if ( SERVER ) then AddCSLuaFile( "NameOfFile.lua" ) else local netvar = GetConVar( "net_graph" ):GetInt( ) hook.Add( "Think", "antinetgraph", function( ) curwep = LocalPlayer( ):GetActiveWeapon( ):GetClass( ) if ( lastwep != curwep ) then if ( curwep == "gmod_camera" ) then netvar = GetConVar( "net_graph" ):GetInt( ) RunConsoleCommand( "net_graph", "0" ) else RunConsoleCommand( "net_graph", tostring( netvar ) ) end lastwep = curwep end end ) end[/lua] May be a bit longer than the other codes, but it doesn't set the net graph every 1/60th of a second and stores the desired net graph value every time it's changed.
ers35 WeaponEquip is only called when a weapon is picked up then equipped sadly :/
[QUOTE=Overv;16621018]Problem is that it tries to run the command 60 times a second and when it has once turned 0, it'll stay at 0. [lua]if ( SERVER ) then AddCSLuaFile( "NameOfFile.lua" ) else local netvar = GetConVar( "net_graph" ):GetInt( ) hook.Add( "Think", "antinetgraph", function( ) curwep = LocalPlayer( ):GetActiveWeapon( ):GetClass( ) if ( lastwep != curwep ) then if ( curwep == "gmod_camera" ) then netvar = GetConVar( "net_graph" ):GetInt( ) RunConsoleCommand( "net_graph 0" ) else RunConsoleCommand( "net_graph " .. tostring( netvar ) ) end lastwep = curwep end end ) end[/lua] May be a bit longer than the other codes, but it doesn't set the net graph every 1/60th of a second and stores the desired net graph value every time it's changed.[/QUOTE] Thanks, I'll put this one, I really want to avoid the " WTF is this shit on my screen I'v never seen that before??!! ". I'll tell you if it works when my server crashes ( have to update the cache after a reboot :/ ).
[QUOTE=kevkev;16620463]I am sure that the toogun uses those functions.[/QUOTE] I do not understand what you are talking about. If you saying that I am overriding functions that the toolgun uses, I am not. I am only overriding and creating functions for the gmod_camera entity. If you saying that the hook is called each time a player selects a tool, it is not. Each default tool is not a separate weapon. They all use the weapon gmod_tool. [QUOTE=mcd1992;16621889]ers35 WeaponEquip is only called when a weapon is picked up then equipped sadly :/[/QUOTE] Incorrect. It is called immediately when a player is given the weapon. I create the functions Deploy and Holster, which are called whenever the camera is switched to or switched from. I would have made it client-side, but I could not get Deploy to work.
Sorry for bumping, but the last script posted here doesn't work, and I still need a script which does that. Thanks.
[QUOTE=ninjerss;16610345]just put it in autorun with the code [lua]if SERVER then AddCSLuaFile("NameOfFile.lua") else NG = GetConVar("net_graph"):GetInt() hook.Add("Think", "antinetgraph", function() local Weapon = LocalPlayer():GetActiveWeapon():GetClass() if Weapon == "gmod_camera" then LocalPlayer():ConCommand("net_graph 0") else LocalPlayer():ConCommand("net_graph " .. NG) end end) end[/lua][/QUOTE] [QUOTE=Euphytose;16610685]Oops, I just got an error, once dead, I have this [CODE] Hook 'antinetgraph' Failed: autorun/scriptnetgraphcamera.lua:6: Tried to use a NULL entity! [/CODE] which prints at the top right hand corner, in yellow, and the script seems to stop working. :/[/QUOTE] He forgot that :GetClass() on nil (when the player is dead) won't work. Next attempt: [QUOTE=kevkev;16620463]I am sure that the toogun uses those functions. [lua]if SERVER then AddCSLuaFile("NameOfFile.lua") else hook.Add("Think","antinetgraph",function() if LocalPlayer():GetActiveWeapon():GetClass() == "gmod_camera" then RunConsoleCommand("net_graph 0") else RunConsoleCommand("net_graph "..tostring(GetConVar("net_graph"):GetInt())) end end) end[/lua][/QUOTE] Nice, yet it will error something like RunConsoleCommand can't hande spaces -> [lua]RunConsoleCommand("net_graph",0) --instead of RunConsoleCommand("net_graph 0")[/lua] Ohwell, next one: [QUOTE=Overv;16621018]Problem is that it tries to run the command 60 times a second and when it has once turned 0, it'll stay at 0. [lua]if ( SERVER ) then AddCSLuaFile( "NameOfFile.lua" ) else local netvar = GetConVar( "net_graph" ):GetInt( ) hook.Add( "Think", "antinetgraph", function( ) curwep = LocalPlayer( ):GetActiveWeapon( ):GetClass( ) if ( lastwep != curwep ) then if ( curwep == "gmod_camera" ) then netvar = GetConVar( "net_graph" ):GetInt( ) RunConsoleCommand( "net_graph 0" ) else RunConsoleCommand( "net_graph " .. tostring( netvar ) ) end lastwep = curwep end end ) end[/lua] May be a bit longer than the other codes, but it doesn't set the net graph every 1/60th of a second and stores the desired net graph value every time it's changed.[/QUOTE] Same problem as above, have you never used RunConsoleCommand? :0 You could just pcall ninjers' or fix kevkev and overv's and it should work :)
Ah yeah, probably because I looked at the code above by kevkev.
So, which one must I put?
[url=http://www.facepunch.com/showpost.php?p=16621018&postcount=20]This one[/url] should work now.
[QUOTE=Overv;16921711][url=http://www.facepunch.com/showpost.php?p=16621018&postcount=20]This one[/url] should work now.[/QUOTE] All works fine. But when I die, I have this : [LUA]Hook 'antinetgraph' Failed: autorun/togglenetgraphcamerascript.lua:7: Tried to use a NULL entity![/LUA] And after that, it doesn't work.
Check if there's a weapon before doing that.
Sorry, you need to Log In to post a reply to this thread.