Modding Help, i dunno what im doin.

Shefanhow

Terrarian
So i just got this error after following the example mods files for making an exclusive accessory, but when i try to build the mod with it in there, it gives me this error

[02:00:22] [11/ERROR] [tML]: Compiling Souls.XNA.dll failed with 47 errors and C:\Users\shefanhow1\Documents\My Games\Terraria\ModLoader\Mod Sources\Souls\Items\Acessories\ExclusiveAccessory.cs(37,25) : error CS0116: A namespace cannot directly contain members such as fields or methods warnings
Terraria.ModLoader.Exceptions.BuildException: Compiling Souls.XNA.dll failed with 47 errors and C:\Users\shefanhow1\Documents\My Games\Terraria\ModLoader\Mod Sources\Souls\Items\Acessories\ExclusiveAccessory.cs(37,25) : error CS0116: A namespace cannot directly contain members such as fields or methods warnings
at Terraria.ModLoader.Core.ModCompile.CompileMod(BuildingMod mod, String outputPath, List`1& refMods, Boolean xna)
at Terraria.ModLoader.Core.ModCompile.BuildModForPlatform(BuildingMod mod, List`1& refMods, Boolean xna)
at Terraria.ModLoader.Core.ModCompile.Build(BuildingMod mod)
at Terraria.ModLoader.Core.ModCompile.Build(String modFolder)
at Terraria.ModLoader.UI.UIBuildMod.<>c__DisplayClass5_0.<Build>b__0(ModCompile mc)
at Terraria.ModLoader.UI.UIBuildMod.BuildMod(Action`1 buildAction, Boolean reload)



and i literally just started messing with this today so i dont know what is even going on. do yall think you could help me out?
 
Could you post the contents of your ExclusiveAccessory.cs file?


using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace SoulsMod.Items.Accessories
{
public abstract class ExclusiveAcessory : ModItem
{
public override void SetDefaults() {
item.width = 30;
item.eight = 32;
item.accessory = true;
item.value = Items.sellPrice(gold: 10);
item.rare = ItemRarityID.Green;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(Determination);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
public override bool CanEquipAccessory(Player player, int slot) {
{
int index = FindDifferentEquippedExclusiveAccessory().index;
if (index != -1) {
return slot == index;
}
}
return base.CanEquipAccessory(player, slot);
}
}
public override void ModifyTooltips(List<TooltipLine> tooltips) {
Items accessory = FindDifferentEquippedExclusiveAccessory().accessory;
if (accessory != null) {
tooltips.Add(new TooltipLine(SoulsMod, "Swap", "Rightclick to swap with '" + accessory.Name + "'!") {
overrideColor = Color.Blue
});
}
}
public override bool CanRightClick() {
int maxAccessoryIndex = 5 + maxAccessoryIndex.LocalPlayer.extraAccessorySlots;
for (int i = 13; i < 13 + maxAccessoryIndex; i++) {
if (maxAccessoryIndex.LocalPlayer.armor.type == Items.type) return false;
}
if (FindDifferentEquippedExclusiveAccessory().accessory != null) {
return true;
}
return base.CanRightClick();
}
public override void RightClick(Player player) {
var (index, accessory) = FindDifferentEquippedExclusiveAccessory();
if (accessory != null) {
Main.LocalPlayer.QuickSpawnClonedItem(accessory);
Main.LocalPlayer.armor[index] = Items.Clone();
}
}
protected (int index, Items accessory) FindDifferentEquippedExclusiveAccessory() {
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 3; i < 3 + maxAccessoryIndex; i++) {
Item otherAccessory = Main.LocalPlayer.armor;
if (!otherAccessory.IsAir &&
!item.IsTheSameAs(otherAccessory) &&
otherAccessory.modItem is ExclusiveAccessory) {
return (i, otherAccessory);
}
}
return (-1, null);
}
public class Determination : ExclusiveAccessory
{
public override void SetStaticDefaults() {
Tooltip.SetDefault("When you would die to an attack revive at half hp");
}
public override void RightClick(Player player) {
string previousItemName = "";
Item accessory = FindDifferentEquippedExclusiveAccessory().accessory;
if (accessory != null) {
previousItemName = accessory.Name;
}
base.RightClick(player);
}
public override void SetDefaults() {
base.SetDefaults();
item.width = 16;
item.height = 16;
item.accessory = true;
item.value = Item.sellPrice(platinum: 4);
item.rare = ItemRarityID.Red;
}
public override void UpdateAccessory(Player player, bool hideVisual) {
player.health += 20;
if (player.health <= 0.05f) {
item.healLife = 0.5f;
}
}

public override int ChoosePrefix(UnifiedRandom rand) {
return rand.Next(new int[] { PrefixID.Arcane, PrefixID.Lucky, PrefixID.Menacing, PrefixID.Quick, PrefixID.Violent, PrefixID.Warding });
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(Souls);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}

}
}
 
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace SoulsMod.Items.Accessories
{
public abstract class ExclusiveAcessory : ModItem
{
public override void SetDefaults() {
item.width = 30;
item.eight = 32;
item.accessory = true;
item.value = Items.sellPrice(gold: 10);
item.rare = ItemRarityID.Green;
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(Determination);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
public override bool CanEquipAccessory(Player player, int slot) {
{
int index = FindDifferentEquippedExclusiveAccessory().index;
if (index != -1) {
return slot == index;
}
}
return base.CanEquipAccessory(player, slot);
}
}
public override void ModifyTooltips(List<TooltipLine> tooltips) {
Items accessory = FindDifferentEquippedExclusiveAccessory().accessory;
if (accessory != null) {
tooltips.Add(new TooltipLine(SoulsMod, "Swap", "Rightclick to swap with '" + accessory.Name + "'!") {
overrideColor = Color.Blue
});
}
}
public override bool CanRightClick() {
int maxAccessoryIndex = 5 + maxAccessoryIndex.LocalPlayer.extraAccessorySlots;
for (int i = 13; i < 13 + maxAccessoryIndex; i++) {
if (maxAccessoryIndex.LocalPlayer.armor.type == Items.type) return false;
}
if (FindDifferentEquippedExclusiveAccessory().accessory != null) {
return true;
}
return base.CanRightClick();
}
public override void RightClick(Player player) {
var (index, accessory) = FindDifferentEquippedExclusiveAccessory();
if (accessory != null) {
Main.LocalPlayer.QuickSpawnClonedItem(accessory);
Main.LocalPlayer.armor[index] = Items.Clone();
}
}
protected (int index, Items accessory) FindDifferentEquippedExclusiveAccessory() {
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 3; i < 3 + maxAccessoryIndex; i++) {
Item otherAccessory = Main.LocalPlayer.armor;
if (!otherAccessory.IsAir &&
!item.IsTheSameAs(otherAccessory) &&
otherAccessory.modItem is ExclusiveAccessory) {
return (i, otherAccessory);
}
}
return (-1, null);
}
public class Determination : ExclusiveAccessory
{
public override void SetStaticDefaults() {
Tooltip.SetDefault("When you would die to an attack revive at half hp");
}
public override void RightClick(Player player) {
string previousItemName = "";
Item accessory = FindDifferentEquippedExclusiveAccessory().accessory;
if (accessory != null) {
previousItemName = accessory.Name;
}
base.RightClick(player);
}
public override void SetDefaults() {
base.SetDefaults();
item.width = 16;
item.height = 16;
item.accessory = true;
item.value = Item.sellPrice(platinum: 4);
item.rare = ItemRarityID.Red;
}
public override void UpdateAccessory(Player player, bool hideVisual) {
player.health += 20;
if (player.health <= 0.05f) {
item.healLife = 0.5f;
}
}

public override int ChoosePrefix(UnifiedRandom rand) {
return rand.Next(new int[] { PrefixID.Arcane, PrefixID.Lucky, PrefixID.Menacing, PrefixID.Quick, PrefixID.Violent, PrefixID.Warding });
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(Souls);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}

}
}
There's a lot going on in that code, both the original and your adaptation. If you are new to modding, I'd suggest starting off with something simpler, like the Mana Heart, because I don't think I can salvage your code (there are some things in it that flat out won't work).
 
There's a lot going on in that code, both the original and your adaptation. If you are new to modding, I'd suggest starting off with something simpler, like the Mana Heart, because I don't think I can salvage your code (there are some things in it that flat out won't work).

So because im new to modding i just replicate the example item? Because thats just copying and pasting the code
 
So because im new to modding i just replicate the example item? Because thats just copying and pasting the code
And i tried to figure out how to use the example code to make my own item but its not exactly that explanatory in the smaller details. Though its definately better than just trying to look up how to start modding for terraria
 
So because im new to modding i just replicate the example item? Because thats just copying and pasting the code
Also i followed the example as closely as i could for the exclusive item while trying to make a new item and i have no idea what part of it went wrong. The file itself doesnt have any error according to VScode.
 
There's a lot going on in that code, both the original and your adaptation. If you are new to modding, I'd suggest starting off with something simpler, like the Mana Heart, because I don't think I can salvage your code (there are some things in it that flat out won't work).
well i got far less errors this time, though thats likely due to it being much simpler code, and im still trying to get the revive at half hp effect on the accessory but i still have gotten 2 errors
and i know where one of them is

Terraria.ModLoader.Exceptions.BuildException: Compiling Souls.XNA.dll failed with 2 errors and C:\Users\shefanhow1\Documents\My Games\Terraria\ModLoader\Mod Sources\Souls\Items\Acessories\Determination.cs(23,16) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?) warnings

this is the code now

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Utilities;
namespace Souls.Items.Accessories
{
public class Determination : ModItem
{
public override void SetStaticDefaults() {
Tooltip.SetDefault("When you would be killed, heal to half health");
}
public override void SetDefaults() {
item.width = 16;
item.height = 16;
item.accessory = true;
item.value = Item.sellPrice(silver: 30);
item.rare = ItemRarityID.Red;
}
public override void UpdateAccessory(Player player, bool hideVisual) {
if (player.statLife >= 50.0) {
item.healLife += 0.5f;
}

}
public override int ChoosePrefix(UnifiedRandom rand) {
// When the item is given a prefix, only roll the best modifiers for accessories
return rand.Next(new int[] { PrefixID.Arcane, PrefixID.Lucky, PrefixID.Menacing, PrefixID.Quick, PrefixID.Violent, PrefixID.Warding });
}
public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(Souls);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
well i got far less errors this time, though thats likely due to it being much simpler code, and im still trying to get the revive at half hp effect on the accessory but i still have gotten 2 errors
and i know where one of them is

Terraria.ModLoader.Exceptions.BuildException: Compiling Souls.XNA.dll failed with 2 errors and C:\Users\shefanhow1\Documents\My Games\Terraria\ModLoader\Mod Sources\Souls\Items\Acessories\Determination.cs(23,16) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?) warnings
id like to get it to being more balanced with a cool down or even just making the effect only happen a few times per life but i dont know anything about this so thats gonna have to wait about a year.
 
so according to terraria this:

(player.statLife <= 50)

is getting this error
Terraria.ModLoader.Exceptions.BuildException: Compiling Souls.XNA.dll failed with 2 errors and C:\Users\shefanhow1\Documents\My Games\Terraria\ModLoader\Mod
Sources\Souls\Items\Acessories\Determination.cs(23,16) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?) warnings
 
so according to terraria this:

(player.statLife <= 50)

is getting this error
Terraria.ModLoader.Exceptions.BuildException: Compiling Souls.XNA.dll failed with 2 errors and C:\Users\shefanhow1\Documents\My Games\Terraria\ModLoader\Mod
Sources\Souls\Items\Acessories\Determination.cs(23,16) : error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?) warnings
The errors are caused by this snippet:
C#:
if (player.statLife >= 50.0)
{
    item.healLife += 0.5f;
}
I could fix the code to remove the errors, but that wouldn't make the accessory do anything functional (item.healLife is meant for consumables). Could you tell me what you want the accessory to do?
 
The errors are caused by this snippet:
C#:
if (player.statLife >= 50.0)
{
    item.healLife += 0.5f;
}
I could fix the code to remove the errors, but that wouldn't make the accessory do anything functional (item.healLife is meant for consumables). Could you tell me what you want the accessory to do?

Well, i am making accessories based off of the soul traits from undertale,
I was hoping to make it to where you could only use one soul at a time,like the insanity gems from ultraconyx
This one would act as either a safety net accessory, where it heals you to a certain amount to prevent death, maybe 3 times per life

or make you respawn insanely fast or instantly when not on cooldown

and i wanted to make the other 6 traits but i havent gotten that far yet
 
Well, i am making accessories based off of the soul traits from undertale,
I was hoping to make it to where you could only use one soul at a time,like the insanity gems from ultraconyx
This one would act as either a safety net accessory, where it heals you to a certain amount to prevent death, maybe 3 times per life

or make you respawn insanely fast or instantly when not on cooldown

and i wanted to make the other 6 traits but i havent gotten that far yet

i was planning to use this mod as a testing grounds to try and make my own actual mod project, using this to learn how to do things with modding in terraria.
 
Back
Top Bottom