├── LICENSE ├── README.md └── lua └── autorun ├── cl_s_vis_controller.lua └── server └── sv_s_vis_controller.lua /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 @scuroin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple-Render-Distance 2 | Addon that allows you to change render distance of certain categories of entities on your server 3 | 4 | - Workshop: https://steamcommunity.com/sharedfiles/filedetails/?id=2513275664 5 | - GitHub: https://github.com/scuroinside/Simple-Render-Distance 6 | - Discord: http://ds.asg-project.ru 7 | -------------------------------------------------------------------------------- /lua/autorun/cl_s_vis_controller.lua: -------------------------------------------------------------------------------- 1 | if SERVER then AddCSLuaFile() return end 2 | local ExportSetting do 3 | local ExportFrame 4 | 5 | function ExportSetting() 6 | local w, h = 400, 320 7 | if IsValid(ExportFrame) then ExportFrame:Remove() end 8 | local frame = vgui.Create('DFrame') 9 | frame:SetTitle('#svc_export') 10 | frame:SetSizable(false) 11 | frame:MakePopup() 12 | frame:SetSize(w, h) 13 | frame:Center() 14 | 15 | local pnl = vgui.Create('RichText', frame) 16 | local cvars = { 17 | 'svc_caneditlevel', 'svc_performancemode', 'svc_disablereceiveshadows', 'svc_disbleshadowdepth', 18 | 'svc_disableshadows', 'svc_shadowdistance', 'svc_propmin', 'svc_playermin', 'svc_playermax', 19 | 'svc_npcmin', 'svc_npcmax', 'svc_vehiclemin', 'svc_vehiclemax', 'svc_weaponmin', 'svc_weaponmax', 20 | 'svc_doormin', 'svc_doormax', 'svc_miscmin', 'svc_miscmax' 21 | } 22 | 23 | do 24 | local form = '%s "%s"' 25 | pnl:SetFontInternal('DebugFixedSmall') 26 | 27 | for k, name in next, cvars do 28 | local str = form:format(name, GetConVarString(name)) 29 | cvars[k] = str 30 | pnl:AppendText(str) 31 | pnl:AppendText'\n' 32 | end 33 | end 34 | 35 | local str_values = table.concat(cvars, '\n') 36 | 37 | local btn2 = vgui.Create('DButton', frame) 38 | btn2:SetText('#svc_export_clipboard') 39 | btn2.DoClick = function() SetClipboardText(str_values) end 40 | 41 | local btn1 = vgui.Create('DButton', frame) 42 | btn1:SetText('#svc_export_file') 43 | btn1:SetTooltip('#svc_export_file_help') 44 | btn1.DoClick = function() 45 | file.Write('svc_export.txt', str_values) 46 | end 47 | 48 | pnl:SetPos(8, 32) 49 | pnl:SetSize(w - 16, h - 32 - 64) 50 | 51 | local x, y = w * .5, h - 64 + 8 52 | btn1:SetPos(x - 140, y) 53 | btn1:SetSize(140 - 4, 64 - 16) 54 | 55 | btn2:SetPos(x + 4, y) 56 | btn2:SetSize(140 - 4, 64 - 16) 57 | frame:RequestFocus() 58 | frame:InvalidateLayout() 59 | 60 | ExportFrame = frame 61 | end 62 | end 63 | 64 | local function SDCSettings(root) 65 | root:ClearControls() 66 | root:ControlHelp('#svc_notsingleplayer'):DockMargin(16, 8, 16, 16) 67 | 68 | local pnl = vgui.Create('ControlPanel') 69 | pnl:SetName('#svc_main') 70 | pnl:InvalidateLayout(true) 71 | pnl:AddControl('CheckBox', {Label = '#svc_caneditlevel', Command = 'svc_caneditlevel'}) 72 | pnl:AddControl('CheckBox', {Label = '#svc_performancemode', Command = 'svc_performancemode'}) 73 | 74 | local btn = pnl:Button('#svc_export') 75 | btn.DoClick = ExportSetting 76 | 77 | root:AddPanel(pnl) 78 | 79 | pnl = vgui.Create('ControlPanel') 80 | pnl:SetName('#svc_shadows') 81 | pnl:AddControl('CheckBox', {Label = '#svc_disablereceiveshadows', Command = 'svc_disablereceiveshadows'}) 82 | pnl:AddControl('CheckBox', {Label = '#svc_disbleshadowdepth', Command = 'svc_disbleshadowdepth'}) 83 | pnl:AddControl('CheckBox', {Label = '#svc_disableshadows', Command = 'svc_disableshadows'}) 84 | pnl:AddControl('Slider', {Label = '#svc_shadowdistance', Type = 'Integer', Command = 'svc_shadowdistance', Min = 0, Max = 3000}) 85 | pnl:InvalidateLayout(true) 86 | root:AddPanel(pnl) 87 | 88 | pnl = vgui.Create('ControlPanel') 89 | pnl:SetName('#svc_props') 90 | pnl:AddControl('Slider', {Label = '#svc_rendermin', Type = 'Integer', Command = 'svc_propmin', Min = -1, Max = 8000}) 91 | pnl:AddControl('Slider', {Label = '#svc_rendermax', Type = 'Integer', Command = 'svc_propmax', Min = 500, Max = 8000}) 92 | pnl:InvalidateLayout(true) 93 | root:AddPanel(pnl) 94 | 95 | pnl = vgui.Create('ControlPanel') 96 | pnl:SetName('#svc_players') 97 | pnl:AddControl('Slider', {Label = '#svc_rendermin', Type = 'Integer', Command = 'svc_playermin', Min = -1, Max = 8000}) 98 | pnl:AddControl('Slider', {Label = '#svc_rendermax', Type = 'Integer', Command = 'svc_playermax', Min = 500, Max = 8000}) 99 | pnl:InvalidateLayout(true) 100 | root:AddPanel(pnl) 101 | 102 | pnl = vgui.Create('ControlPanel') 103 | pnl:SetName('#svc_npcs') 104 | pnl:AddControl('Slider', {Label = '#svc_rendermin', Type = 'Integer', Command = 'svc_npcmin', Min = -1, Max = 8000}) 105 | pnl:AddControl('Slider', {Label = '#svc_rendermax', Type = 'Integer', Command = 'svc_npcmax', Min = 500, Max = 8000}) 106 | pnl:InvalidateLayout(true) 107 | root:AddPanel(pnl) 108 | 109 | pnl = vgui.Create('ControlPanel') 110 | pnl:SetName('#svc_vehicles') 111 | pnl:InvalidateLayout(true) 112 | pnl:AddControl('Slider', {Label = '#svc_rendermin', Type = 'Integer', Command = 'svc_vehiclemin', Min = -1, Max = 8000}) 113 | pnl:AddControl('Slider', {Label = '#svc_rendermax', Type = 'Integer', Command = 'svc_vehiclemax', Min = 500, Max = 8000}) 114 | pnl:InvalidateLayout(true) 115 | root:AddPanel(pnl) 116 | 117 | pnl = vgui.Create('ControlPanel') 118 | pnl:SetName('#svc_weapons') 119 | pnl:AddControl('Slider', {Label = '#svc_rendermin', Type = 'Integer', Command = 'svc_weaponmin', Min = -1, Max = 8000}) 120 | pnl:AddControl('Slider', {Label = '#svc_rendermax', Type = 'Integer', Command = 'svc_weaponmax', Min = 500, Max = 8000}) 121 | pnl:InvalidateLayout(true) 122 | root:AddPanel(pnl) 123 | 124 | pnl = vgui.Create('ControlPanel') 125 | pnl:SetName('#svc_doors') 126 | pnl:AddControl('Slider', {Label = '#svc_rendermin', Type = 'Integer', Command = 'svc_doormin', Min = -1, Max = 8000}) 127 | pnl:AddControl('Slider', {Label = '#svc_rendermax', Type = 'Integer', Command = 'svc_doormax', Min = 500, Max = 8000}) 128 | pnl:InvalidateLayout(true) 129 | root:AddPanel(pnl) 130 | 131 | pnl = vgui.Create('ControlPanel') 132 | pnl:SetName('#svc_misc') 133 | pnl:AddControl('Slider', {Label = '#svc_rendermin', Type = 'Integer', Command = 'svc_miscmin', Min = -1, Max = 8000}) 134 | pnl:AddControl('Slider', {Label = '#svc_rendermax', Type = 'Integer', Command = 'svc_miscmax', Min = 500, Max = 8000}) 135 | pnl:InvalidateLayout(true) 136 | root:AddPanel(pnl) 137 | end 138 | 139 | hook.Add('PopulateToolMenu', 'svc.PopulateToolMenu', function() 140 | spawnmenu.AddToolMenuOption('Utilities', 'Admin', 'RenderSettings', '#svc_settings', '', '', SDCSettings) 141 | end) 142 | 143 | hook.Add('AddToolMenuCategories', 'svc.AddToolMenuCategories', function() 144 | spawnmenu.AddToolCategory('Utilities', 'Admin', '#spawnmenu.utilities.admin') 145 | end) 146 | 147 | do 148 | local cc = GetConVarString('gmod_language') 149 | local add = language.Add 150 | if cc == 'ru' then 151 | add('svc_export', 'Экспортировать настройки') 152 | add('svc_export_clipboard', 'В буффер') 153 | add('svc_export_file', 'В файл') 154 | add('svc_export_file_help', 'Экспортирует настройки в ".../garrysmod/data/svc_export.txt"') 155 | 156 | add('svc_settings', 'Настройки рендера') 157 | add('svc_caneditlevel', 'Редактировать объекты карты') 158 | add('svc_performancemode', 'Отключить осколки объектов') 159 | add('svc_notsingleplayer', 'Эти параметры можно изменить только в одиночной игре') 160 | 161 | add('svc_disablereceiveshadows', 'Отключить тени на объектах') 162 | add('svc_disbleshadowdepth', 'Отключить тени объектов от фонарика') 163 | add('svc_disableshadows', 'Отключить тени объектов на карте') 164 | add('svc_shadowdistance', 'Дистанция теней') 165 | 166 | add('svc_shadows', 'Рендер теней') 167 | add('svc_props', 'Рендер объектов') 168 | add('svc_players', 'Рендер игроков') 169 | add('svc_npcs', 'Рендер NPC') 170 | add('svc_vehicles', 'Рендер автомобилей') 171 | add('svc_weapons', 'Рендер оружия') 172 | add('svc_doors', 'Рендер дверей') 173 | add('svc_misc', 'Рендер прочих объектов') 174 | add('svc_main', 'Основные настройки') 175 | 176 | add('svc_rendermin', 'Дистанция угасания') 177 | add('svc_rendermax', 'Дистанция отрисовки') 178 | else 179 | add('svc_export', 'Export settings') 180 | add('svc_export_clipboard', 'Clipboard') 181 | add('svc_export_file', 'File') 182 | add('svc_export_file_help', 'Exports your settings to ".../garrysmod/data/svc_export.txt"') 183 | 184 | add('svc_settings', 'Render settings') 185 | add('svc_caneditlevel', 'Allow edit map entities') 186 | add('svc_performancemode', 'Disable gibs') 187 | add('svc_notsingleplayer', 'All of these parameters can be changed only in singleplayer') 188 | 189 | add('svc_disablereceiveshadows', 'Disable entities receiving shadows') 190 | add('svc_disbleshadowdepth', 'Disable flashlight shadows') 191 | add('svc_disableshadows', 'Disable shadows on map surface') 192 | add('svc_shadowdistance', 'Shadows distance') 193 | 194 | add('svc_shadows', 'Shadows render') 195 | add('svc_props', 'Entities render') 196 | add('svc_players', 'Players render') 197 | add('svc_npcs', 'NPCs render') 198 | add('svc_vehicles', 'Vehicles render') 199 | add('svc_weapons', 'Weapons render') 200 | add('svc_doors', 'Doors render') 201 | add('svc_misc', 'Miscellaneous render') 202 | add('svc_main', 'Main settings') 203 | 204 | add('svc_rendermin', 'Fade distance') 205 | add('svc_rendermax', 'Render distance') 206 | end 207 | end 208 | 209 | do 210 | local fl = FCVAR_NEVER_AS_STRING + FCVAR_NOTIFY + FCVAR_REPLICATED + FCVAR_DONTRECORD 211 | CreateConVar('svc_caneditlevel', '0', '', fl, 0, 1) 212 | CreateConVar('svc_performancemode', '0', '', fl, 0, 1) 213 | CreateConVar('svc_disablereceiveshadows', '1', '', fl, 0, 1) 214 | CreateConVar('svc_disbleshadowdepth', '0', '', fl, 0, 1) 215 | CreateConVar('svc_disableshadows', '0', '', fl, 0, 1) 216 | CreateConVar('svc_shadowdistance', '500', '', fl, 0, 3000) 217 | CreateConVar('svc_propmin', '-1', '', fl, -1, 8000) 218 | CreateConVar('svc_propmax', '2500', '', fl, 500, 8000) 219 | CreateConVar('svc_playermin', '3000', '', fl, -1, 8000) 220 | CreateConVar('svc_playermax', '3000', '', fl, 500, 8000) 221 | CreateConVar('svc_npcmin', '3000', '', fl, -1, 8000) 222 | CreateConVar('svc_npcmax', '3000', '', fl, 500, 8000) 223 | CreateConVar('svc_vehiclemin', '-1', '', fl, -1, 8000) 224 | CreateConVar('svc_vehiclemax', '2500', '', fl, 500, 8000) 225 | CreateConVar('svc_weaponmin', '-1', '', fl, -1, 8000) 226 | CreateConVar('svc_weaponmax', '500', '', fl, 500, 8000) 227 | CreateConVar('svc_doormin', '-1', '', fl, -1, 8000) 228 | CreateConVar('svc_doormax', '3000', '', fl, 500, 8000) 229 | CreateConVar('svc_miscmin', '-1', '', fl, -1, 8000) 230 | CreateConVar('svc_miscmax', '500', '', fl, 500, 8000) 231 | end -------------------------------------------------------------------------------- /lua/autorun/server/sv_s_vis_controller.lua: -------------------------------------------------------------------------------- 1 | local cv_propmn, 2 | cv_propmx, 3 | cv_playermn, 4 | cv_playermx, 5 | cv_vehiclemn, 6 | cv_vehiclemx, 7 | cv_weaponmn, 8 | cv_weaponmx, 9 | cv_doormn, 10 | cv_doormx, 11 | cv_miscmn, 12 | cv_miscmx, 13 | cv_worldedit, 14 | cv_performancemode, 15 | cv_shadowdistance, 16 | cv_dontreceiveshadows, 17 | cv_disbleshadows, 18 | cv_disbledepth 19 | 20 | do 21 | local fl = FCVAR_ARCHIVE + FCVAR_NEVER_AS_STRING + FCVAR_NOTIFY + FCVAR_REPLICATED + FCVAR_DONTRECORD 22 | cv_worldedit = CreateConVar('svc_caneditlevel', '0', '', fl, 0, 1) 23 | cv_performancemode = CreateConVar('svc_performancemode', '0', '', fl, 0, 1) 24 | cv_dontreceiveshadows = CreateConVar('svc_disablereceiveshadows', '1', '', fl, 0, 1) 25 | cv_disbledepth = CreateConVar('svc_disbleshadowdepth', '0', '', fl, 0, 1) 26 | cv_disbleshadows = CreateConVar('svc_disableshadows', '0', '', fl, 0, 1) 27 | cv_shadowdistance = CreateConVar('svc_shadowdistance', '500', '', fl, 0, 3000) 28 | cv_propmn = CreateConVar('svc_propmin', '-1', '', fl, -1, 8000) 29 | cv_propmx = CreateConVar('svc_propmax', '2500', '', fl, 500, 8000) 30 | cv_playermn = CreateConVar('svc_playermin', '3000', '', fl, -1, 8000) 31 | cv_playermx = CreateConVar('svc_playermax', '3000', '', fl, 500, 8000) 32 | cv_npcmn = CreateConVar('svc_npcmin', '3000', '', fl, -1, 8000) 33 | cv_npcmx = CreateConVar('svc_npcmax', '3000', '', fl, 500, 8000) 34 | cv_vehiclemn = CreateConVar('svc_vehiclemin', '-1', '', fl, -1, 8000) 35 | cv_vehiclemx = CreateConVar('svc_vehiclemax', '2500', '', fl, 500, 8000) 36 | cv_weaponmn = CreateConVar('svc_weaponmin', '-1', '', fl, -1, 8000) 37 | cv_weaponmx = CreateConVar('svc_weaponmax', '500', '', fl, 500, 8000) 38 | cv_doormn = CreateConVar('svc_doormin', '-1', '', fl, -1, 8000) 39 | cv_doormx = CreateConVar('svc_doormax', '3000', '', fl, 500, 8000) 40 | cv_miscmn = CreateConVar('svc_miscmin', '-1', '', fl, -1, 8000) 41 | cv_miscmx = CreateConVar('svc_miscmax', '500', '', fl, 500, 8000) 42 | end 43 | 44 | do 45 | local _R = debug.getregistry() 46 | local SetKeyValue = _R.Entity.SetKeyValue 47 | local GetClass = _R.Entity.GetClass 48 | local CreatedByMap = _R.Entity.CreatedByMap 49 | 50 | local door_class = { 51 | prop_dynamic = true, 52 | prop_door_rotating = true, 53 | func_door_rotating = true, 54 | func_door = true 55 | } 56 | 57 | local prop_class = { 58 | prop_physics = true, 59 | prop_physics_multiplayer = true 60 | } 61 | 62 | local function SetupEntityVars(ent) 63 | if CreatedByMap(ent) and not cv_worldedit:GetBool() then return end 64 | 65 | ent:SetKeyValue('performancemode', cv_performancemode:GetString()) 66 | ent:SetKeyValue('disableshadows', cv_disbleshadows:GetString()) 67 | ent:SetKeyValue('shadowcastdist', cv_shadowdistance:GetString()) 68 | ent:SetKeyValue('disablereceiveshadows', cv_dontreceiveshadows:GetString()) 69 | ent:SetKeyValue('disableshadowdepth', cv_disbledepth:GetString()) 70 | 71 | if ent:IsPlayer() then 72 | ent:SetKeyValue('fademindist', cv_playermn:GetString()) 73 | ent:SetKeyValue('fademaxdist', cv_playermx:GetString()) 74 | return 75 | end 76 | 77 | if ent:IsNPC() then 78 | ent:SetKeyValue('fademindist', cv_npcmn:GetString()) 79 | ent:SetKeyValue('fademaxdist', cv_npcmx:GetString()) 80 | return 81 | end 82 | 83 | if ent:IsWeapon() then 84 | ent:SetKeyValue('fademindist', cv_weaponmn:GetString()) 85 | ent:SetKeyValue('fademaxdist', cv_weaponmx:GetString()) 86 | return 87 | end 88 | 89 | if ent:IsVehicle() then 90 | ent:SetKeyValue('fademindist', cv_vehiclemn:GetString()) 91 | ent:SetKeyValue('fademaxdist', cv_vehiclemx:GetString()) 92 | return 93 | end 94 | 95 | local class = GetClass(ent) 96 | if prop_class[class] then 97 | ent:SetKeyValue('fademindist', cv_propmn:GetString()) 98 | ent:SetKeyValue('fademaxdist', cv_propmx:GetString()) 99 | return 100 | end 101 | 102 | if door_class[class] then 103 | ent:SetKeyValue('fademindist', cv_doormn:GetString()) 104 | ent:SetKeyValue('fademaxdist', cv_doormx:GetString()) 105 | return 106 | end 107 | 108 | ent:SetKeyValue('fademindist', cv_miscmn:GetString()) 109 | ent:SetKeyValue('fademaxdist', cv_miscmx:GetString()) 110 | end 111 | 112 | local function CVarChanged(name, old, new) 113 | local tb, i = ents.GetAll(), 0 114 | 115 | while true do 116 | i = i + 1 117 | local ent = tb[i] 118 | if not ent then break end 119 | SetupEntityVars(ent) 120 | end 121 | end 122 | 123 | hook.Add('OnEntityCreated', 'svc.OnEntityCreated', SetupEntityVars) 124 | cvars.AddChangeCallback('svc_caneditlevel', CVarChanged) 125 | cvars.AddChangeCallback('svc_performancemode', CVarChanged) 126 | cvars.AddChangeCallback('svc_disablereceiveshadows', CVarChanged) 127 | cvars.AddChangeCallback('svc_disbleshadowdepth', CVarChanged) 128 | cvars.AddChangeCallback('svc_disableshadows', CVarChanged) 129 | cvars.AddChangeCallback('svc_shadowdistance', CVarChanged) 130 | cvars.AddChangeCallback('svc_propmin', CVarChanged) 131 | cvars.AddChangeCallback('svc_propmax', CVarChanged) 132 | cvars.AddChangeCallback('svc_playermin', CVarChanged) 133 | cvars.AddChangeCallback('svc_playermax', CVarChanged) 134 | cvars.AddChangeCallback('svc_npcmin', CVarChanged) 135 | cvars.AddChangeCallback('svc_npcmax', CVarChanged) 136 | cvars.AddChangeCallback('svc_vehiclemin', CVarChanged) 137 | cvars.AddChangeCallback('svc_vehiclemax', CVarChanged) 138 | cvars.AddChangeCallback('svc_weaponmin', CVarChanged) 139 | cvars.AddChangeCallback('svc_weaponmax', CVarChanged) 140 | cvars.AddChangeCallback('svc_doormin', CVarChanged) 141 | cvars.AddChangeCallback('svc_doormax', CVarChanged) 142 | cvars.AddChangeCallback('svc_miscmin', CVarChanged) 143 | cvars.AddChangeCallback('svc_miscmax', CVarChanged) 144 | end --------------------------------------------------------------------------------