Added more util functions
This commit is contained in:
@@ -4,9 +4,6 @@ local AddCallMetaTable = LuaSetup.LuaUserData.AddCallMetaTable
|
||||
local CreateStatic = LuaSetup.LuaUserData.CreateStatic
|
||||
local CreateEnum = LuaSetup.LuaUserData.CreateEnumTable
|
||||
|
||||
require("DefaultLib/Utils/Math")
|
||||
require("DefaultLib/Utils/SteamApi")
|
||||
|
||||
defaultLib["SByte"] = CreateStatic("Barotrauma.LuaSByte", true)
|
||||
defaultLib["Byte"] = CreateStatic("Barotrauma.LuaByte", true)
|
||||
defaultLib["Int16"] = CreateStatic("Barotrauma.LuaInt16", true)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
string.startsWith = function(str, start)
|
||||
return string.sub(str, 1, string.len(start)) == start
|
||||
end
|
||||
|
||||
string.endsWith = function(str, ending)
|
||||
return ending == "" or string.sub(str, -string.len(ending)) == ending
|
||||
end
|
||||
38
Barotrauma/BarotraumaShared/Lua/DefaultLib/Utils/Util.lua
Normal file
38
Barotrauma/BarotraumaShared/Lua/DefaultLib/Utils/Util.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
Util = {}
|
||||
|
||||
local itemDictionary = {}
|
||||
|
||||
local function AddItem(item)
|
||||
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 = {}
|
||||
end)
|
||||
|
||||
for _, item in pairs(Item.ItemList) do
|
||||
AddItem(item)
|
||||
end
|
||||
|
||||
Util.GetItemsById = function(id)
|
||||
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
|
||||
@@ -61,6 +61,11 @@ if false then
|
||||
end
|
||||
end
|
||||
|
||||
require("DefaultLib/Utils/Math")
|
||||
require("DefaultLib/Utils/String")
|
||||
require("DefaultLib/Utils/Util")
|
||||
require("DefaultLib/Utils/SteamApi")
|
||||
|
||||
LuaSetup = nil
|
||||
|
||||
require("ModLoader")
|
||||
@@ -1,11 +1,11 @@
|
||||
# LuaForBarotrauma
|
||||
This is a Barotrauma modification that adds Lua modding support.
|
||||
# LuaCsForBarotrauma
|
||||
This is a Barotrauma modification that adds Lua and Cs modding support.
|
||||
|
||||
### Online Documentation: https://evilfactory.github.io/LuaCsForBarotrauma
|
||||
### VS Code Documentation: https://gitee.com/zhurengong/btlua-docs
|
||||
### Discord: https://discord.gg/f9zvNNuxu9
|
||||
|
||||
### This project uses a forked version of Moonsharp: https://github.com/evilfactory/moonsharp
|
||||
### This project uses a fork of Moonsharp: https://github.com/evilfactory/moonsharp
|
||||
|
||||
# Barotrauma
|
||||
|
||||
|
||||
Reference in New Issue
Block a user