tAPI Need help with adding max life

So im currently working on a mod Endgame Gods.
I wish to add a consumable item that extends your max life, just like the life crystal in vanilla, but I want the max life to now be 3,000 rather than 500.
Problem is I dont know the codding for this, and am seeking help.

Anyone who can provide me with a source code for this or can help me enough to where it works I will provide credit in my mod.
 
Well, I'm pretty certain it has to do with this and stick it on effects.
Code:
p.statLifeMax2 += 100; //p being the Player variable
 
Well, I'm pretty certain it has to do with this and stick it on effects.
Code:
p.statLifeMax2 += 100; //p being the Player variable
What would the class file need to look like for this? I've never created a consumable item that required a class file so I dont even know what that would look like...
 
I haven't realy done items that much but I think it's something like this.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace ModName.Items
{
    public class ModItemName: ModItem
    {
        public override bool? UseItem(Player p)
        {
            p.statLifeMax2 += 100;
            return true;
        }
    }
}
 
I haven't realy done items that much but I think it's something like this.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace ModName.Items
{
    public class ModItemName: ModItem
    {
        public override bool? UseItem(Player p)
        {
            p.statLifeMax2 += 100;
            return true;
        }
    }
}
:/ well it doesn't come up with any errors compiling it into the mod nor with loading the mod IG, but it doesn't seem to use the item, maybe I need to put some "can use" code in there....
*EDIT* Adding "can use" coding didn't work either...
 
Last edited:
Ok, I got it to work.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace ModName.Items //Make sure to change "ModName" to your Mod's internal name.
{
    public class ModItemName: ModItem //Make sure to change "ModItemName" to your item's name.
    {
        public override bool? UseItem(Player p)
        {
            p.statLife += 100;
            p.statLifeMax += 1500;
            p.statLifeMax2 += 1500;
            return true;
        }
    }
}
 
Ok, I got it to work.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace ModName.Items //Make sure to change "ModName" to your Mod's internal name.
{
    public class ModItemName: ModItem //Make sure to change "ModItemName" to your item's name.
    {
        public override bool? UseItem(Player p)
        {
            p.statLife += 100;
            p.statLifeMax += 1500;
            p.statLifeMax2 += 1500;
            return true;
        }
    }
}
IT WORKS! Thank you soo much :D This is kind of a core item to the mod considering the power of my future NPCs and my current new Bosses, so this really helps!

Btw do you have any clue how I would be able to restrict the use of the item if your health is 3000?
I've tried to implement this using the CanUse coding but I cant seem to get it down..
 
I would think something like this.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace ModName.Items //Make sure to change "ModName" to your Mod's internal name.
{
    public class ModItemName: ModItem //Make sure to change "ModItemName" to your item's name.
    {
        public override bool? UseItem(Player p)
        {
            if(p.statLifeMax2 >= 500 && p.statLifeMax2 <= 1000)
            {
                p.statLife += 100;
                p.statLifeMax += 100;
                p.statLifeMax2 += 100;
                return true;
            }
            else
            {
                   return false;
            }
        }
    }
}
 
Last edited:
To begin with, you shouldn't really be touching statLifeMax2 in this case, considering the fact, that it's the "temporary max health" value. Basically, think of accessories which would increase the max health when worn.
 
I would think something like this.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace ModName.Items //Make sure to change "ModName" to your Mod's internal name.
{
    public class ModItemName: ModItem //Make sure to change "ModItemName" to your item's name.
    {
        public override bool? UseItem(Player p)
        {
            if(p.statLifeMax2 >= 500 && p.statLifeMax2 <= 1000)
            {
                p.statLife += 100;
                p.statLifeMax += 100;
                p.statLifeMax2 += 100;
                return true;
            }
            else
            {
                   return false;
            }
        }
    }
}
IT WORKS! just had to switch around
Code:
(p.statLifeMax2 >= 3000 && p.statLifeMax2 <= 100)
to
Code:
(p.statLifeMax2 <= 3000 && p.statLifeMax2 >= 100)

Thank you very much for your help, this might have taken me some long time to figure out :)
You will be credited for the item's coding :D
[DOUBLEPOST=1424793276][/DOUBLEPOST]
To begin with, you shouldn't really be touching statLifeMax2 in this case, considering the fact, that it's the "temporary max health" value. Basically, think of accessories which would increase the max health when worn.
It seems to have worked though :)
 
I basically got this code from Terraria, both the Life Crystal and the Life Fruit are set up in this format, all three statLifes (statLife, statLifeMax, and statLifeMax2) are all added together.
 
Back
Top Bottom