Advertisement
Short_Circuit

Bytewave's Workshop Adder for Garry's Mod

Aug 5th, 2014
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. --[[
  2. -------------------------------------
  3. - Bytewave's Worksohp Adder         -
  4. -                                   -
  5. - Adds maps for client download     -
  6. - based on the server's current map -
  7. - as well as general addons         -
  8. -                                   -
  9. - For free public use               -
  10. -------------------------------------
  11.  
  12. INSTRUCTIONS:
  13. Place this file in lua/autorun/server.
  14. Name it something easy-to-remember, such as workshop.lua.
  15. Edit this file where you are told. Do not touch
  16. any other part of this file unless you have no Lua knowledge
  17.  
  18. FINDING AN ADDON'S ID:
  19. Look at the addon's URL in the Steam browser (make sure you can
  20. actually see links in the Steam browser, there's a setting
  21. for it under Interface I believe).
  22. Search for this:
  23. ?id=xxxxxxxxx
  24. Copy that string of numbers, and there ya' go.
  25. ]]--
  26.  
  27. -- EDIT HERE:
  28. -- Add each addon ID on a new line, followed by a comma
  29. -- Do not place a comma on the final line
  30.  
  31. local ADDONS = {
  32.     123456789,
  33.     987654321,
  34. }
  35.  
  36. -- Add maps in this format:
  37. -- <mapname> = <Workshop ID>
  38. -- Add a comma to each line until the end
  39.  
  40. local MAPS = {
  41.     some_map_name  = 123456789,
  42.     some_other_map = 987654321,
  43. }
  44.  
  45. -- Do not edit anything below this line!
  46. -- (Unless you know what you're doing, of course.)
  47.  
  48. local players = player.GetAll()
  49. local format  = string.format
  50.  
  51. -- I like making things look pretty. Don't judge me.
  52. local function PChatToAll(msg)
  53.     for _, ply in pairs(players) do
  54.         if ply and IsValid(ply) then
  55.             ply:ChatPrint(format("[WORKSHOP]: %s", msg))
  56.         end
  57.     end
  58. end
  59.  
  60. local function PSLog(msg)
  61.     ServerLog(format("[WORKSHOP]: %s\n", msg))
  62. end
  63.  
  64. local function EchoAll(msg)
  65.     PSLog(msg)
  66.     PChatToAll(msg)
  67. end
  68.  
  69. -- Make some global variables to not call
  70. -- game.GetMap() and table.Count() every time
  71. local curMap     = string.lower(game.GetMap())
  72. local addonCount = table.Count(ADDONS)
  73.  
  74. EchoAll("Starting Workshop operations, expect chat spam!")
  75.  
  76. --[[-----------
  77.   Addon Adder
  78. -----------]]--
  79.  
  80. EchoAll("Adding Workshop addons to client downloads...")
  81.  
  82. for num, ID in pairs(ADDONS) do
  83.     EchoAll(format("Adding addon %d (%d of %d) for client download...", ID, num, addonCount))
  84.  
  85.     -- tostring() because someone thought it'd be a good idea
  86.     -- to make resource.AddWorkshop take a string instead
  87.     -- of a number
  88.     resource.AddWorkshop(tostring(ID))
  89.  
  90.     EchoAll(format("Addon %d (%d of %d) added.", ID, num, addonCount))
  91. end
  92.  
  93. --[[---------
  94.   Map Adder
  95. ---------]]--
  96.  
  97. local curMapID = MAPS[curMap]
  98.  
  99. EchoAll(format("Server playing on map %q. Attempting to add this map for client download...", curMap))
  100.  
  101. if not (curMapID == nil) then
  102.     EchoAll(format("Adding map %q (ID: %d) for client download...", curMap, curMapID))
  103.  
  104.     -- tostring() because someone thought it'd be a good idea
  105.     -- to make resource.AddWorkshop take a string instead
  106.     -- of a number
  107.     resource.AddWorkshop(tostring(curMapID))
  108.  
  109.     EchoAll(format("Map %q (ID: %d) added.", curMap, curMapID))
  110. else
  111.     EchoAll(format("Map %q not found in the MAPS table!", curMap))
  112. end
  113.  
  114. -- We're done here, now let's say we're done
  115. EchoAll("All Workshop operations complete! Sorry for the spam!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement