Script that Only Downloads the Current Workshop Map?

I need your guys’ help. I’m trying to help my friend set up a TTT server, and one problem we’ve come accross is that when we set up the workshop maps to download for clients with


resource.AddWorkshop( "workshop id" )

, all of the maps are downloaded when people first join the server.

I haven’t run a Gmod server in years, but I remember finding a script that basically said “if the map equals this, download this workshop addon (the map on the workshop)”. Each line of code was exactly the same, except each line was a different map until all the workshop maps were listed. This script made it so that if we weren’t on that map, it would skip to the next one, this would continue until it got to the map we were on and downloaded that map.

This saved new players a lot of time joining the server, but I no longer have that script and have no scripting knowledge. I was wondering if anyone out there knows what I’m talking about and can either redirect me to the script or post an example script that would do just that. Thanks!




local WorkshopMaps = {}
WorkshopMaps["ttt_whatevermapname"] = { workshopid = "workshop_id_here" }


if WorkshopMaps[ string.lower( game.GetMap() ) ] then
	resource.AddWorkshop( WorkshopMaps[ string.lower( game.GetMap() ) ].workshopid )
end



Also. I’m pretty sure this is suppose to go in the Developer Discussion thread. https://facepunch.com/forumdisplay.php?f=65

Thanks for the reply! I have a couple of questions about that script.

  1. So to add more maps, it would it be like…

local WorkshopMaps = {}
WorkshopMaps["ttt_equilibre"] = { workshopid = "284614653" }
WorkshopMaps["ttt_lost_temple_v2"] = { workshopid = "241365345" }
WorkshopMaps["ttt_canyon_a4"] = { workshopid = "224282233" }


if WorkshopMaps[ string.lower( game.GetMap() ) ] then
	resource.AddWorkshop( WorkshopMaps[ string.lower( game.GetMap() ) ].workshopid )
end

Correct?

  1. Can I put it in the same file with the other resource.AddWorkshop( “workshop id” ), or would it be it’s own file? Where do I put it?

Also, I don’t think this belongs in the Developer Discussion thread because I’m not really making anything. I’m just using maps and addons other people have made.

Question 1) Yes; new line per map with map name.
Question 2) You could drop it there, as long as you’re putting it in a server-side file.
You can either drop it in the same lua file your workshop collections are defined in, or make a new file (assuming you’re putting all of this within your /autorun/server/ folder).

Thanks man! I’ll give it a shot!

No problem - best of luck.