This is a Lua library you are able to add to mods in order to modify P3D files dynamically. There are a couple of benefits of doing this over doing static edits in the CustomFiles
folder.
- If you're only changing 1 or 2 chunks in a file, it takes less space in your mod to edit it dynamically in Lua.
- If you want to change things based on a Mod Setting, you would have to create a static P3D file for every setting, whereas you can have a single file in Lua.
- Download the latest
P3D.zip
from https://github.com/Hampo/LuaP3DLib/releases. - Extract the contents to the
/Resources/lib
folder of your mod. - Add
dofile(GetModPath() .. "/Resources/lib/P3D2.lua")
to theCustomFiles.lua
of your mod. - Add
P3D.LoadChunks(GetModPath() .. "/Resources/lib/P3DChunks")
after the previous line inCustomFiles.lua
. - (Optional) Make an additional file called
P3DFunctions.lua
in the same lib folder to contain your P3D-related functions.- You will also need to do
dofile(GetModPath() .. "/Resources/lib/P3DFunctions.lua")
inCustomFiles.lua
.
- You will also need to do
- Add the following Authors to your
Meta.ini
:
[Author]
Name=Proddy
Website=https://github.com/Hampo/LuaP3DLib
Notes=P3D Class System
Group=LuaP3DLib
Credits=1
[Author]
Name=EnAppelsin
Website=https://github.com/EnAppelsin
Notes=Original P3D Lua idea
Group=LuaP3DLib
Credits=1
[Author]
Name=Lucas Cardellini
Website=https://lucasstuff.com/
Notes=P3D Chunk Structures
Group=LuaP3DLib
Credits=1
You can find complete mods in the Examples
folder.
local Path = GetPath()
local GamePath = "/GameData/" .. Path
local P3DFile = P3D.P3DFile(GamePath)
-- P3DFile now has `:GetChunk`, `:GetChunks`, `:GetChunkIndexed`, `:GetChunksIndexed`, `:AddChunk`, `RemoveChunk`
-- After modifications
P3DFile:Output()
for chunk in P3DFile:GetChunks(P3D.Identifiers.Locator) do -- You can find a full list of Identifiers in `P3D2.lua`
chunk.Position.X = chunk.Position.X + 20
end
for chunk in P3DFile:GetChunks(P3D.Identifiers.Locator, true) do -- You can find a full list of Identifiers in `P3D2.lua`
P3D:RemoveChunk(chunk)
end
local Path = GetPath()
local GamePath = "/GameData/" .. Path
local P3DFile = P3D.P3DFile(GamePath)
for chunk in P3DFile:GetChunks(P3D.Identifiers.Locator, true) do -- You can find a full list of Identifiers in `P3D2.lua`
P3D:RemoveChunk(chunk)
end
P3DFile:Output()