Advertisement
Guest User

sv_screengrab

a guest
Sep 17th, 2013
33
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. util.AddNetworkString("screengrab_start")
  2. util.AddNetworkString("screengrab_part")
  3. util.AddNetworkString("screengrab_fwd_init")
  4. util.AddNetworkString("screengrab_fwd")
  5.  
  6. hook.Add("PlayerSay", "screengrab_playersay", function( ply, said )
  7. if string.Left( string.lower(said), 3 ) == "!gc" then
  8. local split = string.Split( said, " " )
  9. table.remove( split, 1 )
  10. SCRG.CheckArgs( ply, split )
  11. return false
  12. end
  13. end)
  14.  
  15. SCRG.CanRun = { "STEAM_0:0:19254119" }
  16.  
  17. function SCRG.CheckArgs( ply, args )
  18. if !ply:IsAdmin() and !table.HasValue(SCRG.CanRun, ply:SteamID()) then
  19. return
  20. end
  21. if args == nil or #args == 0 then
  22. ply:SendLua("MsgC(Color(255,0,0), 'Not enough arguments specified'")
  23. return
  24. end
  25. local name = args[1]
  26. local quality = 10
  27. if #args == 2 then
  28. if type( tonumber(args[2])) == "number" then
  29. quality = tonumber( args[2] )
  30. if quality > 80 then
  31. quality = 80
  32. elseif quality < 10 then
  33. quality = 10
  34. end
  35. else
  36. ply:SendLua("MsgC(Color(255,0,0), 'Invalid quality entered, defaulting to 10')")
  37. end
  38. else
  39. ply:SendLua("MsgC(Color(255,0,0), 'Invalid/no quality entered, defaulting to 10')")
  40. end
  41. local targ = false
  42. --If more than one possible target, it just grabs the first one.
  43. --Fix it yourself if you dont like it, I'm doing this for free and quickly.
  44. for k, v in pairs( player.GetAll() ) do
  45. if string.find( string.lower( v:Name() ), string.lower( args[1] ) ) != nil then
  46. targ = v
  47. elseif string.lower( v:SteamID( ) ) == string.lower( args[1] ) then
  48. targ = v
  49. end
  50. end
  51. if targ == false then
  52. ply:SendLua("MsgC(Color(255,0,0), 'No target found')")
  53. return
  54. end
  55. targ.SG = {}
  56. targ.SG.INIT = ply
  57. targ.SG.LEN = 0
  58. targ.SG.COUNT = 0
  59. net.Start("screengrab_start")
  60. net.WriteUInt( quality, 32 )
  61. net.Send( targ )
  62. end
  63.  
  64. concommand.Add("screengrab_player", function( ply, cmd, args )
  65. SCRG.CheckArgs( ply, args)
  66. end)
  67.  
  68. net.Receive("screengrab_start", function( x, ply )
  69. -- Readying the transfer
  70. if !IsValid( ply ) then
  71. print("player isnt valid")
  72. return
  73. end
  74. MsgN("Screenshot of "..ply:Name())
  75. local numparts = net.ReadUInt( 32 )
  76.  
  77. ply.SG.LEN = numparts
  78.  
  79. if IsValid( ply.SG.INIT ) then
  80. net.Start("screengrab_fwd_init")
  81. net.WriteEntity( ply )
  82. net.WriteUInt( numparts, 32 )
  83. net.Send( ply.SG.INIT )
  84. else
  85. MsgN("Caller of GC is now nonvalid")
  86. --Welp, the caller is gone. Not much point now.
  87. --I'll probably make it save to text files in a later version
  88. return
  89. end
  90.  
  91. --Tell them to initiate the transfer
  92. net.Start("screengrab_part")
  93. net.Send( ply )
  94.  
  95. end)
  96.  
  97. net.Receive("screengrab_part", function( x, ply )
  98. if !IsValid( ply ) then return end
  99. if !IsValid( ply.SG.INIT ) then return end
  100. if ply.SG.LEN == 0 then return end
  101.  
  102. local len = net.ReadUInt( 32 )
  103. local data = net.ReadData( len )
  104.  
  105. net.Start("screengrab_fwd")
  106. net.WriteEntity( ply )
  107. net.WriteUInt( len, 32 )
  108. net.WriteData( data, len )
  109. net.Send( ply.SG.INIT )
  110.  
  111. ply.SG.COUNT = ply.SG.COUNT + 1
  112. if ply.SG.COUNT == ply.SG.LEN then
  113. MsgN("Finished GC")
  114. ply.SG = nil
  115. else
  116. net.Start("screengrab_part")
  117. net.Send( ply )
  118. end
  119.  
  120.  
  121. end)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement