Last updated | 2 years ago |
Total downloads | 7385 |
Total rating | 2 |
Categories | |
Dependency string | Amadare-FTKAPI-0.1.0 |
Dependants | 2 other packages depend on this package |
This mod requires the following mods to function
BepInEx-BepInExPack_ForTheKing
BepInEx pack for For The King. Preconfigured and ready to use.
Preferred version: 5.4.19README
For The King API (FTKAPI) - Modding Library
FTKAPI is a work-in-progress modding framework to aid developers in creating For The King mods, by providing centralized and simplified APIs for the game.
Documentation
There is a provided example plugin(s) made with the use of the library located in the Examples folder.
Features
Objects
- CustomItem
Can create an item with full custom functionality or inherit functionality from existing items (herbs, orbs, armor, weapons). - CustomClass
Can create a character class with full custom functionality or inherit functionality from existing classes (blacksmith, hunter, etc.). - CustomLocalizedString
Can create a string/text that supports additional languages.
Managers
- AssetManager
Allows importing custom assets such as models and images, to be used with custom or existing GameObjects. - ItemManager
Allows the modification and addition of items. As simple asItemManager.AddItem(new CustomItem());
! - ClassManager
Allows the modification and addition of classes. As simple asClassManager.AddClass(new CustomClass());
! - NetworkManager
Allows registering custom objects with network connectivity. Example below. - PluginConfigManager
Allows plugins to add configuration entry directly into game menu. Example below.
Networking
When using NetworkManager
, you can register object that can be instantiated on your and other clients side and have working communication between users. Simplest way to do that is to use RPC-commands through your custom inheritor of PunBehavior
class. Here is example of such implementation:
// MyPluginRpc.cs
class MyPluginRpc : PunBehavior
{
public void Start()
{
if (PhotonNetwork.IsMasterClient)
{
SendMessage("Hello from master client");
}
}
public void SendMessage(string message)
{
this.photonView.RPC("SendMessagePRC", PhotonTargets.Others, message);
}
[PunRPC]
public void SendMessagePRC(string message)
{
Logger.LogInfo($"Received '{message}'!");
}
}
Then, you can register GameObject
that would have this Component. Empty GameObject
is created by default, so you just have to add necessary components. This function will be called on both sides during creation.
NOTE: you can modify this GameObject in any way you want, but in order for RPC component to work, it's parent GameObject should have PhotonView which is populated by default.
NOTE: you shouldn't create a lot of there objects. Ideally it should be one per plugin.
// during plugin initialization
NetworkManager.RegisterNetObject("MyPluginGuid.SyncObject",
gameObject => gameObject.AddComponent<MyPluginRpc>(),
new () { SpawnOnRoomCreation = false }
);
Then you can just call NetworkManager.SpawnNetworkObject
with same id you provided, and this object would be instantiated and "network-enabled"!
// somewhere in-room
var networkGameObject = NetworkManager.SpawnNetworkObject("MyPluginGuid.SyncObject");
// other clients will log "Received 'Hello from master client!'" when object will be created."
Note that in example above SpawnOnRoomCreation
is set to false
during registration, but it is true
by default. So if you don't provide options, you don't have to create it manually.
You can read more about network synchronization FTK uses in the official Photon reference: https://doc.photonengine.com/en-us/pun/v1/gameplay/synchronization-and-state
In-Game configuration
Allows plugins to add configuration entry directly into game menu.
// create BepInEx config entry
var entry = Config.Bind("MySection", "MyConfigKey", "MyDescription", defaultValue: 42);
// add entry to conifguration screen
PluginConfigManager.RegisterBinding(entry);
NOTE: In order for options to be saved automatically, you'll need to set Config.SaveOnConfigSet = true;
somewhere in your code.
You can also create your custom configuration entries that aren't explicitly tied to BepInEx configurations by implementing IConfigurableEntry
interface or use CustomConfigurableEntry
.
PluginConfigManager.Instance.RegisterSingleBinding(new CustomConfigurableEntry() {
Key = "MyConfigKey",
Section = "MySection",
Description = "MyDescription",
OwnerName = "MyPluginName",
SettingType = typeof(bool),
Value = true
});
Build
- Download repository with submodules
- dotnet restore
- (optional) Set
BuiltPluginDestPath
andBuiltPluginDestPath2
in FTKAPI.csproj to copy resulting binaries to your plugin directory - Build using with whatever tool you have: Visual Studio, Visual Studio Code, Rider or dotnet cli directly
Special thanks to
lulzsun/FTKModLib that explicitly allowed me to re-use a lot of his code
And by transitivity rule, all these other folks whose work helped him:
999gary/FTKExampleItemMod used as learning reference
CarbonNikm/FTK-Debugging-Commands used as learning reference
Valheim-Modding/Jotunn used as learning reference