Skip to content

Instantly share code, notes, and snippets.

@samcadams
Last active August 7, 2021 21:58
Show Gist options
  • Save samcadams/9b563aa053386f404dfb48d179105575 to your computer and use it in GitHub Desktop.
Save samcadams/9b563aa053386f404dfb48d179105575 to your computer and use it in GitHub Desktop.
gmod playermodel content enforcer
--Throw in addons/contentenforcer/lua/autorun
--Replace model name with path to ATLEAST ONE model
--Replace numerical id with the relative workshop id
--Upon player join they will be prompted to download missing content if any content is detected missing
--I'm just including my default models that I had
--Make sure to GMAD your player model content out and throw it on the server. FastDL sync but don't add it to resources.lua
--Content is downloaded the the garrymod/cache folder and automatically retrieved upon rejoin. If the cache file is missing
--or otherwise incorrect it'll redownload it. This means if your players rejoin they usually shouldnt have to redownload anything
--unless they wiped content.
--You can also add content without restarting the server, add the content to server, FastDL then update this script
--Script will automatically reload and all clients will detect the missing content
--Sometimes you'll get issues with the content not fully loading without a map change. Just try to map change if hotloading like that.
--Also recommended to have a steam workshop collection with all playermodels so people can 100% forsure without a problem download the content.
--This method isn't always 100% so always have the collection if people need it. This helps immensely though.
local knownModels = {
["models/kryptonite/ben_swolo/ben_swolo.mdl"] = 1269812661,
["models/player/kuma/taliban_rpg.mdl"] = 208348503,
["models/player/ratdock/squidwod_tennicles.mdl"] = 1787778076,
["models/player/howardalien.mdl"] = 1520414736,
["models/amusquiz/player/cmplayer.mdl"] = 800564435,
["models/player/waluigi/models/waluigi.mdl"] = 1729241291,
["models/cowboah/trainhopper.mdl"] = 1583140310,
["models/player/comradebear/comradebear.mdl"] = 465449464,
["models/combine_elite_guard.mdl"] = 1357960725,
["models/player/agent_47.mdl"] = 157660704,
["models/grandtheftauto5/trevor.mdl"] = 216408135,
["models/player/stanmcg/handguy/handguy_playermodel.mdl"] = 1574071896,
["models/player/nosaczt37/nosacz.mdl"] = 1286716330,
["models/player/stanmcg/blockhead_bot/blockhead_bot_playermodel.mdl"] = 1636700119,
}
local prompted = false
function ContentPrompt()
if not prompted then
local frame = vgui.Create("DFrame")
frame:SetSize(250, 100)
frame:SetTitle("Content Required")
frame:ShowCloseButton(true)
frame:Center()
local reason = vgui.Create("DLabel", frame)
reason:SetText("You're missing content required to enjoy \nthis server fully. Installing content will fix most errors.")
reason:SizeToContents()
reason:SetPos(5, 32)
local sendit = vgui.Create("DButton", frame)
sendit:SetPos(5, 70)
sendit:SetSize(240, 25)
sendit:SetText("Download Missing Content")
sendit.DoClick = function()
chat.AddText(Color( 255, 0, 0 ), "[CONTENT ENFORCER] ", Color(255, 255,0), "Great! We're downloading your content in the background. Lag may be possible.")
ValidateContent()
frame:Close()
end
frame:MakePopup()
prompted = true
end
end
function ValidateContent()
for uri,wkshp in pairs(knownModels) do
if not util.IsValidModel(uri) then
print("[CONTENT ENFORCER] Verifying content")
steamworks.FileInfo( wkshp, function( result )
if file.Exists("cache/workshop/"..result["fileid"]..".cache", "GAME") then
print("[CONTENT ENFORCER] Mounting content from cache.")
local success, files = game.MountGMA( "cache/workshop/"..result["fileid"]..".cache" )
if result then
print("[CONTENT ENFORCER] Mounted content successfully")
else
print("[CONTENT ENFORCER] Failed to mount content: "..uri.."="..wkshp)
end
else
print("[CONTENT ENFORCER] Downloading content...")
steamworks.Download( result.fileid, true, function( name )
PrintTable(result)
print (name)
if name == nil then
print("[CONTENT ENFORCER] Failed to mount content: "..uri.."="..wkshp)
else
local success, files = game.MountGMA( name )
if result then
print("[CONTENT ENFORCER] Mounted content successfully")
else
print("[CONTENT ENFORCER] Failed to mount content: "..uri.."="..wkshp)
chat.AddText(Color( 255, 0, 0 ), "[CONTENT ENFORCER] ", Color(255, 255,0), "Some content failed to download. Please contact Fires")
end
end
end )
end
end )
end
end
chat.AddText(Color( 255, 0, 0 ), "[CONTENT ENFORCER] ", Color(255, 255,0), "Content download completed.")
end
function ContentCheck()
for uri,wkshp in pairs(knownModels) do
if not util.IsValidModel(uri) then
print("[CONTENT ENFORCER] Player missing content: "..uri)
steamworks.FileInfo( wkshp, function( result )
if file.Exists("cache/workshop/"..result["fileid"]..".cache", "GAME") then
print("[CONTENT ENFORCER] Mounting content from cache.")
local success, files = game.MountGMA( "cache/workshop/"..result["fileid"]..".cache" )
if result then
print("[CONTENT ENFORCER] Mounted content successfully")
else
print("[CONTENT ENFORCER] Failed to mount content: "..uri.."="..wkshp)
chat.AddText(Color( 255, 0, 0 ), "[CONTENT ENFORCER] ", Color(255, 255,0), "Some local content failed to mount. Please contact Fires")
end
else
ContentPrompt()
return true
end
end)
end
end
print("[CONTENT ENFORCER] Client has all content")
return false
end
if SERVER then return end
timer.Simple(0.1, ContentCheck)
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment