Forum Mod Bakery Docs

Dynamically load level locators file (or any P3D file)

Posted in Support
Please login to contribute to the conversation.
Hello SHAR modding community!

I'm trying to load different level1 locator files (copies of 'art/missions/level01/level.p3d') based on a certain condition.
In example:


if SomeChoice == 1 then
    Game.LoadP3DFile("\\Mods\\" .. GetModName() .. "\\Resources\\level01\\custom.p3d");

The game crashes on level load, with a ton of similar messages:
  • Locator type 3 'level1_carstart' not found for 'InitLevelPlayerVehicle' command
  • A crash occurred in the following script: scripts\missions\level01\leveli.mfk (line 5); Script command InitLevelPlayerVehicle, Arg list famil_v, level1_carstart, DEFAULT

The 'custom.p3d' is an exact copy of the original file (for now). I don't understand why it can't find the locator types.

I'm having some trouble understanding how it all works. I'm new to SHAR modding, but I'm quite, if I can say, an experienced programmer.
If anyone can give me an explanation or can point me to a more in-depth documentation or discussion on this topic.
Yh the game isnt going to be able to find a file outside of custom files like that. Open and output the file with lua

Output(Readfile(GetModPath() .. "/Resources/level01/custom.p3d))
I see. Thank you for pointing me to the correct function.
No need to even read the file. You can use Redirect function to make the game read another file. Like this:
if SomeChoice == 1 then
    Redirect(GetModPath() .. "/Resources/level01/custom.p3d")
If SomeChoice is 0 the game will load original file.