• Lazy loading addons using game.MountGMA
    6 replies, posted
I'm attempting to write an addon that will "lazy-load" addons so players don't have to sit in a connecting menu while workshop items download. The wiki has a page for game.MountGMA that specifies a way to download and mount an addon. I've attempted to implement it here: -- garrysmod/addons/lazyload/lua/autorun/sh_lazyworkshop.lua local workshopItems = { 248302805, 160250458, 104482086, 108424005, 108176967, 104815552, 264467687, 104548572, 180507408, 181283903, 183139624, 183140076, 112550250, 1169579845, 1605334558, 1525218777, 1222388614, 299444899, 576517817 } local function loadGMA( id )     steamworks.FileInfo( id, function( result )         steamworks.Download( result.fileid, true, function( name )             -- debugging             print( "[Lazy Load] Loading ", name )             game.MountGMA( name )         end )     end ) end hook.Add( "PlayerInitialSpawn", "lazy_load_workshop", function( ply )     print( "[Lazy Load] Attempting to start lazy loading addons." )     if CLIENT then         for _, workshopID in ipairs(workshopItems) do             loadGMA( workshopID )         end     end end ) This code is a rough proof-of-concept, but I cannot get it to work. When I connect to the server running this code, I see the "[Lazy Load] Attempting to start lazy loading addons." message in the server's console, but nothing is printed client-side. What am I doing wrong here? Any help is appreciated.
Downloads the Playable Piano addon and mounts the content. iirc it only mounts content to the filesystem so you can have access at the resources, not lua files, never sure why it would not load lua files, i might be wrong but this might be due those lua files aren't loaded in the string table that contains all lua files that are going to be sent to players You can try to search those files in client once you mount those and then trying to RunString on those
I think it was a symptom of attempting to hook PlayerInitialSpawn on the client. This updated code works: if CLIENT then     print( "[Lazy Load] Attempting to start lazy loading addons." )     for _, workshopID in ipairs(workshopItems) do         loadGMA( workshopID )     end end There are some minor texture errors, but I believe that shouldn't be an issue.
PlayerInitialSpawn is serverside hook
You probably want GM/InitPostEntity instead
I've run into a problem lazy-loading some addons with this method -- textures are missing and replaced with some other texture (not sure what it is). For example, FA:S does this: https://files.facepunch.com/forum/upload/172195/9e7d9864-e108-41a3-9dfc-17bf97c5842e/image.png I'm not sure how I could fix this issue aside from preloading the addon using resource.AddWorkshop(), any advice would be appreciated.
mat_specular probably changes it because it probably reloads texture files to find the specmaps, THEN realizes it cant find it. that's all the ideas i got on this concept :v but if i had to make an uneducated guess, id say youd have to somehow loop through all of the textures in the new addon and precache them somewhere, or force the client to run mat_reloadtexture <texture> or some command like that, exact name slips my mind.
Sorry, you need to Log In to post a reply to this thread.