Just remove the parentheses around BuffID.WellFedHow would I make an edible item grant the well-fed buff?
I have this, but my gut feeling tells me that it's incorrect.
Code:public bool UseItem(Item item, Player player) { player.AddBuff((BuffID.WellFed) , 6000, true); return false; }
You don't need to do that - You can just putHow would I make an edible item grant the well-fed buff?
I have this, but my gut feeling tells me that it's incorrect.
Code:public bool UseItem(Item item, Player player) { player.AddBuff((BuffID.WellFed) , 6000, true); return false; }
item.buffType = BuffID.WellFed;
and item.buffTime = 6000;
in SetDefaultsSome vanilla accessories will change a variable in player, likeHmmmmm...
I am making a mod that extends on mod milestones called Banners++ (Apparently, I soon realized that there was a Banners+ too. Might rename if I have to.)
Only, one problem, how do you detect a player wearing an accessory?
I know it has to be something like (player. == true) and I also know that this question is extremely dumb and I should know better.
I just can't exactly pinpoint my finger on it...
player.accFlipper
for the flipper accessory, but for all others, I spotted some Item[] in Player called inventory
, miscEquips
and armor
. You'll have to loop through the correct one out of them (there might be others I missed) and manually check, as far as I know there is no convenient method for it.Thanks for the reply!Some vanilla accessories will change a variable in player, likeplayer.accFlipper
for the flipper accessory, but for all others, I spotted some Item[] in Player calledinventory
,miscEquips
andarmor
. You'll have to loop through the correct one out of them (there might be others I missed) and manually check, as far as I know there is no convenient method for it.
I think for that you're going to have to subclassThanks for the reply!
I also have another question...
What about specific accessories? I want a vanilla enemy to be able to detect my modded accessories. Again, sorry if this sounds dumb.
GlobalNPC
and in AI()
you'll have to first check the NPC type (if it's the one you want to detect accessories) and loop through Main.player
and check each players inventory, maybe only if the player is within a certain distance of the NPC (or whatever your additional criteria). When you're looping through player.inventory
, player.miscEquips
or player.armor
(whichever contains accessories, bit of trial and error to find out), you can just check each item with something like if(item.type == ModContent.ItemType<MyModdedAccessory>()) {
}
You'll need a static global bool likeDoes anyone know how to make a boss generate an ore underground? I have the scripts for actually generating the ore down, but my issue is the generation after killing a boss part of it. It either doesn't work, or I can just restart the game and kill the boss again and then the ore generates more.
public static bool hasGeneratedOre
in one of your classes, and only generate ore when that boss is defeated if hasGeneratedOre is false, and then you'll obviously need to set it to true after that. To keep this variable across each time you enter the world, you'll need to have a subclass of ModWorld and override Load
and Save
like so:public override TagCompound Save()
{
return new TagCompound
{
{"hasGeneratedOre", hasGeneratedOre}
};
}
public override void Load(TagCompound tag)
{
hasGeneratedOre = tag.GetBool("hasGeneratedOre");
}
Alright, thanks so much!I think for that you're going to have to subclassGlobalNPC
and inAI()
you'll have to first check the NPC type (if it's the one you want to detect accessories) and loop throughMain.player
and check each players inventory, maybe only if the player is within a certain distance of the NPC (or whatever your additional criteria). When you're looping throughplayer.inventory
,player.miscEquips
orplayer.armor
(whichever contains accessories, bit of trial and error to find out), you can just check each item with something like
Code:if(item.type == ModContent.ItemType<MyModdedAccessory>()) { }
Probably be useful to create a Helper class with some commonly used/useful functions in, like hasInInventory and hasEquippedAccessoryAlright, thanks so much!
Even though that is a complicated process, I will learn.
You can probably change that in GlobalTile, but I wouldn't know how sorryI’m new to modding and planning on adding a Flower that only spawns in crimson, but for it to make sense I need to make the Deathweed stop spawning in the crimson. I have the code for a flower, but I don’t know how to stop the Deathweed from spawing.
(If anyone wants to know I’m going to make each flower make a potion)
That’s ok, now I can look up Global Tiles since I have not heard of those.Probably be useful to create a Helper class with some commonly used/useful functions in, like hasInInventory and hasEquippedAccessory
You can probably change that in GlobalTile, but I wouldn't know how sorry
Add [AutoloadHead] before the public class line. Like this:How do you assign a town NPC head sprite to a town NPC? Is it a line of code? Do you have to name the head sprite file something special?
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
namespace ModName.NPCs
{
[AutoloadHead]
public class ModNPC : ModNPC
{
It most likely seems to be due to the fact that the stone block is a vanilla item. Thus, you can do this:Here is some code for an item I'm making, the game seems to load it perfectly fine, but it does not shoot, and it always displays 0 ammo. I knew it probably wouldn't work, as I'm not experienced in coding, and I had nothing to go off of here. I'm wondering if someone can help me to get the slingshot item to use stone blocks instead of typical ammunition.
public class Slingshot : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Uses stone.");
}
public override void SetDefaults()
{
item.damage = 15;
item.ranged = true;
item.width = 20;
item.height = 33;
item.useTime = 25;
item.useAnimation = 25;
item.crit = 13;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 3;
item.value = 200;
item.rare = 1;
item.UseSound = SoundID.Item5;
item.autoReuse = false;
item.shoot = mod.ProjectileType("StoneProj");
item.shootSpeed = 25f;
item.useAmmo = ItemID.StoneBlock;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Cobweb, 3);
recipe.AddIngredient(ModContent.ItemType<Stick>(), 1);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System;
using Terraria.DataStructures;
using Terraria.Localization;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Linq;
namespace ModName.Items
{
public class StoneBlock : GlobalItem
{
public override void SetDefaults(Item item) {
if (item.type == ItemID.StoneBlock) {
item.damage = 15;
item.ranged = true;
item.shoot = mod.ProjectileType("StoneProj");
item.ammo = item.type; // This makes it so the ammo type of this Stone Block is the first one in it's class.
//item.ammo = ItemID.StoneBlock; // An alternative way to do it, since this is a vanilla item, it has an ID.
}
}
}
}
public static void AI(Item item, Player player, NPC npc) {
if (npc.type == 2) {
if (player.miscEquips) {
if (item.type == ModContent.ItemType<SightNecklace>()) {
npc.friendly = true;
npc.aiStyle = 24;
npc.damage = 0;
}
}
}
}