tModLoader Transmutation tome gone wrong

Saobie

Terrarian
So basically i posted a question for how to get a spell tome to spawn an item sometimes on use and got an answer for that. I thought id expand on the idea and create another tome that has a small chance to spawn a variety of ores (1/140 chance for any non hardmode ore, 1/700 chance to spawn colbat/palladium. This tome is obtainable pre-hardmode) and well basically it only spawns Iron ore, which is the first item on the list of possible items to spawn. Basically i want to know how to fix the spell tome so it can spawnn any of the items on the list

Excuse the fact that its not pasted in a code block, idk how to do that:

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace SaobiesMod.Items.Weapons
{
public class MagicTransmutationTome : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Special tome that sometimes converts mana into metal. Yields various types of metals");
}
public override void SetDefaults()
{
item.damage = 0;
item.magic = true; //this make the item do magic damage
item.width = 24;
item.height = 28;
item.useTime = 30;
item.useAnimation = 30;
item.useStyle = 5; //this is how the item is holded
item.noMelee = true;
item.knockBack = 2;
item.value = Item.buyPrice(1, 0, 0, 0);
item.rare = 6;
item.mana = 10; //mana use
item.UseSound = SoundID.Item21; //this is the sound when you use the item
item.autoReuse = true;

}
public override bool UseItem(Player player)
{
if(Main.rand.Next(1,140) == 50)
player.QuickSpawnItem(ItemID.IronOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 51)
player.QuickSpawnItem(ItemID.GoldOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 52)
player.QuickSpawnItem(ItemID.LeadOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 53)
player.QuickSpawnItem(ItemID.TungstenOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 54)
player.QuickSpawnItem(ItemID.TinOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 55)
player.QuickSpawnItem(ItemID.CopperOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 56)
player.QuickSpawnItem(ItemID.PlatinumOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 57)
player.QuickSpawnItem(ItemID.SilverOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 58)
player.QuickSpawnItem(ItemID.Meteorite);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 59)
player.QuickSpawnItem(ItemID.DemoniteOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 60)
player.QuickSpawnItem(ItemID.CrimtaneOre);
return base.UseItem(player);

if(Main.rand.Next(1,140) == 61)
player.QuickSpawnItem(ItemID.Hellstone);
return base.UseItem(player);

if(Main.rand.Next(1,700) == 556)
player.QuickSpawnItem(ItemID.PalladiumOre);
return base.UseItem(player);

if(Main.rand.Next(1,700) == 555)
player.QuickSpawnItem(ItemID.CobaltOre);
return base.UseItem(player);
}
}
}
 
First off, you'll want to return true so tModLoader knows your item actually does something.

2nd: The button is here:
0sklPXv.png


3rd: You can't "return" in the middle of your code if you expect the computer to run the rest of your code.

4th: In the future, remember that you can just call Main.rand once and store the returned value, then use that value in your logic. The way you have it the computer will make 14 different random numbers.

Also, there are a whole bunch of different ways to do this decision making, I tried to show a couple ones with easy syntax.


Code:
        public override bool UseItem(Player player)
        {
            if (Main.rand.Next(140) == 0)
            {
                int[] choices = new int[] { ItemID.IronOre, ItemID.GoldOre, ItemID.LeadOre, ItemID.TungstenOre, ItemID.TinOre,
                    ItemID.CopperOre, ItemID.PlatinumOre,ItemID.SilverOre,ItemID.Meteorite,ItemID.DemoniteOre, ItemID.CrimtaneOre, ItemID.Hellstone};
                int choice = choices[Main.rand.Next(choices.Length)];
                // or
                // int choice = Main.rand.Next(choices);
                player.QuickSpawnItem(choice);
            }
            else if (Main.rand.Next(700) == 0)
            {
                if (Main.rand.NextBool())
                {
                    player.QuickSpawnItem(ItemID.PalladiumOre);
                }
                else
                {
                    player.QuickSpawnItem(ItemID.CobaltOre);
                }
            }
            else
            {
                // No drop.
            }
            return true;
        }
 
Oh wow, the example you showed me looks very much like the random projectile code i have for a spell tome i made

I lost everything i made recently when the laptop i was using broke :/

In any event, i really appreciate the help xD ill likely use that example code for things like this since its familiar to me
 
Back
Top Bottom