Creating An Active
Simple explanation on creating an Active item and how it works.
Last updated
Simple explanation on creating an Active item and how it works.
Last updated
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
.
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.
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.
Active items do not need drops.
now, outside of your pickup and init, make a DoEffect method
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.
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 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.
this returns if the player is above 0.5 health.
so inside the DoEffect we now want to check if it can be used.
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.