i normally use right click but thats just me
he means something like this
------------------------------------------------------------ this is the right click function
public override bool CanRightClick()
{
return true;
}
public override void RightClick(Player player)
------------------------------------------------------------
{
int f = Main.rand.Next(0, 5);
if(f >= 0 && f <= 0)
{
player.QuickSpawnItem(mod.ItemType("item1"));
}
else if(f >= 1 && f <= 1)
{
player.QuickSpawnItem(mod.ItemType("item2"));
}
else if(f >= 2 && f <= 2)
{
player.QuickSpawnItem(mod.ItemType("item3"));
}
else if(f >= 3 && f <= 3)
{
player.QuickSpawnItem(mod.ItemType("item4"));
}
else if(f >= 4 && f <= 4)
{
player.QuickSpawnItem(mod.ItemType("item5"));
}
}
Why are you not just checking f for equality (f == 0)? Isn't that a lot easier?
I'm sorry for asking this but how do I set that up?
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace EpicnessModRemastered.Items
{
public class SuperMagicalChest : ModItem
{
public override void SetDefaults()
{
item.name = "Super Magical Chest";
item.maxStack = 1;
item.consumable = true;
item.width = 24;
item.height = 24;
item.useTime = 10;
item.useAnimation = 10;
item.useStyle = 4;
item.toolTip = "Left click to open";
item.rare = 10;
item.useSound = mod.GetSoundSlot(SoundType.Item, "Sounds/Item/Legendaryget");
}
public override bool UseItem(Player player)
{
(Main.rand.Next(3) == int result Main.rand.Next(3));,
if (int result Main.rand.Next(3); == 0)
{
player.QuickSpawnItem(mod.ItemType("SparkyCard"));
}
else if (int result Main.rand.Next(3); == 1)
{
player.QuickSpawnItem(mod.ItemType("LumberJacksAxe"));
}
else if (int result Main.rand.Next(3); == 2)
{
player.QuickSpawnItem(mod.ItemType("PrincessesBow"));
}
return true;
}
}
}
Good start, but I'll explain where and why you went wrong.
What you need to do is to create a variable at the start of UseItem, and then you can do whatever you want with that variable until UseItem is finished (then it's discarded). So first, to declare a variable, you need to use the format <type - identifier - assignment (optional)>. This means, from left to right, what kind of variable you want, what it's called, and what value you want it to start it with respectively.
Because you want an integer (whole number) called
result, you should type
int result;. But because you want to put a random number in it, you have to assign (=) the result of the game's random number generator (
Main.rand.Next(5), which means you are generating one of five different numbers (0, 1, 2, 3 and 4)). So that becomes:
Code:
int result = Main.rand.Next(5);
Now you have that value, you can check your if-statements against it, like so:
Code:
if (result == 0)
{
// Stuff.
}
else if (result == 1)
{
// Stuff.
}
// And so on.
You don't have to use
int anymore, because the script remembers that
result is an integer; if you use
int again, the code thinks you're trying to make a new variable with the same name, which isn't allowed. You also don't have to use Main.rand.Next() anymore, because you only need to assign that random value once.
Hope that clears things up for you.