• Labor of Love is here! Visit our Labor of Love thread for a special message from the team, a look at brand new Labor of Love merch, and the changelog (minus a few surprises 😉)

tModLoader Help with GlobalItem

ZanderMeister

Skeletron Prime
How do I change vanilla armor's set bonus?
I know that there's a UpdateArmorSet hook, but I don't know how to use it properly.
 

Sin Costan

Eye of Cthulhu
How do I change vanilla armor's set bonus?
I know that there's a UpdateArmorSet hook, but I don't know how to use it properly.
It doesn't look like you can change the armor set's abilities at all, however, you can add to it. Also, it seems you would need to need to call IsArmorSet and then UpdateArmorSet so it is easier to do. For example you can do it like this in the global item settings.

Code:
public override void IsArmorSet(Item head, Item body, Item legs)
{
    if(head.type == ItemID.SilverHelmet && body.type == ItemID.CopperChainmail && legs.type == ItemID.IronGreaves)
    {
        return "Random Set";
    }
    return "";
}

public override void UpdateArmorSet(Player player, string set)
{
   if(set == "Random Set")
   {
       player.noFallDmg = true;
   }
}

This is at least my guess. It seems that the way they do Armor sets is different because it is not defined by a group name rather barely defined by their setBonus description (player.setBonus) and the attribute associated with it, so you could try looking at UpdateArmorSets(int i) method in Player class and the setBonus(int i, bool english) method in the Lang class of Terraria.
 

ZanderMeister

Skeletron Prime
It doesn't look like you can change the armor set's abilities at all, however, you can add to it. Also, it seems you would need to need to call IsArmorSet and then UpdateArmorSet so it is easier to do. For example you can do it like this in the global item settings.

Code:
public override void IsArmorSet(Item head, Item body, Item legs)
{
    if(head.type == ItemID.SilverHelmet && body.type == ItemID.CopperChainmail && legs.type == ItemID.IronGreaves)
    {
        return "Random Set";
    }
    return "";
}

public override void UpdateArmorSet(Player player, string set)
{
   if(set == "Random Set")
   {
       player.noFallDmg = true;
   }
}

This is at least my guess. It seems that the way they do Armor sets is different because it is not defined by a group name rather barely defined by their setBonus description (player.setBonus) and the attribute associated with it, so you could try looking at UpdateArmorSets(int i) method in Player class and the setBonus(int i, bool english) method in the Lang class of Terraria.


When I try to compile the mod, it gives me error, that has something to do with return value. But when I change void in "properties"(override public blahblah) of method IsArmorSet to string, it gives me even more errors about "Terraria.Item doesn't have definition for defence(i change some values for armor too, using SetDefaults)" and so on.

I can show you my code, if you would like to help me.(but I can't show you log, 'coz it mainly written in Russian)
 
Last edited:

Sin Costan

Eye of Cthulhu
When I try to compile the mod, it gives me error, that has something to do with return value. But when I change void in "properties"(override public blahblah) of method to string, it gives me even more errors about "Terraria.Item doesn't have definition for defence(i change some valuse for armor too, using SetDefaults)" and so on.

I can show you my code, if you would like to help me.(but I can't show you log, 'coz it mainly written in Russian)
Defence is actually statDefense for players. Also I typed it wrong, it's string, not void for IsArmorSet. It would help me fix more problems if you put up your code.
 

ZanderMeister

Skeletron Prime
Defence is actually statDefense for players. Also I typed it wrong, it's string, not void for IsArmorSet. It would help me fix more problems if you put up your code.

