Залив
This commit is contained in:
104
lua/autorun/mw_assets/attachments.lua
Normal file
104
lua/autorun/mw_assets/attachments.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
MW_ATTS = {}
|
||||
|
||||
function GetAttachmentBaseClass(base)
|
||||
MW_ATTS[base] = MW_ATTS[base] || {}
|
||||
|
||||
return MW_ATTS[base]
|
||||
end
|
||||
|
||||
function LoadAttachment(path, fileName)
|
||||
ATTACHMENT = {}
|
||||
|
||||
if (mw_utils.CompileFile(path..fileName)) then
|
||||
local name = string.Replace(fileName, ".lua", "")
|
||||
ATTACHMENT.ClassName = name
|
||||
ATTACHMENT.Folder = path
|
||||
table.Merge(GetAttachmentBaseClass(name), table.Copy(ATTACHMENT))
|
||||
end
|
||||
end
|
||||
|
||||
local oldModel = Model
|
||||
function Model(dir) --sorry
|
||||
if (GetConVar("mgbase_precacheatts"):GetInt() > 0) then
|
||||
util.PrecacheModel(dir)
|
||||
end
|
||||
return dir
|
||||
end
|
||||
|
||||
local function loadAttachments(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
LoadAttachment(dir, v)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadAttachments(dir..v)
|
||||
end
|
||||
end
|
||||
|
||||
loadAttachments("weapons/mg_base/modules/attachmentss")
|
||||
Model = oldModel
|
||||
|
||||
--check baseclass
|
||||
local function checkBaseClassInAttachments()
|
||||
for name, att in pairs(MW_ATTS) do
|
||||
if (istable(name)) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: You may have defined BaseClass twice! "..(name.Name || "error class"))
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
|
||||
if (name != "att_base") then
|
||||
if (att.Base == nil) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: "..name.." doesn't inherit from anything! This will cause problems...")
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
|
||||
if (att.Base == name) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: You are inheriting from self (Base = myself)! This would freeze your game. ("..name..")")
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
|
||||
if (MW_ATTS[att.Base] == nil) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: "..name.." is trying to inherit from missing attachment! ("..(att.Base || "missing class")..")")
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
checkBaseClassInAttachments()
|
||||
|
||||
--inherit
|
||||
local function inherit(current, base)
|
||||
for k, v in pairs(base) do
|
||||
if (!istable(v)) then
|
||||
if (current[k] == nil) then
|
||||
current[k] = v
|
||||
end
|
||||
else
|
||||
if (current[k] == nil) then
|
||||
current[k] = {}
|
||||
end
|
||||
inherit(current[k], v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function DoAttachmentInheritance(att)
|
||||
local baseClass = MW_ATTS[att.Base]
|
||||
while (baseClass != nil) do
|
||||
inherit(att, baseClass)
|
||||
baseClass = MW_ATTS[baseClass.Base]
|
||||
end
|
||||
end
|
||||
|
||||
local function finishAttachments()
|
||||
for name, att in pairs(MW_ATTS) do
|
||||
DoAttachmentInheritance(att)
|
||||
end
|
||||
end
|
||||
finishAttachments()
|
||||
10
lua/autorun/mw_assets/favorites.lua
Normal file
10
lua/autorun/mw_assets/favorites.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
AddCSLuaFile()
|
||||
|
||||
if (CLIENT) then
|
||||
MW_FAVORITES = {}
|
||||
|
||||
--load favs
|
||||
if (file.Exists("mwbase/favorites.json", "DATA")) then
|
||||
MW_FAVORITES = util.JSONToTable(file.Read("mwbase/favorites.json", "DATA"))
|
||||
end
|
||||
end
|
||||
29
lua/autorun/mw_assets/injectors.lua
Normal file
29
lua/autorun/mw_assets/injectors.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
|
||||
MW_ATT_INJECTORS = {}
|
||||
|
||||
local function loadInjectors(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
INJECTOR = {}
|
||||
|
||||
local name = string.Replace(v, ".lua", "")
|
||||
if (mw_utils.CompileFile(dir..v)) then
|
||||
|
||||
INJECTOR.ClassName = name
|
||||
|
||||
if (!table.IsEmpty(INJECTOR)) then
|
||||
MW_ATT_INJECTORS[name] = table.Copy(INJECTOR)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadInjectors(dir..v)
|
||||
end
|
||||
end
|
||||
loadInjectors("weapons/mg_base/modules/injectors")
|
||||
68
lua/autorun/mw_assets/presets.lua
Normal file
68
lua/autorun/mw_assets/presets.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
|
||||
MW_PRESETS = {}
|
||||
|
||||
local function loadPresets(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
PRESET = {}
|
||||
|
||||
local name = string.Replace(v, ".lua", "")
|
||||
if (mw_utils.CompileFile(dir..v)) then
|
||||
PRESET.ClassName = name
|
||||
PRESET._bUserGenerated = false
|
||||
|
||||
if (!table.IsEmpty(PRESET)) then
|
||||
MW_PRESETS[name] = table.Copy(PRESET)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadPresets(dir..v)
|
||||
end
|
||||
end
|
||||
loadPresets("weapons/mg_base/modules/presets")
|
||||
|
||||
if (CLIENT) then
|
||||
local function loadPresetsFromData(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "DATA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".json")) then
|
||||
local name = string.Replace(v, ".json", "")
|
||||
local preset = util.JSONToTable(file.Read(dir..v))
|
||||
|
||||
if (preset == nil || table.IsEmpty(preset)) then
|
||||
continue
|
||||
end
|
||||
|
||||
if (preset.Name == nil || preset.SWEP == nil || preset.Attachments == nil) then
|
||||
continue
|
||||
end
|
||||
|
||||
if (!isstring(preset.Name) || !isstring(preset.SWEP)) then
|
||||
continue
|
||||
end
|
||||
|
||||
if (!istable(preset.Attachments)) then
|
||||
continue
|
||||
end
|
||||
|
||||
preset.ClassName = name
|
||||
preset._bUserGenerated = true
|
||||
|
||||
MW_PRESETS[name] = table.Copy(preset)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadPresetsFromData(dir..v)
|
||||
end
|
||||
end
|
||||
loadPresetsFromData("mwbase/presets")
|
||||
end
|
||||
35
lua/autorun/mw_assets/rigs.lua
Normal file
35
lua/autorun/mw_assets/rigs.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
|
||||
MW_RIGS = {}
|
||||
MW_GLOVES = {}
|
||||
|
||||
local function loadRigs(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
RIG = {}
|
||||
GLOVE = {}
|
||||
|
||||
local name = string.Replace(v, ".lua", "")
|
||||
if (mw_utils.CompileFile(dir..v)) then
|
||||
if (!table.IsEmpty(RIG)) then
|
||||
MW_RIGS[name] = table.Copy(RIG)
|
||||
end
|
||||
|
||||
if (!table.IsEmpty(GLOVE)) then
|
||||
MW_GLOVES[name] = table.Copy(GLOVE)
|
||||
end
|
||||
end
|
||||
|
||||
RIG = nil
|
||||
GLOVE = nil
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadRigs(dir..v)
|
||||
end
|
||||
end
|
||||
loadRigs("weapons/mg_base/modules/rigs")
|
||||
89
lua/autorun/mw_loader.lua
Normal file
89
lua/autorun/mw_loader.lua
Normal file
@@ -0,0 +1,89 @@
|
||||
CreateConVar("mgbase_precacheatts", "0", FCVAR_ARCHIVE + FCVAR_REPLICATED, "Attachments limit.", 0, 1)
|
||||
require("mw_utils")
|
||||
|
||||
local function IncludeDir(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if string.EndsWith(v, ".lua") then
|
||||
AddCSLuaFile(dir..v)
|
||||
include(dir..v)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
IncludeDir(dir..v)
|
||||
end
|
||||
end
|
||||
|
||||
CHAN_ATMO = 137
|
||||
CHAN_REFLECTION = 138
|
||||
CHAN_CASINGS = 139
|
||||
CHAN_TRIGGER = 140
|
||||
CHAN_MINIGUNFIRE = 141
|
||||
CHAN_MAGAZINEDROP = 142
|
||||
CHAN_WPNFOLEY = 143
|
||||
|
||||
IncludeDir("weapons/mg_base/modules/sounds")
|
||||
|
||||
CUSTOMIZATION_COLOR_COMMON = Color(0, 220, 30, 255)
|
||||
CUSTOMIZATION_COLOR_LEGENDARY = Color(255, 175, 0, 255)
|
||||
CUSTOMIZATION_COLOR_EPIC = Color(255, 0, 150, 255)
|
||||
CUSTOMIZATION_COLOR_RARE = Color(0, 175, 255, 255)
|
||||
|
||||
SLOT_CONVERSIONS = -999
|
||||
|
||||
include("mw_assets/rigs.lua")
|
||||
include("mw_assets/attachments.lua")
|
||||
include("mw_assets/injectors.lua")
|
||||
include("mw_assets/presets.lua")
|
||||
include("mw_assets/favorites.lua")
|
||||
|
||||
hook.Call("MW19_OnAssetsLoaded")
|
||||
|
||||
hook.Add("PreRegisterSWEP", "MW19_PreRegisterSWEP", function(swep, class)
|
||||
if (swep.Customization != nil) then
|
||||
|
||||
--give our sweps their tracer names
|
||||
if !swep.Bullet.TracerName then
|
||||
if swep.SubCategory == "Shotguns" then
|
||||
swep.Bullet.TracerName = "mgbase_tracer_slow"
|
||||
elseif swep.SubCategory == "Sniper Rifles" then
|
||||
swep.Bullet.TracerName = "mgbase_tracer_fast"
|
||||
elseif swep.SubCategory == "Pistols" || swep.SubCategory == "Submachine Guns" then
|
||||
swep.Bullet.TracerName = "mgbase_tracer_small"
|
||||
else
|
||||
swep.Bullet.TracerName = "mgbase_tracer"
|
||||
end
|
||||
end
|
||||
|
||||
--check if we have missing attachments and if yes remove em
|
||||
for slot, atts in pairs(swep.Customization) do
|
||||
if (isstring(slot)) then --old sweps
|
||||
mw_utils.ErrorPrint("PreRegisterSWEP: "..swep.Folder.." is using old base! SWEP will not show up in menu...")
|
||||
return false --bye
|
||||
end
|
||||
|
||||
local newAtts = table.Copy(atts)
|
||||
|
||||
for i, attClass in pairs(atts) do
|
||||
if (!isstring(attClass)) then --old sweps
|
||||
mw_utils.ErrorPrint("PreRegisterSWEP: "..swep.Folder.." is using old base! SWEP will not show up in menu...")
|
||||
swep = {}
|
||||
return false --bye
|
||||
end
|
||||
|
||||
if (MW_ATTS[attClass] == nil) then
|
||||
mw_utils.ErrorPrint("PreRegisterSWEP: "..swep.Folder.." tried loading an attachment that doesn't exist ("..attClass..")!")
|
||||
table.remove(newAtts, i)
|
||||
end
|
||||
end
|
||||
|
||||
if (#newAtts <= 0) then
|
||||
table.remove(swep.Customization, slot)
|
||||
else
|
||||
swep.Customization[slot] = newAtts
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
52
lua/autorun/mw_ltl.lua
Normal file
52
lua/autorun/mw_ltl.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
-- Based on Zombie Survival Translation Library
|
||||
-- https://github.com/JetBoom/zombiesurvival/blob/master/gamemodes/zombiesurvival/gamemode/sh_translate.lua
|
||||
|
||||
MWBLTL = {}
|
||||
|
||||
local Languages = {}
|
||||
local Translations = {}
|
||||
local AddingLanguage
|
||||
|
||||
function MWBLTL.GetTranslations(short)
|
||||
return Translations[short] || Translations["en"]
|
||||
end
|
||||
|
||||
function MWBLTL.AddLanguage(short, long)
|
||||
Languages[short] = long
|
||||
Translations[short] = Translations[short] or {}
|
||||
AddingLanguage = short
|
||||
end
|
||||
|
||||
function MWBLTL.AddTranslation(id, text)
|
||||
if (not AddingLanguage or not Translations[AddingLanguage]) then return end
|
||||
|
||||
Translations[AddingLanguage][id] = text
|
||||
end
|
||||
|
||||
function MWBLTL.Get(id)
|
||||
return MWBLTL.GetTranslations(GetConVar("gmod_language"):GetString())[id]
|
||||
end
|
||||
|
||||
function MWBLTL.LoadingServerFiles(path)
|
||||
if (SERVER) then include(path) end
|
||||
end
|
||||
|
||||
function MWBLTL.LoadingClientFiles(path)
|
||||
if (SERVER) then AddCSLuaFile(path) end
|
||||
if (CLIENT) then include(path) end
|
||||
end
|
||||
|
||||
function MWBLTL.LoadingSharedFiles(path)
|
||||
MWBLTL.LoadingServerFiles(path)
|
||||
MWBLTL.LoadingClientFiles(path)
|
||||
end
|
||||
|
||||
local dir = "weapons/mg_base/modules"
|
||||
for _, name in pairs(file.Find(dir.."/languages/*.lua", "LUA")) do
|
||||
MWBLTL.LANGUAGE = {}
|
||||
MWBLTL.LoadingSharedFiles(dir.."/languages/"..name)
|
||||
for k, v in pairs(MWBLTL.LANGUAGE) do
|
||||
MWBLTL.AddTranslation(k, v)
|
||||
end
|
||||
MWBLTL.LANGUAGE = nil
|
||||
end
|
||||
77
lua/autorun/mw_matproxy.lua
Normal file
77
lua/autorun/mw_matproxy.lua
Normal file
@@ -0,0 +1,77 @@
|
||||
AddCSLuaFile()
|
||||
|
||||
if SERVER then return end
|
||||
|
||||
local lastPos = Vector()
|
||||
local lastValue = 0
|
||||
local lerp = Lerp
|
||||
matproxy.Add( {
|
||||
name = "MwEnvMapTint",
|
||||
|
||||
init = function(self, mat, values)
|
||||
local color = {1, 1, 1}
|
||||
|
||||
if (values.color != nil) then
|
||||
color = string.Explode(" ", string.Replace(string.Replace(values.color, "[", ""), "]", ""))
|
||||
end
|
||||
|
||||
self.min = values.min || 0
|
||||
self.max = values.max || 1
|
||||
self.color = Vector(color[1], color[2], color[3])
|
||||
mat:SetTexture("$envmap", values.envmap || "viper/shared/envmaps/specularity_50")
|
||||
end,
|
||||
|
||||
bind = function(self, mat, ent)
|
||||
if (!IsValid(ent)) then return end
|
||||
|
||||
if (!lastPos:IsEqualTol(ent:GetPos(), 1)) then
|
||||
local c = render.GetLightColor(ent:GetPos())
|
||||
lastValue = (c.x * 0.2126) + (c.y * 0.7152) + (c.z * 0.0722)
|
||||
lastValue = math.min(lastValue * 2, 1)
|
||||
lastPos = ent:GetPos()
|
||||
end
|
||||
|
||||
ent.m_MwEnvMapTint = lerp(10 * RealFrameTime(), ent.m_MwEnvMapTint || 0, lastValue)
|
||||
mat:SetVector("$envmaptint", self.color * lerp(ent.m_MwEnvMapTint, self.min, self.max))
|
||||
end
|
||||
})
|
||||
|
||||
matproxy.Add( {
|
||||
name = "MwCamo",
|
||||
|
||||
init = function(self, mat, values)
|
||||
end,
|
||||
|
||||
bind = function(self, mat, ent)
|
||||
--[[if (!IsValid(ent)) then return end
|
||||
|
||||
mat:SetInt("$detailblendmode", 0)
|
||||
mat:SetFloat("$detailblendfactor", 0)
|
||||
|
||||
if (ent.mw_Camo == nil || ent.mw_Camo == "") then return end
|
||||
|
||||
mat:SetInt("$detailblendmode", 4)
|
||||
mat:SetFloat("$detailblendfactor", 1)
|
||||
mat:SetTexture("$detail", ent.mw_Camo)]]
|
||||
end
|
||||
})
|
||||
|
||||
matproxy.Add( {
|
||||
name = "MwSight",
|
||||
|
||||
init = function(self, mat, values)
|
||||
end,
|
||||
|
||||
bind = function(self, mat, ent)
|
||||
if (!IsValid(ent)) then return end
|
||||
|
||||
if (ent.mw_Aim == nil) then
|
||||
mat:SetInt("$cloakpassenabled", 0)
|
||||
mat:SetFloat("$cloakfactor", 0)
|
||||
else
|
||||
mat:SetInt("$cloakpassenabled", 1)
|
||||
mat:SetFloat("$cloakfactor", math.Round(ent.mw_Aim))
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user