1. For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
    Dismiss Notice

tAPI Need help with adding max life

Discussion in 'General Mod Discussion' started by KingKirmit, Feb 24, 2015.

  1. KingKirmit

    KingKirmit Golem

    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.
     
  2. Sin Costan

    Sin Costan Eye of Cthulhu

    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
     
  3. KingKirmit

    KingKirmit Golem

    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...
     
  4. Sin Costan

    Sin Costan Eye of Cthulhu

    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;
            }
        }
    }
    
     
  5. KingKirmit

    KingKirmit Golem

    :/ 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: Feb 24, 2015
  6. Sin Costan

    Sin Costan Eye of Cthulhu

    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;
            }
        }
    }
    
     
  7. KingKirmit

    KingKirmit Golem

    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..
     
  8. Sin Costan

    Sin Costan Eye of Cthulhu

    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: Feb 24, 2015
  9. Shockah

    Shockah Grandson of The Wizard

    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.
     
  10. KingKirmit

    KingKirmit Golem

    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
    --- Double Post Merged, Feb 24, 2015 ---
    It seems to have worked though :)
     
  11. Sin Costan

    Sin Costan Eye of Cthulhu

    :joy:
     
  12. Shockah

    Shockah Grandson of The Wizard

    It did work, but the check for it effectively does NOTHING.
     
  13. Sin Costan

    Sin Costan Eye of Cthulhu

    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.
     
  14. Shockah

    Shockah Grandson of The Wizard

    Adding it sounds fine, but there is no point in checking it in the if condition.
     
  15. Exxcluded

    Exxcluded Terrarian

    How do you make it permanent? For me it removes the extra health / mana when I leave