Class TimbnPluginPlayer
Acts on the player character, with every change undone when the plugin unloads or the player returns to the main menu. See TimbnPlayer to read where the player is. Reach it through the plugin's Player property.
public sealed class TimbnPluginPlayer
- Inheritance
-
TimbnPluginPlayer
- Inherited Members
Methods
Carry(Item, Action?, TimbnCarryRule)
Puts an item in the player's hands, held over their head the way they carry a log. A player with a free carry slot keeps what they carried and holds the new item on top, otherwise what was on top is dropped, so check TimbnPlayer.HandsFree first when the item should be the only thing carried. A small item, such as a mug, shows its icon there. Pressing the interaction key with nothing in reach puts it down on the ground the way the game drops anything carried, and the game does the same when the player starts work or a fight. The item is kept out of every save the game writes, so a save never holds it. An item that is already carried is not handed over again, and the handle comes back already ended. The rule says how it sits in and leaves their hands. With Exclusive it is the only thing they hold, what they held before drops at their feet and nothing else can be picked up or handed to them meanwhile, and with OnlyByCode nothing but disposing the handle takes it either, for an item the player may only hand over at a spot the plugin handles itself.
public IDisposable Carry(Item item, Action? putDown = null, TimbnCarryRule rule = TimbnCarryRule.Vanilla)
Parameters
itemItemThe item to carry, such as one of the plugin's own added with Balance.Add.
putDownActionRuns once the player has put it down or the game took it, a frame later, so a dropped item is already on the ground. It does not run when the handle is disposed.
ruleTimbnCarryRuleHow the item sits in and leaves the player's hands. By default as the game carries a log.
Returns
- IDisposable
A handle that takes the item out of the player's hands when disposed, if they still carry it. It is also taken when the plugin unloads and on the way to the main menu.
Examples
_mug = Player.Carry(new Item("my_mod_mug"), () => TimbnItems.RemoveDrops(TimbnItems.FindDrops(drop => drop.Id == "my_mod_mug")));
// once it is handed over
_mug.Dispose();
MultiplyWalkSpeed(float)
Makes the player walk faster or slower until the returned handle is disposed. It multiplies the game's own speed without changing it, so the game's slowdowns, such as aiming a bow, still apply on top and cannot cancel it. Several plugins can hold a speed at once, and the newest one wins. When the last is released, the player walks at the game's speed again.
public IDisposable MultiplyWalkSpeed(float multiplier)
Parameters
multiplierfloatHow many times the normal walking speed. 1 is normal.
Returns
- IDisposable
A handle that ends the change when disposed. It is also released when the plugin unloads and on the way to the main menu.
Examples
Buff = new TimbnPotionBuff
{
OnStart = () => _swift = Player.MultiplyWalkSpeed(1.5f),
OnEnd = () => _swift?.Dispose(),
};
SlideTo(Vector3, Action?)
Moves the player to a spot along the NPC navmesh with the game's own walker, the way a story scene walks them, and calls back when they get there. Their physics is off on the way, so they never get stuck, but they pass through gaps and over ledges they could not walk by hand. Movement keys do not stop it, so dispose the handle to call it off. A newer slide, from any plugin, replaces this one, and then this one never calls back.
public IDisposable SlideTo(Vector3 position, Action? arrived = null)
Parameters
positionVector3Where to go.
arrivedActionRuns once on arrival. It never runs after the handle is disposed or when the navmesh has no way there, which is logged.
Returns
- IDisposable
A handle that stops the slide when disposed. It is also stopped when the plugin unloads and on the way to the main menu.
Examples
_slide?.Dispose();
_slide = Player.SlideTo(hit.point);
TakeControl()
Takes the player's control away, the way the game does during its own cutscenes and conversations. They cannot walk, interact, attack, use the hotbar, or open the game's menus with their keys, nothing can push them, and hotkeys checked with IsDownWithControl(KeyboardShortcut) stay quiet. Each call adds its own reason to the game's list of reasons the player is held, and the game only gives control back once every reason has let go, so several plugins can take control at once and a game cutscene ending meanwhile never frees the player. Read your own keys with IsDownInGame(GameKey) or IsDownInGame(KeyboardShortcut) while it is held, and see GameHasControl(params TakenControlType[]) to notice the game stepping in.
public IDisposable TakeControl()
Returns
- IDisposable
A handle that gives control back when disposed. It is also released when the plugin unloads and on the way to the main menu.
Examples
_control = Player.TakeControl();
// later
_control?.Dispose();
WalkTo(Vector3, Action?)
Walks the player to a spot along the navmesh as if they held the movement keys, and calls back when they get there. They move at their own speed and only go where they could by hand, so walls, fences and ledges stop them. Without a hold, any movement input from the player ends the walk, as suits a walk they asked for, such as clicking where to go. Take control first for a walk a scene needs, and then the player cannot stop it. Control the game takes, such as a talk, ends the walk either way. A newer walk, from any plugin, takes over once its route is found, so the player keeps moving meanwhile and carries on when the newer one has no way. A spot the player does not fit, such as against a wall, is walked to as close as they fit.
public IDisposable WalkTo(Vector3 position, Action? arrived = null)
Parameters
positionVector3Where to walk to.
arrivedActionRuns once on arrival. It never runs after the handle is disposed, when the walk is ended or taken over, or when the player has no way to within half a unit of the spot or gets blocked on the way, each of which is logged.
Returns
- IDisposable
A handle that stops the walk when disposed. It is also stopped when the plugin unloads and on the way to the main menu.
Examples
_control = Player.TakeControl();
_walk = Player.WalkTo(bench, SitDown);
// later, to call it off
_walk?.Dispose();