init project ep

This commit is contained in:
2026-06-08 16:17:11 +03:00
commit 09c2ae238e
515 changed files with 20648 additions and 0 deletions
@@ -0,0 +1,40 @@
math.lerp = function (a, b, t)
if type(a) ~= "number" then error(string.format("bad argument #1 to 'lerp' (number expected, got %s)", type(a)), 2) end
if type(b) ~= "number" then error(string.format("bad argument #2 to 'lerp' (number expected, got %s)", type(b)), 2) end
if type(t) ~= "number" then error(string.format("bad argument #3 to 'lerp' (number expected, got %s)", type(t)), 2) end
return a * (1 - t) + b * t
end
math.clamp = function (value, min, max)
if type(value) ~= "number" then error(string.format("bad argument #1 to 'clamp' (number expected, got %s)", type(value)), 2) end
if type(min) ~= "number" then error(string.format("bad argument #2 to 'clamp' (number expected, got %s)", type(min)), 2) end
if type(max) ~= "number" then error(string.format("bad argument #3 to 'clamp' (number expected, got %s)", type(max)), 2) end
return math.max(min, math.min(max, value))
end
math.round = function (value, decimals)
if type(value) ~= "number" then error(string.format("bad argument #1 to 'round' (number expected, got %s)", type(value)), 2) end
if type(decimals) ~= "number" then error(string.format("bad argument #2 to 'round' (number expected, got %s)", type(decimals)), 2) end
decimals = decimals or 0
local mult = 10 ^ decimals
return math.floor(value * mult + 0.5) / mult
end
math.sign = function (value)
if type(value) ~= "number" then error(string.format("bad argument #1 to 'sign' (number expected, got %s)", type(value)), 2) end
return value >= 0 and 1 or -1
end
math.remap = function (value, inMin, inMax, outMin, outMax)
if type(value) ~= "number" then error(string.format("bad argument #1 to 'remap' (number expected, got %s)", type(value)), 2) end
if type(inMin) ~= "number" then error(string.format("bad argument #2 to 'remap' (number expected, got %s)", type(inMin)), 2) end
if type(inMax) ~= "number" then error(string.format("bad argument #3 to 'remap' (number expected, got %s)", type(inMax)), 2) end
if type(outMin) ~= "number" then error(string.format("bad argument #4 to 'remap' (number expected, got %s)", type(outMin)), 2) end
if type(outMax) ~= "number" then error(string.format("bad argument #5 to 'remap' (number expected, got %s)", type(outMax)), 2) end
return outMin + (outMax - outMin) * ((value - inMin) / (inMax - inMin))
end
@@ -0,0 +1,28 @@
if true then return end
local descriptor = LuaUserData.RegisterType("Barotrauma.LuaCsSteam")
LuaUserData.AddMethod(descriptor, "GetWorkshopCollection", function (id, callback)
id = tostring(id)
Networking.RequestPostHTTP("https://api.steampowered.com/ISteamRemoteStorage/GetCollectionDetails/v1/", function (result)
local data = json.parse(result)
if data.response.collectiondetails[1].children == nil then
callback()
return
end
local workshopItems = {}
for key, value in pairs(data.response.collectiondetails[1].children) do
table.insert(workshopItems, value.publishedfileid)
end
if callback then
callback(workshopItems)
end
end,
"collectioncount=1&publishedfileids[0]=" .. id,
"application/x-www-form-urlencoded")
end)
@@ -0,0 +1,13 @@
string.startsWith = function(str, start)
if type(str) ~= "string" then error(string.format("bad argument #1 to 'startsWith' (string expected, got %s)", type(str)), 2) end
if type(start) ~= "string" then error(string.format("bad argument #2 to 'startsWith' (string expected, got %s)", type(start)), 2) end
return string.sub(str, 1, string.len(start)) == start
end
string.endsWith = function(str, ending)
if type(str) ~= "string" then error(string.format("bad argument #1 to 'endsWith' (string expected, got %s)", type(str)), 2) end
if type(ending) ~= "string" then error(string.format("bad argument #2 to 'endsWith' (string expected, got %s)", type(ending)), 2) end
return ending == "" or string.sub(str, -string.len(ending)) == ending
end
@@ -0,0 +1,86 @@
Util = {}
local itemDictionary = {}
local itemGroups = {}
local function AddItem(item)
for _, itemGroup in pairs(itemGroups) do
if itemGroup.func(item) then
table.insert(itemGroup.items, item)
end
end
local id = item.Prefab.Identifier.Value
if itemDictionary[id] == nil then
itemDictionary[id] = {}
end
table.insert(itemDictionary[id], item)
end
Hook.Add("item.created", "luaSetup.util.itemDictionary", function (item)
AddItem(item)
end)
Hook.Add("roundEnd", "luaSetup.util.itemDictionary", function (item)
itemDictionary = {}
for _, itemGroup in pairs(itemGroups) do
itemGroup.items = {}
end
end)
for _, item in pairs(Item.ItemList) do
AddItem(item)
end
Util.RegisterItemGroup = function(groupName, func)
if type(groupName) ~= "string" then
error(string.format("bad argument #1 to 'RegisterItemGroup' (string expected, got %s)", type(groupName)), 2)
end
if type(func) ~= "function" then
error(string.format("bad argument #2 to 'RegisterItemGroup' (function expected, got %s)", type(func)), 2)
end
local items = {}
for _, item in pairs(Item.ItemList) do
if func(item) then
table.insert(items, item)
end
end
itemGroups[groupName] = {
func = func,
items = items
}
end
Util.GetItemGroup = function(groupName)
if type(groupName) ~= "string" then
error(string.format("bad argument #1 to 'GetItemGroup' (string expected, got %s)", type(groupName)), 2)
end
if not itemGroups[groupName] then
error("bad argument #1 to 'GetItemGroup' couldn't find the specified groupName", 2)
end
return itemGroups[groupName].items or {}
end
Util.GetItemsById = function(id)
if id == nil then
error(string.format("bad argument #1 to 'GetItemsById' (string expected, got %s)", type(id)), 2)
end
return itemDictionary[id]
end
Util.FindClientCharacter = function(character)
if CLIENT and Game.IsSingleplayer then return nil end
for _, client in pairs(Client.ClientList) do
if client.Character == character then
return client
end
end
end