• Print

Author Topic: Restrict workshop dupes  (Read 10191 times)

0 Members and 1 Guest are viewing this topic.

Offline //AG// Not Me

  • Newbie
  • *
  • Posts: 11
  • Karma: 1
Restrict workshop dupes
« on: October 18, 2013, 04:14:26 pm »
Hello, I was wondering how i would go about restricting workshop dupes, but letting people spawn in there own dupes. thanks

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Restrict workshop dupes
« Reply #1 on: October 18, 2013, 06:04:40 pm »
Replace your:
gamemodes\sandbox\gamemode\spawnmenu\creationmenu\content\contenttypes\dupes.lua with this:

Code: Lua
  1.  
  2. local HTML                              = nil
  3. local DupeInClipboard   = false;
  4.  
  5. spawnmenu.AddCreationTab( "#spawnmenu.category.dupes", function()
  6.  
  7.         HTML = vgui.Create( "DHTML" );
  8.                 JS_Language( HTML )
  9.                 HTML:SetAllowLua( true );
  10.                 HTML:OpenURL( "asset://garrysmod/html/dupes.html" );
  11.                 HTML:Call( "SetDupeSaveState( " .. tostring( DupeInClipboard ).. " );" );              
  12.  
  13.         ws_dupe = WorkshopFileBase( "dupe", { "dupe" } )
  14.         ws_dupe.HTML = HTML
  15.  
  16.         function ws_dupe:FetchLocal( offset, perpage )
  17.  
  18.                 local f = file.Find( "dupes/*.dupe", "MOD", "datedesc" )
  19.  
  20.                 local saves = {}
  21.  
  22.                 for k, v in pairs( f ) do
  23.  
  24.                         if ( k <= offset ) then continue end
  25.                         if ( k > offset + perpage ) then break end
  26.  
  27.                         local entry =
  28.                         {
  29.                                 file    = "dupes/" .. v,
  30.                                 name    = v:StripExtension(),
  31.                                 preview = "dupes/" .. v:StripExtension() .. ".jpg"
  32.                         }
  33.  
  34.                         table.insert( saves, entry );
  35.  
  36.                 end
  37.  
  38.                 local results =
  39.                 {
  40.                         totalresults    = #f,
  41.                         results                 = saves
  42.                 }
  43.  
  44.                 local json = util.TableToJSON( results, false );
  45.                 HTML:Call( "dupe.ReceiveLocal( "..json.." )" );
  46.  
  47.         end
  48.  
  49.         function ws_dupe:Arm( filename )
  50.  
  51.                 RunConsoleCommand( "dupe_arm", filename );
  52.  
  53.         end
  54.  
  55.         function ws_dupe:DownloadAndArm( id )
  56.  
  57.                 chat.AddText( Color(200,50,50), "Disabled Feature", Color(200,200,200), ": You are not allowed to spawn workshop dupes here." )
  58.                 --[[MsgN( "Downloading Dupe...\n" )
  59.                 steamworks.Download( id, true, function( name )
  60.  
  61.                         MsgN( "Finished - arming!\n" )
  62.                         ws_dupe:Arm( name );
  63.  
  64.                 end )]]
  65.  
  66.         end
  67.  
  68.         function ws_dupe:Publish( filename, imagename )
  69.  
  70.                 RunConsoleCommand( "dupe_publish", filename, imagename )
  71.  
  72.         end
  73.  
  74.         return HTML
  75.  
  76. end, "icon16/control_repeat_blue.png", 200 )
  77.  
  78.  
  79. hook.Add( "DupeSaveAvailable", "UpdateDupeSpawnmenuAvailable", function()
  80.  
  81.         DupeInClipboard = true;
  82.  
  83.         if ( !HTML ) then return end
  84.  
  85.         HTML:Call( "SetDupeSaveState( true );" );
  86.  
  87. end )
  88.  
  89. hook.Add( "DupeSaveUnavailable", "UpdateDupeSpawnmenuUnavailable", function()
  90.  
  91.         DupeInClipboard = false;
  92.  
  93.         if ( !HTML ) then return end
  94.  
  95.         HTML:Call( "SetDupeSaveState( false );" );
  96.  
  97. end )
  98.  
  99. hook.Add( "DupeSaved", "DuplicationSavedSpawnMenu", function()
  100.  
  101.         if ( !HTML ) then return end
  102.  
  103.         HTML:Call( "ShowLocalDupes();" );
  104.  
  105. end )
  106.  
  107.  
  108. concommand.Add( "dupe_show", function()
  109.  
  110.         g_SpawnMenu:OpenCreationMenuTab( "#spawnmenu.category.dupes" );
  111.  
  112.         timer.Simple( 1.0, function() if ( !IsValid( HTML ) ) then return end HTML:Call( "ShowLocalDupes();" ); end )
  113.  
  114. end, nil, "", { FCVAR_DONTRECORD } )
  115.  

  • Print