TryConnect

版本 v0.1.2·更新於 2026-05-06

API and runtime support for registering custom items and prefab-based content in Gamble With Your Friends

模組介紹 作者原文

How to Use TryConnect in Your Mod (WIP!!)

  • Add TryConnect as a dependency in your mod.
  • Register your custom item in the Awake method.

using System.Collections;

using BepInEx;

using TryConnect;

using UnityEngine;

[BepInDependency(TryConnectApi.PluginGuid)]

[BepInPlugin("com.try-4646.Heroin-Mod", "Heroin", "1.0.0")]

public sealed class HeroinPlugin: BaseUnityPlugin

{

private void Awake()

{

TryConnectRegistrationResult result =

TryConnectApi.RegisterBundledCustomItem(

this,

new TryConnectBundledItemRegistration

{

Key = "heroin_injector",

DisplayName = "Heroin",

Description = "Go Crazy.",

BundlePath = "heroin.assetbundle",

VisualPrefabName = "heroin",

VisualLocalScale = Vector3.one * 1f,

ApplyVisualColor = true,

VisualColor = new Color(0.8f, 0.1f, 0.1f),

ReplacementChancePercent = 100,

ExtraBasePrice = 1,

ExtraFloorPrice = 1

// ReplaceColliders = true,

// VisualLocalPosition = new Vector3(0f, 0f, 0f),

// VisualLocalEulerAngles = new Vector3(0f, 0f, 0f)

});

Logger.LogInfo($"TryConnect register result: {result}");

}

}

public sealed class HeroinDrink: Drink

{

private bool _extraEffectAppliedThisPress;

private bool _ragdollEffectActive;

protected override void OnUseItem(bool isPressed)

{

base.OnUseItem(isPressed);

if (!isPressed)

{

_extraEffectAppliedThisPress = false;

return;

}

if (_extraEffectAppliedThisPress ||!isServer)

{

return;

}

_extraEffectAppliedThisPress = true;

PlayerInventory holder = NetworkHolder;

if (holder == null)

{

return;

}

PlayerBuff buff = holder.GetComponent();

if (buff!= null)

{

buff.ApplyBuff(PlayerBuffType.TipsyFortune, 1, 15f);

}

if (!_ragdollEffectActive)

{

StartCoroutine(RandomRagdollEffect(holder));

}

Debug.Log("[Heroin] Random ragdoll effect started.");

}

private IEnumerator RandomRagdollEffect(PlayerInventory holder)

{

_ragdollEffectActive = true;

PlayerController playerController = holder.GetComponent();

float duration = 15f;

float timer = 0f;

while (timer < duration)

{

float randomDelay = Random.Range(1f, 3.5f);

yield return new WaitForSeconds(randomDelay);

if (playerController!= null)

{

playerController.TriggerRagdoll();

Debug.Log("[Heroin] Random ragdoll triggered.");

}

timer += randomDelay;

}

_ragdollEffectActive = false;

Debug.Log("[Heroin] Random ragdoll effect ended.");

}

}

Explanation:

  • Add [BepInDependency(TryConnectApi.PluginGuid)] to make sure TryConnect is loaded first.
  • Create a TryConnectItemRegistration object with your custom item details.
  • Call TryConnectApi.RegisterCustomItem(registration) to register your item.
  • Log the result for debugging.

Result:

Your custom item will now appear in the shop with the specified chance and properties, managed by TryConnect.

安裝與使用 安裝:按包內說明操作

  1. 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
  2. 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
  3. 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
  4. 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。

不同模組的安裝位置差異較大,包內說明是最可靠的依據。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

BepInEx-BepInExPack

檔案與校驗

檔案名稱
TryConnect-0.1.2.zip
檔案大小
69.4 KiB