EtG Modding Guide
Search…
⌃K

Creating An Active

Simple explanation on creating an Active item and how it works.

Difficulty: 2/10

This tutorial will use code and terms explained in passives, so it is advised to check that out before making an active.
Creating an active item is very similar to creating a passive. You want to create a new class and name it your item name(remember, no spaces). At the top, you want to be using ItemAPI; and using UnityEngine; make your class inherit from PlayerItem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ItemAPI;
using UnityEngine;
namespace YourNameSpace
{
class YourClassName : PlayerItem
{
}
}
Once you have done that copy in the init from your passive and change all names accordingly. you can remove the AddPassiveStatModifier if you don't want your active item to have any passive effects.
you also need to set a cooldown for your item, and whether or not the item should be consumable. This also goes in the init.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ItemAPI;
using UnityEngine;
namespace YourNameSpace
{
class YourClassName : PlayerItem
{
public static void Init()
{
//Same set up as passive items
//...
ItemBuilder.SetCooldownType(item, ItemBuilder.CooldownType.None, 0f);
item.consumable = false;
}
}
}
there are 4 cooldown types, Damage, None, PerRoom, and Timed. So you set that and then set the value.
for Damage you set how much damage before it recharges, PerRoom how many rooms, Timed how many seconds, none doesn't matter.
now you make a pickup for your active item.
public override void Pickup(PlayerController player)
{
base.Pickup(player);
}
Active items do not need drops.
now, outside of your pickup and init, make a DoEffect method
protected override void DoEffect(PlayerController user)
{
}
this is where all of the code for what happens upon using the active item is put. Inside the parenthesis of the DoEffect we put in the parameters it needs. It takes the Player and gives it a name, in this case, user, so that we can reference the player in our code.
for this example, we will take half a heart from the player and give them 15 casings.
so within our DoEffect, we want to first apply the damage, so we put this in the DoEffect.
user.healthHaver.ApplyHealing(-0.5f);
the first part is what healthHaver we want to apply the healing to (a healthHaver is anything that has health of course), then we specify what we want to do with that health, in this case, we want to ApplyHealing. Now then, you may be wondering, "I thought we were going to damage the player, now heal them", and you are correct, we are healing the player with a negative value and thus are actually taking away health. So the number within the parenthesis is the amount of healing that we want to apply, each fell heart equals 1, so to damage for half a heart we need to use -0.5. The number is meant to be a float, and at the moment it is reading it as a double, so we add an f at the end to tell the computer that our number is a float.
Now we give the player 15 casings, this also goes in the DoEffect.
user.carriedConsumables.Currency += 15;
user refers to the player, and we want to add 15 casings, so we use += instead of =. Otherwise, it would just set the number of casings the player has to 15.
Now, if we wanted to, we can take this one step further and disable this item if the player is at 1/2 a heart, so they don't accidentally kill themselves with it. We do this by creating a bool, CanBeUsed.
public override bool CanBeUsed(PlayerController user)
{
return user.healthHaver.GetCurrentHealth() > .5f;
}
this returns if the player is above 0.5 health.
so inside the DoEffect we now want to check if it can be used.
protected override void DoEffect(PlayerController user)
{
if (CanBeUsed(user))
{
user.healthHaver.ApplyHealing(-0.5f);
user.carriedConsumables.Currency += 15;
}
}
now we need to go back into our module, and call YourClassName.Init(); of course, replace "YourClassName" with whatever the name of your items class was.