• Print

Author Topic: Download current map from workshop  (Read 7571 times)

0 Members and 1 Guest are viewing this topic.

Offline MCFX2

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • @pump_upp - best crypto pumps on telegram !
Download current map from workshop
« on: August 18, 2016, 09:48:44 pm »
I had an idea to download the current map from the workshop instead of having to rely on fastDL or worse serverDL.
my current attempt is to modify the workshopdl.lua (in lua/autorun/server), and based on the current map get a workshop addon with the right map:
Code: Lua
  1. local mapIDs = mapIDs or {}
  2. local curMap = game.GetMap()
  3.  
  4. mapIDs["ttt_fastfood_a6"] = 145316417
  5.  
  6. if not mapIDs[curMap] == nil then
  7.  resource.AddWorkshop(mapIDs[map])
  8. end
  9.  
  10.  

However, this invariable results in "missing map" errors (for those who don't already have the map) instead of actually working. Is the problem in the way I've implemented/loaded it, or is it a gmod bug? If it IS a gmod bug, are there any workarounds?

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Download current map from workshop
« Reply #1 on: August 18, 2016, 10:30:17 pm »
I don't know how to do it with the current map, but I know you can put a file in
Code: [Select]
garrysmod/lua/autorun/server called 'resources.lua' in which you can have all of the resource.AddWorkshop( "" ) lines in there. Check this creator out. It helped me a lot when I ran a server.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline MCFX2

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • @pump_upp - best crypto pumps on telegram !
Re: Download current map from workshop
« Reply #2 on: August 18, 2016, 10:57:15 pm »
I don't know how to do it with the current map, but I know you can put a file in
Code: [Select]
garrysmod/lua/autorun/server called 'resources.lua' in which you can have all of the resource.AddWorkshop( "" ) lines in there. Check this creator out. It helped me a lot when I ran a server.
That's the problem- my options are to download all the maps on the server which definitely isn't ideal, or rely on fastDL, which also isn't ideal. Does calling the file 'resources.lua' magically somehow make it work differently?

I've looked at that, but that doesn't solve the problems stated above.
« Last Edit: August 18, 2016, 11:00:50 pm by MCFX2 »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Download current map from workshop
« Reply #3 on: August 18, 2016, 11:01:14 pm »
The file will make all the files added into it be added to the client when they connect, so the first thing you said. Not sure how to make it only the current.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Download current map from workshop
« Reply #4 on: August 19, 2016, 08:45:47 am »
I use a similar script on my server, where all the Workshop maps are stored in a table, similar to yours. It works just fine.
Have you tried this with other map addons? It could be that ttt_fastfood_a6 isn't the name of the actual map file, for some reason or another, but I doubt that.
You do need this script in /lua/autorun/server, as iViscosity pointed out, but once there, your code ought to work.

a nitpick: Instead of using not a == b, you can use ~=, the "not equal to" operator. Doubt that's causing any issues, but hey.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Download current map from workshop
« Reply #5 on: August 19, 2016, 01:40:18 pm »
Here's the system I've been using:

Code: [Select]
maplist = {}

maplist["gm_trainconstruct2"] = "161015436"
maplist["gm_freespace_13"] = "115510325"
maplist["gm_citylimits_day_v1"] = "106750883"
maplist["gm_citylimits_v2"] = "104674256"
maplist["gm_bluehills_test3"] = "243902601"
maplist["gm_excess_islands"] = "115250988"
maplist["gm_bigcity"] = "105982362"
maplist["gm_fork"] = "326332456"
maplist["gm_Lair"] = "104488112"
maplist["gm_carcon_ws"] = "206869955"
maplist["gm_flatgrass_airport"] = "108420002"
maplist["gm_flatgrass_classic"] = "104609986"
maplist["rp_chaos_city_v33x_03"] = "296403366","296391343","296396662","296399858"
maplist["gm_megacity"] = "457749390"
maplist["gm_flatbuild_2015_dev"] = "432484761"
maplist["gm_flatgrass_abs_v3c"] = "213888400"
maplist["gm_valley"] = "104483504"
maplist["GM_City25"] = "523367894"
maplist["gm_construct_flatgrass_v6-2"] = "104468359"
maplist["gm_mobenix_v3_final"] = "140618773"
--add new maps down here with the same syntax

--------------------------------------------------

local map = game.GetMap() -- Get's the current map name
local workshopid = maplist[map]
-- Finds the workshop ID for the current map name from the table above

if( workshopid != nil )then
--If the map is in the table above, add it through workshop
print( "[WORKSHOP] Setting up maps. " ..map.. " workshop ID: " ..workshopid )
resource.AddWorkshop( workshopid )
else
--If not, ) then hope the server has FastDL or the client has the map
print( "[WORKSHOP] Not available for current map. Using FastDL instead hopefully..." )
end

There are a couple tricks when using this code:

The map name must be exactly the same map name as it appears on the file
The workshop id must be valid for the maps
This can go in the bottom of your resource.addworkshop file if you have one otherwise it goes in garrysmod\lua\autorun\server

  • Print