Hey,
I added a workshop collection with >100 Items to my Garry's Mod Server and I want to force clients to download all Items if they join the server.
I could write a .lua with resource.AddWorkshop("Id") for every item into lua/autorun/server/ but that would take days and I would have to change this file everytime I add or delete items from the collection...
So i found a code (I allready put in the collection ID [884764080]:
[code] function util.GetWorkshopCollectionIDs(collectionid,callback)
if collectionid == nil || callback == nil then return end
http.Fetch(
"http://steamcommunity.com/sharedfiles/filedetails/?id="..collectionid,
function(source)
local source_ = string.Explode("<div class=\"workshopItem\">",source)
local t = {}
for k, v in pairs(source_) do
local source__ = string.Explode("\"><div",v)
local insert = string.Explode("id=",source__[1])[2]
table.insert(t,insert)
end
table.remove(t,1)
callback(t)
end,
function()
return false
end
);
end
util.GetWorkshopCollectionIDs(884764080,function(ids)
for k, v in pairs(ids) do
resource.AddWorkshop(v)
end
end);[/code]
I put this code as workshop.lua into lua/autorun/server/
But somehow this does not force clients to download the workshop collection.
What am I doing wrong?
[URL="https://wiki.garrysmod.com/page/Workshop_for_Dedicated_Servers"]No reason to complicate things[/URL]
This is how to force the Server to download the collection...
I want to force the clients to download the collection.
Thank you.
My idea is slow because of the delay caused by webpage connection, right?
Make a single addon with everything you need and then do what JasonMan told you to do. You'll also want to add this to the client. Stops you needing a massive list. Also if you're actually trying to truly force them to do something just remember that you can't force the client to do anything.
A little tip use this website to get the lua file that you would use in the autorun file
[URL]http://www.configcreator.com/create/gmod/resources.lua[/URL]
-Edit
Didnt see the website was posted already XD
This code will force download of all server addons (which has been downloaded from Workshop collection). But before you should connect your server to one of collections ([url]https://wiki.garrysmod.com/page/Workshop_for_Dedicated_Servers[/url]).
Put it in a file in autorun\server folder and restart your server.
[CODE]
-- Purpose: Restores Workshop ID from addon's filename, if wsid equals 0
local function restoreWSID( addon )
if tonumber( addon.wsid ) > 0 then return addon.wsid end
return string.match( addon.file, "[%d]+" ) or 0
end
local function updateClientAddons()
local addons = engine.GetAddons()
if table.Count( addons ) <= 0 then return end
for _, addon in pairs( addons ) do
if addon.mounted then
local id = restoreWSID( addon )
if tonumber( id ) == 0 then continue end
resource.AddWorkshop( id )
end
end
end
hook.Add( "InitPostEntity", "WorkshopClientInit", updateClientAddons ) -- Can be Initialize too
[/CODE]
Rofl... Please, give the choice to the player if they want to download or not addons... Cause 3go of addons with a poor connection (if you force the download before join ofc) = "Raaaa f*** off" ~disconnected~
Juste put on the famouse "ressources.lua" the base hud addon content.
Make a little scripte who look at cache and downloads/server if addon is here and mount, then make a for loop to download missing addon.
it's may be nice for the no-fibre players ^^.
(engine.GetAddons is realy usefull for this think)
I really wish gmod would make the client stream in content while they have already downloaded the essentials to join map/gamemode files.
Sorry, you need to Log In to post a reply to this thread.