using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace AlternativityRedux.Items
{
public class ObsidianArmor : GlobalItem
{
public override void SetDefaults(Item item)
{
if (item.type == ItemID.ObsidianHelm)
{
item.defence = 6;
item.toolTip = "6% increased ranged damage";
item.toolTip2 = "3% ranged critical strike chance";
}
if (item.type == ItemID.ObsidianShirt)
{
item.defence = 7;
item.toolTip = "7% increased ranged damage";
item.toolTip2 = "4% ranged critical strike chance";
}
if (item.type == ItemID.ObsidianPants)
{
item.defence = 5;
item.toolTip = "6% increased ranged damage";
item.toolTip2 = "2% ranged critical strike chance";
}
}
public override void UpdateEquip(Item item, Player player)
{
for(int k = 1; k < 8 + player.extraAccessorySlots; k++)
{
if (player.armor[k].type == ItemID.ObsidianHelm)
{
player.rangedDamage += 0.06f;
player.rangedCrit += 3;
}
if (player.armor[k].type == ItemID.ObsidianShirt)
{
player.rangedDamage += 0.07f;
player.rangedCrit += 4;
}
if (player.armor[k].type == ItemID.ObsidianPants)
{
player.rangedDamage += 0.06f;
player.rangedCrit += 2;
player.moveSpeed += 0.08f;
}
}
}
public override string IsArmorSet(Item head, Item body, Item legs)
{
if (head.type == ItemID.ObsidianHelm && body.type == ItemID.ObsidianShirt && legs.type == ItemID.ObsidianPants)
{
return "ObsidianArmorSet";
}
}
public override void UpdateArmorSet(Player player, string set)
{
if (set == "ObsidianArmorSet")
{
player.setBonus = "Immunity to 'On Fire!'";
player.buffImmune[BuffId.OnFire] = true;
}
}
}
}


I know about statDefence, was digging through Terraria source recently ;)
 

Sin Costan

Eye of Cthulhu
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace AlternativityRedux.Items
{
public class ObsidianArmor : GlobalItem
{
public override void SetDefaults(Item item)
{
if (item.type == ItemID.ObsidianHelm)
{
item.defence = 6;
item.toolTip = "6% increased ranged damage";
item.toolTip2 = "3% ranged critical strike chance";
}
if (item.type == ItemID.ObsidianShirt)
{
item.defence = 7;
item.toolTip = "7% increased ranged damage";
item.toolTip2 = "4% ranged critical strike chance";
}
if (item.type == ItemID.ObsidianPants)
{
item.defence = 5;
item.toolTip = "6% increased ranged damage";
item.toolTip2 = "2% ranged critical strike chance";
}
}
public override void UpdateEquip(Item item, Player player)
{
for(int k = 1; k < 8 + player.extraAccessorySlots; k++)
{
if (player.armor[k].type == ItemID.ObsidianHelm)
{
player.rangedDamage += 0.06f;
player.rangedCrit += 3;
}
if (player.armor[k].type == ItemID.ObsidianShirt)
{
player.rangedDamage += 0.07f;
player.rangedCrit += 4;
}
if (player.armor[k].type == ItemID.ObsidianPants)
{
player.rangedDamage += 0.06f;
player.rangedCrit += 2;
player.moveSpeed += 0.08f;
}
}
}
public override string IsArmorSet(Item head, Item body, Item legs)
{
if (head.type == ItemID.ObsidianHelm && body.type == ItemID.ObsidianShirt && legs.type == ItemID.ObsidianPants)
{
return "ObsidianArmorSet";
}
}
public override void UpdateArmorSet(Player player, string set)
{
if (set == "ObsidianArmorSet")
{
player.setBonus = "Immunity to 'On Fire!'";
player.buffImmune[BuffId.OnFire] = true;
}
}
}
}


I know about statDefence, was digging through Terraria source recently ;)
Ok, there were only a few problems. You have to have another return statement outside the if statement because you only have that one path and then nothing else, so use an else statement or just put the return statement outside the if statement, both will work. The int k" should equal "0" in the for loop, since head slot I believe is 0. I don't think there's anymore problems.
 

ZanderMeister

Skeletron Prime
Ok, there were only a few problems. You have to have another return statement outside the if statement because you only have that one path and then nothing else, so use an else statement or just put the return statement outside the if statement, both will work. The int k" should equal "0" in the for loop, since head slot I believe is 0. I don't think there's anymore problems.
Man, I feel so stupid right now.
I just wrote "defence", not "defense" -_-

Thank you really much for helping me!
 
Top Bottom