This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
Spawning followers #66
Answered
by
Chasmical
Killerstrike1234
asked this question in
Q&A
-
How would I spawn a follower as a trait or an ability for a custom mod |
Beta Was this translation helpful? Give feedback.
Answered by
Chasmical
Sep 28, 2022
Replies: 1 comment 46 replies
-
You can use one of the As a custom ability it would look kind of like this: public class FollowerSpawn : CustomAbility
{
[RLSetup]
public static void Setup()
{
RogueLibs.CreateCustomAbility<FollowerSpawn>()
.WithName(new CustomNameInfo("Follower Spawn"))
.WithDescription(new CustomNameInfo("A special ability that spawns followers."))
.WithSprite(Properties.Resources.MySprite)
.WithUnlock(new AbilityUnlock());
}
public override void OnAdded() { }
public override void OnPressed()
{
if (!Owner.CanHaveMoreFollowers(true))
return; // the user can't have any more followers
// get the user's position
Vector2 userPos = Owner.tr.position;
// get a random direction
Vector2 randomDir = Random.insideUnitCircle.normalized;
Vector2 followerPos = userPos + randomDir * 0.64f; // 0.64f = 1 floor tile
// spawn a follower
// (we'll reuse the Friend Phone's code in here, see ItemFunctions.UseItem(...))
Agent follower = gc.spawnerMain.SpawnAgent(followerPos, Owner, "Bouncer", "FriendPhone", Owner);
}
} |
Beta Was this translation helpful? Give feedback.
46 replies
Answer selected by
Killerstrike1234
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use one of the
SpawnerMain.SpawnAgent
methods to spawn a follower.As a custom ability it would look kind of like this: