• Tabbed out Detector for TTT
    9 replies, posted
So someone I know said that they made a script for there Dark-RP Server that when the person tabbed out of the game it would put text above there head in the game saying "Tabbed Out". Does anyone know how this is done? I know the putting text above someones head is easy Draw...ext, But no idea how to detect if someone is tabed out of the game. This would be awesome for TTT.
system.HasFocus Only works on Windows, so check for system.IsWindows. They're not player methods and can only be detected clientside so you'll have to do the correct networking.
Wrote this up real quick. It's shared and it does the networking. [lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 3, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then //check if we see the player //ply:GetShootPos():ToScreen().visible might work instead of this, but I don't know for sure. local trace = { start = LocalPlayer():GetShootPos(), endpos = ply:GetShootPos(), filter = LocalPlayer(), mask = MASK_VISIBLE } local tr = util.TraceLine(trace) if IsValid(tr.Entity) then //draw the label if we see them. local Coords = ply:GetShootPos():ToScreen() if Coords.visible then //This might be sufficient instead of the trace. //Draw "Minimized" on them. draw.WordBox(2, Coords.x, Coords.y, "Minimized", "TargetID", Color(0,0,0,200), Color(255,255,255,200)) end end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua] Not sure if [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/ToScreen]Vector:ToScreen[/url]'s return value, [url=http://wiki.garrysmod.com/page/Structures/ToScreenData]ToScreenData[/url], which has "visible" works to see if they are on the other side of a wall or not. Let me know if it works!
Awesome, thanks Going to try it out right now, Thanks for the Help! Another quick coding question, when you guys are writing code for Gmod what software do you use. Anything better then Notepad++? [editline]9th December 2015[/editline] [QUOTE=bobbleheadbob;49278413]Wrote this up real quick. It's shared and it does the networking. [lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 3, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then //check if we see the player //ply:GetShootPos():ToScreen().visible might work instead of this, but I don't know for sure. local trace = { start = LocalPlayer():GetShootPos(), endpos = ply:GetShootPos(), filter = LocalPlayer(), mask = MASK_VISIBLE } local tr = util.TraceLine(trace) if IsValid(tr.Entity) then //draw the label if we see them. local Coords = ply:GetShootPos():ToScreen() if Coords.visible then //This might be sufficient instead of the trace. //Draw "Minimized" on them. draw.WordBox(2, Coords.x, Coords.y, "Minimized", "TargetID", Color(0,0,0,200), Color(255,255,255,200)) end end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua] Not sure if [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/ToScreen]Vector:ToScreen[/url]'s return value, [url=http://wiki.garrysmod.com/page/Structures/ToScreenData]ToScreenData[/url], which has "visible" works to see if they are on the other side of a wall or not. Let me know if it works![/QUOTE] Sorry for the double post, replied in the wrong place Awesome, thanks Going to try it out right now, Thanks for the Help! Another quick coding question, when you guys are writing code for Gmod what software do you use. Anything better then Notepad++? Btw: You should totally upload this to workshop or something this would help so many server admins. [editline]9th December 2015[/editline] [QUOTE=bobbleheadbob;49278413]Wrote this up real quick. It's shared and it does the networking. [lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 3, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then //check if we see the player //ply:GetShootPos():ToScreen().visible might work instead of this, but I don't know for sure. local trace = { start = LocalPlayer():GetShootPos(), endpos = ply:GetShootPos(), filter = LocalPlayer(), mask = MASK_VISIBLE } local tr = util.TraceLine(trace) if IsValid(tr.Entity) then //draw the label if we see them. local Coords = ply:GetShootPos():ToScreen() if Coords.visible then //This might be sufficient instead of the trace. //Draw "Minimized" on them. draw.WordBox(2, Coords.x, Coords.y, "Minimized", "TargetID", Color(0,0,0,200), Color(255,255,255,200)) end end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua] Not sure if [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/ToScreen]Vector:ToScreen[/url]'s return value, [url=http://wiki.garrysmod.com/page/Structures/ToScreenData]ToScreenData[/url], which has "visible" works to see if they are on the other side of a wall or not. Let me know if it works![/QUOTE] Just tested it out Could not get anything to show up. Little bit of a noob question but just putting it in Autorun or just lua is ok right? First time kinda working with the source engine :D
[QUOTE=Ztiep;49282441]Awesome, thanks Going to try it out right now, Thanks for the Help! Another quick coding question, when you guys are writing code for Gmod what software do you use. Anything better then Notepad++? [editline]9th December 2015[/editline] Sorry for the double post, replied in the wrong place Awesome, thanks Going to try it out right now, Thanks for the Help! Another quick coding question, when you guys are writing code for Gmod what software do you use. Anything better then Notepad++? Btw: You should totally upload this to workshop or something this would help so many server admins. [editline]9th December 2015[/editline] Just tested it out Could not get anything to show up. Little bit of a noob question but just putting it in Autorun or just lua is ok right? First time kinda working with the source engine :D[/QUOTE] Putting it in autorun should work. Do you get any errors on startup? Try this instead: [lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 3, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then //draw the label if we see them. local Coords = ply:GetShootPos():ToScreen() if Coords.visible then //This might be sufficient instead of the trace. //Draw "Minimized" on them. draw.WordBox(2, Coords.x, Coords.y, "Minimized", "TargetID", Color(0,0,0,200), Color(255,255,255,200)) end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua]
[QUOTE=bobbleheadbob;49283142]Putting it in autorun should work. Do you get any errors on startup? Try this instead: [lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 3, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then //draw the label if we see them. local Coords = ply:GetShootPos():ToScreen() if Coords.visible then //This might be sufficient instead of the trace. //Draw "Minimized" on them. draw.WordBox(2, Coords.x, Coords.y, "Minimized", "TargetID", Color(0,0,0,200), Color(255,255,255,200)) end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua][/QUOTE] Working! Only thing is that you can see it through walls, anyway of changing this. [editline]10th December 2015[/editline] [QUOTE=bobbleheadbob;49283142]Putting it in autorun should work. Do you get any errors on startup? Try this instead: [lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 3, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then //draw the label if we see them. local Coords = ply:GetShootPos():ToScreen() if Coords.visible then //This might be sufficient instead of the trace. //Draw "Minimized" on them. draw.WordBox(2, Coords.x, Coords.y, "Minimized", "TargetID", Color(0,0,0,200), Color(255,255,255,200)) end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua][/QUOTE] Also there is scaling of the text as you walk away from the player, also a way of turning that off?
[QUOTE=Ztiep;49283800]Working! Only thing is that you can see it through walls, anyway of changing this. [editline]10th December 2015[/editline] Also there is scaling of the text as you walk away from the player, also a way of turning that off?[/QUOTE] Let me make a 3d2d version. I'll post it here.
[QUOTE=bobbleheadbob;49284041]Let me make a 3d2d version. I'll post it here.[/QUOTE] Used some of the Pac3 got a working version the way I want it. Just have to change some stuff. also added if Alive to detect if the player is dead [/lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 1, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then if ply:Alive() then local pos_3d = id and ply:GetBonePosition(id) or ply:EyePos() local pos_2d = (pos_3d + Vector(0,0,10)):ToScreen() draw.DrawText("Tabbed out of Game", "ChatFont", pos_2d.x , pos_2d.y, Color(255,255,255,math.Clamp((pos_3d + Vector(0,0,10)):Distance(EyePos()) * -1 + 500, 0, 500)/500*255),1) end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua] [editline]10th December 2015[/editline] [QUOTE=bobbleheadbob;49284041]Let me make a 3d2d version. I'll post it here.[/QUOTE] [lua] if CLIENT then if system.IsWindows() then timer.Create("TabbedOut", 1, 0, function() if not system.HasFocus() then net.Start("Minimized") net.WriteBool(true) net.SendToServer() else net.Start("Minimized") net.WriteBool(false) net.SendToServer() end end) end hook.Add("HUDPaint", "DrawMinimized", function() for id,ply in pairs(player.GetAll()) do if ply:GetNWBool("Minimized", false) then if ply:Alive() then local pos_3d = ply:EyePos() local pos_2d = (pos_3d + Vector(0,0,10)):ToScreen() draw.DrawText("Tabbed Out Of Game", "TargetID", pos_2d.x , pos_2d.y, Color(255,0,0,math.Clamp((pos_3d + Vector(0,0,10)):Distance(EyePos()) * -1 + 500, 0, 500)/500*255),1) end end end end) else util.AddNetworkString("Minimized") net.Receive("Minimized", function(len, ply) local isMinimized = net.ReadBool() ply:SetNWBool("Minimized", isMinimized) end) end [/lua] Final code, Works great! Thanks so much for the help.
[URL="http://steamcommunity.com/sharedfiles/filedetails/?id=572519224"]Alt + Tab Labels[/URL] I improved my version and uploaded it to the workshop like you suggested.
[QUOTE=bobbleheadbob;49284537][URL="http://steamcommunity.com/sharedfiles/filedetails/?id=572519224"]Alt + Tab Labels[/URL] I improved my version and uploaded it to the workshop like you suggested.[/QUOTE] Nice, Thanks again. Even got it to update the rank on the scoreboard for the person. No more trying to get someone attention when they are not even in the game. :D
Sorry, you need to Log In to post a reply to this thread.