tModLoader Official tModLoader Help Thread

How can I make it to where an NPC will only spawn if I have a certain type of item? For example, I want my Mask Salesman to only spawn if you have any mask in your inventory.
 
hello i'm new to modding and i think it's pretty easy but i do have a problem, i cant seem to find the code for armor buffs anywhere on the internet. can a brother get some help please!
 
hello i'm new to modding and i think it's pretty easy but i do have a problem, i cant seem to find the code for armor buffs anywhere on the internet. can a brother get some help please!
What do you mean by 'armor buffs'? Could you please specify?
 
im talking about buffs like immune to fire and such things like that
Immunity to the 'On Fire!' debuff is actually not prevented by another buff.
You'll want to look into the 'buffImmune' array in player. For example this:
Code:
player.buffImmune[BuffID.OnFire] = true;
Will result in immunity to the On Fire! debuff.
 
I don't really understand your guide to the yoyos... how do you make fully custom yoyos?
If you want to know how yoyo's work (and thus make custom yoyo's) you'll have to understand the code/AI behind it.
Look up the yoyo AI in the source and try to comprehend (at least some of) it. Then you'll know how to customize it and create your own yoyo AI/behaviour.
 
I don't really understand your guide to the yoyos... how do you make fully custom yoyos?
yoyo's are a bit weird. The easiest thing is to make your own ModItem can clone the defaults of the wooden yoyo. this is the base for all yoyo's in the game. the aiStyle takes care of it actually being a yoyo.
use: item.CloneDefaults(3278);
You'll need to make your own projectile for item.shoot though, I dont think it'll shoot a proper yoyo projectile else.
 
So I basically want my sword to make it's projectile come from the sky from above enemies when the blade makes contact with enemies
I would also like to know how to make a projectile spawn another projectile on the projectile's death
 
So I basically want my sword to make it's projectile come from the sky from above enemies when the blade makes contact with enemies
I would also like to know how to make a projectile spawn another projectile on the projectile's death

For spawning another projectile to spawn from a projectile's death, you use this code...

For projectile C# file
Code:
public override void Kill(Int timeLeft)
{
    Projectile.NewProjectile(positionX, positionY, velocityX, velocityY, type, damage, knockback, owner, ai[0], ai[1]); //Note, fill in the properties yourself.
}

And for when your blade hits an enemy you want to spawn a projectile...

For item C# file
Code:
public virtual void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
    Projectile.NewProjectile(target.position.X, target.positionY - 100f, 0, 8, int type, int damage, float knockBack, Main.myPlayer, 0f, 0f);
}

Projectile.NewProjectile requires...

Code:
Projectile.NewProjectile(float positionX, float positionY, float velocityX, float velocityY, int type, int damage, float knockBack, int owner, float ai[0], float ai[1]);
 
For spawning another projectile to spawn from a projectile's death, you use this code...

For projectile C# file
Code:
public override void Kill(Int timeLeft)
{
    Projectile.NewProjectile(positionX, positionY, velocityX, velocityY, type, damage, knockback, owner, ai[0], ai[1]); //Note, fill in the properties yourself.
}

And for when your blade hits an enemy you want to spawn a projectile...

For item C# file
Code:
public virtual void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
    Projectile.NewProjectile(target.position.X, target.positionY - 100f, 0, 8, int type, int damage, float knockBack, Main.myPlayer, 0f, 0f);
}

Projectile.NewProjectile requires...

Code:
Projectile.NewProjectile(float positionX, float positionY, float velocityX, float velocityY, int type, int damage, float knockBack, int owner, float ai[0], float ai[1]);
I got this error
upload_2016-1-29_21-34-48.png

