Create-A-Crate: Basic Pipeline

Updated a week ago

Usage

Basic Pipeline

  1. Open a BepInEx BaseUnityPlugin
    • If this is new to you, read up on how to do it here
  2. Find this library's .dll file on your computer
    • Can be found in Thunderstore's Settings > Browse profile folder > BepInEx > plugins > SimonTendo-LCCrashBandicootCratesMod > LCCrashBandicootCratesMod.dll
    • Copy the path to this folder, in the file explorer's top bar
  3. Reference the assembly in your plugin
    • In the plugin's project settings:
      • In the References, add <Reference Include="LCCrashBandicootCratesMod.dll" HintPath="PathYouJustCopied\LCCrashBandicootCratesMod.dll" />
    • In the namespace's Using field
      • using LCCrashBandicootCratesMod;
      • Note: in case this doesn't show up as an auto-correct option, or throws an error if you pasted this into your code, then it means you already have access to this mod's code and you needn't worry about it further
    • In the main Plugin Class:
      • [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
      • [BepInDependency("local.SimonTendo.LCCrashBandicootCratesMod")]
    • In the plugin manifest's dependencies:
      • "dependencies": ["BepInEx-BepInExPack-5.4.2304", "SimonTendo-LCCrashBandicootCratesMod-1.0.1"]
  4. Register the crate
    • Make sure this next step happens immediately upon loading the game, preferably the Awake() method of the Plugin class that BepInEx loads and is usually the start of any mod's code and set-up. If you register the crate too late, it might not automatically register any NetworkObjects that you want to spawn from your crate.
    • To actually register your own crate, copy the giant method below into your plugin, and call it on Awake(). This method does all the work of registering the crate to the network, to StartOfRound, and anything related to it actually spawning in-game.
    • To customize the crate, change the parameter's values that are behind the :. For example, to change the weight from 10 lb to 30 lb, change weight: 1.1f to weight: 1.3f. Or, to change the bounciness of your crate, rewrite bounceForce: 20.0f to bounceForce: 33.3f.
    • You can even call methods from your own code with the Event parameters like jumpOntoEvent and destroyEvent, which get called whenever the crate is jumped onto or destroyed respectively. These methods are also given the crate that called the event and the player that interacted with the crate (if applicable), letting you customize things about the crate, such as increasing the bounceForce of a crate every time it's jumped onto. I recommend making public static or internal static methods, for example public static void IncreaseBounciness(CrateGrabbableObject crate, PlayerControllerB player) { }, which you can then pass as a parameter in CreateYourOwnCrate() like this: jumpOntoEvent: IncreaseBounciness
public static void CreateYourOwnCrate()
{
    Item yourCrateItemProperties = CreateACrate.MakeItem(
        crateName: "Modded Crate",
        twoHanded: true,
        twoHandedAnim: true,
        disableWallHands: false,
        grabBeforeStart: true,
        weight: 1.1f,
        trigger: false,
        holdButtonUse: false,
        spawnsOnGround: true,
        conductive: false,
        maxValue: 100,
        minValue: 50,
        requireBattery: false,
        batteryUsage: 0.0f,
        autoUsePower: false,
        crateIcon: null,
        grabAnim: "HoldLung",
        grabSFX: null,
        dropSFX: null,
        pocketSFX: null,
        defensiveWeapon: false,
        tooltips: null,
        verticalOffset: 0.01f,
        floorOffset: 0,
        dropAhead: true,
        restRotation: default,
        rotationOffset: default,
        positionOffset: default,
        meshVariants: null,
        materialVariants: null,
        usableInAnimations: false,
        inspectable: false
        );

    CrateData yourCrateData = CreateACrate.MakeCrateData(
        breakSFX: null,
        bounceSFX: null,
        specialSFX: null,
        audioOneShot: true,
        audioToggle: true,
        audioRandomized: false,
        noiseAudible: true,
        noiseLoudness: 0.5f,
        noiseRange: 10.0f,
        noiseInterval: 2.0f,
        switchMats: null,
        matIndeces: null,
        bounceThreshold: 2.0f,
        bounceDivider: 10.0f,
        bounceTime: 1.0f,
        bounceCurve: null,
        fallTriggersWalk: -1.0f,
        fallTriggersJump: -1.0f,
        fallTriggersAttack: -1.0f,
        walkPlaySFX: false,
        jumpPlaySFX: false,
        attackPlaySFX: false,
        timerPlaySFX: false,
        destroyPlaySFX: false,
        walkPlayParticle: false,
        jumpPlayParticle: false,
        attackPlayParticle: false,
        timerPlayParticle: false,
        destroyPlayParticle: false,
        switchPrefabsOnInt: null,
        switchToNull: false,
        countInBetween: false,
        valueDecrease: 0.5f,
        walkSpawnAmount: -1,
        jumpSpawnAmount: -1,
        attackSpawnAmount: -1,
        destroySpawnAmount: -1,
        walkLosesContent: false,
        jumpLosesContent: false,
        attackLosesContent: false,
        otherLosesContent: true,
        timerRepeats: 0,
        timerVisible: true,
        timerMedian: 45.0f
        );

    ModdedCrateRuntimeParameters yourCrateRuntimeParameters = CreateACrate.MakeModdedCrateRuntimeParameters(
        crateData: yourCrateData,
        itemProperties: yourCrateItemProperties,
        scanName: null,
        crateScale: default,
        newMaterials: null,
        newMesh: null,
        newBreakParticles: null,
        breakParticleColor: default,
        specialParticles: null,
        specialParticleColor: default,
        collide: true,
        overrideCollide: null,
        overrideBounce: null,
        useCooldown: 0.25f,
        bounceForce: 20.0f,
        startingInt: 0,
        destroyUpon: 1,
        addOrSnap: true,
        walkChangesInt: 0,
        jumpChangesInt: 1,
        attackChangesInt: 99,
        startEvent: null,
        walkIntoEvent: null,
        jumpOntoEvent: null,
        attackEvent: null,
        timerEndEvent: null,
        destroyEvent: null,
        newSpawnPrefab: null,
        spawnAmount: 1,
        timerDuration: -1.0f,
        timerObject: null
        );


    CreateACrate.RegisterCrateToAllLevelsWithRarity(
    	runtimeParameters: yourCrateRuntimeParameters,
    	rarityExperimentation: 10,
    	rarityAssurance: 10,
    	rarityVow: 10,
    	rarityOffense: 20,
    	rarityMarch: 20,
   	rarityAdamance: 20,
    	rarityRend: 30,
    	rarityDine: 30,
    	rarityTitan: 30,
    	rarityEmbrion: 40,
    	rarityArtifice: 40,
    	rarityModded: 50
    );
}

And that's it, your crate will now spawn on the moons you selected!

Feel free to experiment with the parameters to see different results, or to reach out to me on the Lethal Company Modding discord server, if you have any questions about how the mod works.

I realize there are a LOT of parameters to sift through, and it's not the most intuitive system, so this might maybe be reworked in the future, leading to incompatibility issues should it come to that. But I am very proud of it, since it allows full customization of your own crates, so I hope you enjoy!