My code
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TEM.Items.Hardmode.Weapons
{
    public class Apophis : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Apophis";
            item.damage = 100;
            item.melee = true;
            item.width = 66;
            item.height = 66;
            item.useTime = 20;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 10;
            item.value = 0;
            item.rare = 10;
            item.useSound = 1;
            item.autoReuse = true;
            item.shootSpeed = 10;
            item.shoot = mod.ProjectileType("ApophisRock");
        }
        public override Color? GetAlpha(Color lightColor)
        {
            return Color.White;
        }
        public virtual void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
            Projectile.NewProjectile(target.position.X, target.positionY - 100f, 0, 8, int type, int damage, float knockBack, Main.myPlayer, 0f, 0f);
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.FragmentSolar, 18);
            recipe.AddTile(TileID.LunarCraftingStation);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
    }
}
 
I got this error
View attachment 94528
My code
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TEM.Items.Hardmode.Weapons
{
    public class Apophis : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Apophis";
            item.damage = 100;
            item.melee = true;
            item.width = 66;
            item.height = 66;
            item.useTime = 20;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 10;
            item.value = 0;
            item.rare = 10;
            item.useSound = 1;
            item.autoReuse = true;
            item.shootSpeed = 10;
            item.shoot = mod.ProjectileType("ApophisRock");
        }
        public override Color? GetAlpha(Color lightColor)
        {
            return Color.White;
        }
        public virtual void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
            Projectile.NewProjectile(target.position.X, target.positionY - 100f, 0, 8, int type, int damage, float knockBack, Main.myPlayer, 0f, 0f);
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.FragmentSolar, 18);
            recipe.AddTile(TileID.LunarCraftingStation);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
    }
}

You gotta set the parameters of the stuff in the parenthesis. int type, just set to your projhectile with item.shoot and make your int damage an integer like 10, float knockBack like 4f. Also set the where you see the 0 and 8 are velocity X and the velocity Y respectively. So set them with a float number.
 
You gotta set the parameters of the stuff in the parenthesis. int type, just set to your projhectile with item.shoot and make your int damage an integer like 10, float knockBack like 4f. Also set the where you see the 0 and 8 are velocity X and the velocity Y respectively. So set them with a float number.
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TEM.Items.Hardmode.Weapons
{
    public class Apophis : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Apophis";
            item.damage = 100;
            item.melee = true;
            item.width = 66;
            item.height = 66;
            item.useTime = 20;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 10;
            item.value = 0;
            item.rare = 10;
            item.useSound = 1;
            item.autoReuse = true;
            item.shootSpeed = 10;
            item.shoot = mod.ProjectileType("ApophisRock");
        }
        public override Color? GetAlpha(Color lightColor)
        {
            return Color.White;
        }
        public virtual void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
            Projectile.NewProjectile(target.position.X, target.positionY - 100f, 0, 8, mod.ProjectileType("ApophisRock"), 10, 4f, Main.myPlayer, 0f, 0f);
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.FragmentSolar, 18);
            recipe.AddTile(TileID.LunarCraftingStation);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
    }
}
I built that and got this error
upload_2016-1-29_22-51-16.png
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TEM.Items.Hardmode.Weapons
{
    public class Apophis : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Apophis";
            item.damage = 100;
            item.melee = true;
            item.width = 66;
            item.height = 66;
            item.useTime = 20;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 10;
            item.value = 0;
            item.rare = 10;
            item.useSound = 1;
            item.autoReuse = true;
            item.shootSpeed = 10;
            item.shoot = mod.ProjectileType("ApophisRock");
        }
        public override Color? GetAlpha(Color lightColor)
        {
            return Color.White;
        }
        public virtual void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
            Projectile.NewProjectile(target.position.X, target.positionY - 100f, 0, 8, mod.ProjectileType("ApophisRock"), 10, 4f, Main.myPlayer, 0f, 0f);
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.FragmentSolar, 18);
            recipe.AddTile(TileID.LunarCraftingStation);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
    }
}
I built that and got this error
View attachment 94541
It seems I forgot to put a "." between "position" and "y".
 
Back
Top Bottom