Standalone [1.3] tModLoader - A Modding API

it says there is an error, but i dont know how to fix it
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LordBozo.NPCs
{
    public class MyGlobalNPC : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            if (npc.type == NPCID.Golem)      //this is where the error is at

            public override bool PreNPCLoot(NPC npc)
        {
            int rand = Main.rand.Next(0, 9);

            if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
            // Drop item 1
            else if (rand == 1)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1122);
            // Drop item 2
            else if (rand == 2)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 8899);
            else if (rand == 3)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1248);
            else if (rand == 4)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1294);
            else if (rand == 5)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1295);
            else if (rand == 6)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1296);
            else if (rand == 7)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1297);
            else if (rand == 8)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("OneRing"));  // Etc etc, untill you reach 8, where you drop your own item.

            return false;
        }
    }
    }
}
 
it says there is an error, but i dont know how to fix it
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LordBozo.NPCs
{
    public class MyGlobalNPC : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            if (npc.type == NPCID.Golem)      //this is where the error is at

            public override bool PreNPCLoot(NPC npc)
        {
            int rand = Main.rand.Next(0, 9);

            if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
            // Drop item 1
            else if (rand == 1)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1122);
            // Drop item 2
            else if (rand == 2)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 8899);
            else if (rand == 3)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1248);
            else if (rand == 4)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1294);
            else if (rand == 5)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1295);
            else if (rand == 6)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1296);
            else if (rand == 7)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1297);
            else if (rand == 8)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("OneRing"));  // Etc etc, untill you reach 8, where you drop your own item.

            return false;
        }
    }
    }
}
Corrected:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LordBozo.NPCs
{
    public class MyGlobalNPC : GlobalNPC
    {
        public override bool PreNPCLoot(NPC npc)
        {
            int rand = Main.rand.Next(0, 9);

            if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
            // Drop item 1
            else if (rand == 1)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1122);
            // Drop item 2
            else if (rand == 2)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 8899);
            else if (rand == 3)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1248);
            else if (rand == 4)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1294);
            else if (rand == 5)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1295);
            else if (rand == 6)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1296);
            else if (rand == 7)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1297);
            else if (rand == 8)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("OneRing"));  // Etc etc, untill you reach 8, where you drop your own item.

            return false;
        }
    }
}
 
Corrected:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LordBozo.NPCs
{
    public class MyGlobalNPC : GlobalNPC
    {
        public override bool PreNPCLoot(NPC npc)
        {
            int rand = Main.rand.Next(0, 9);

            if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
            // Drop item 1
            else if (rand == 1)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1122);
            // Drop item 2
            else if (rand == 2)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 8899);
            else if (rand == 3)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1248);
            else if (rand == 4)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1294);
            else if (rand == 5)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1295);
            else if (rand == 6)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1296);
            else if (rand == 7)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1297);
            else if (rand == 8)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("OneRing"));  // Etc etc, untill you reach 8, where you drop your own item.

            return false;
        }
    }
}
thanks again Iriazul :D ive been trying to figure this out for atleast 3 hours now
[doublepost=1465790434,1465789931][/doublepost]
Corrected:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LordBozo.NPCs
{
    public class MyGlobalNPC : GlobalNPC
    {
        public override bool PreNPCLoot(NPC npc)
        {
            int rand = Main.rand.Next(0, 9);

            if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
            // Drop item 1
            else if (rand == 1)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1122);
            // Drop item 2
            else if (rand == 2)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 8899);
            else if (rand == 3)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1248);
            else if (rand == 4)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1294);
            else if (rand == 5)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1295);
            else if (rand == 6)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1296);
            else if (rand == 7)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1297);
            else if (rand == 8)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("OneRing"));  // Etc etc, untill you reach 8, where you drop your own item.

            return false;
        }
    }
}
ummmm, now it doesnt do it for just the golem, it just reset the loot table for EVERYTHING

Edit: also, how can i make one of these functions drop 2 items?
 
Edit: also, how can i make one of these functions drop 2 items?

my guess is to just add an Item.NewItem line again, for example:

Code:
if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemIDHere);

as for the golem problem, my guess is
Code:
if (rand == 0 && npc.type == 245)
add && npc.type == 245 into all the rand statements

because npc type 245 is golem.

all of this is UNtested
 
Last edited:
Code:
if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemIDHere);

For those that aren't experience with C#, it is important to point out that the second call to NewItem() will always be run here and not only when rand == 0, because only the first line of code under if statements is conditional when you don't include {} around your code. This is why you should always use the curly braces.

Code:
if (rand == 0)
{
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemIDHere);
}
 
For those that aren't experience with C#, it is important to point out that the second call to NewItem() will always be run here and not only when rand == 0, because only the first line of code under if statements is run when you don't include {} around your code. This is why you should always use the curly braces.
thank you for correcting me :)
 
Code:
 public override void AI()
        {
            if (projectile.ai[0] == 1)
            {
                projectile.velocity *= 2;
            }
        }
this makes the boomerang just not come back... what am I doing wrong?
help pls
When you call the AI() hook yourself, the vanilla AI never gets called. You'll need to move that code to either PreAI or PostAI.

Also, you could try the following at the end of your PostAI hook to see what the ai array is doing.
Code:
Main.NewText("ai[0]: " + projectile.ai[0] + ", ai[1]: " + projectile.ai[1]);
 
Code:
if (rand == 0)
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemIDHere);

For those that aren't experience with C#, it is important to point out that the second call to NewItem() will always be run here and not only when rand == 0, because only the first line of code under if statements is conditional when you don't include {} around your code. This is why you should always use the curly braces.

Code:
if (rand == 0)
{
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 1258);
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemIDHere);
}


Thanks Jeckel, and thanks kreeperslayer11
 
Also, you could try the following at the end of your PostAI hook to see what the ai array is doing.

ai[0]: 0 when the projectile is out and then when it reaches where the boomerang would return It goes to 1
ai[1]: goes up really fast when the projectile is out and then returns to 0 instantly and the projectile disappears

I also moved the code I put in public override void AI() to the PostAI()
 
Last edited:
Do it just like any other weapon that shoots multiple projectiles, except use player.maxMinions as the variable in the for loop.
Thanks, but I tried to do that, and I keep getting errors in my code. Could you please help?
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TGEM.Items.Weapons
{
    public class ConjurersArrows : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "ConjurersArrows";
            item.damage = 6;
            item.summon = true;
            item.mana = 2;
            item.width = 14;
            item.height = 16;
            item.toolTip = "Shhots arrows based on max minions.";
            item.useTime = 25;
            item.useAnimation = 25;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 7;
            item.value = 10000;
            item.rare = 2;
            item.useSound = 14;
            item.autoReuse = true;
            item.shoot = (1);
            item.shootSpeed = 14f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.WoodenArrow, 100);  
            recipe.AddTile(TileID.WorkBenches);  
            recipe.SetResult(this);
            recipe.AddRecipe();

        }

public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    float spread = 45f * 0.0174f;
    float baseSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
    double startAngle = Math.Atan2(speedX, speedY)- spread/2;
    double deltaAngle = spread/8f;
    double offsetAngle;
    int = (player.maxMinions);
    {
        offsetAngle = startAngle + deltaAngle * i;
        Terraria.Projectile.NewProjectile(position.X, position.Y, baseSpeed*(float)Math.Sin(offsetAngle), baseSpeed*(float)Math.Cos(offsetAngle), item.shoot, damage, knockBack, item.owner);
    }
    return false;
}
    }
}
error at:
Code:
    int = (player.maxMinions);
 
Thanks, but I tried to do that, and I keep getting errors in my code. Could you please help?
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TGEM.Items.Weapons
{
    public class ConjurersArrows : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "ConjurersArrows";
            item.damage = 6;
            item.summon = true;
            item.mana = 2;
            item.width = 14;
            item.height = 16;
            item.toolTip = "Shhots arrows based on max minions.";
            item.useTime = 25;
            item.useAnimation = 25;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 7;
            item.value = 10000;
            item.rare = 2;
            item.useSound = 14;
            item.autoReuse = true;
            item.shoot = (1);
            item.shootSpeed = 14f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.WoodenArrow, 100); 
            recipe.AddTile(TileID.WorkBenches); 
            recipe.SetResult(this);
            recipe.AddRecipe();

        }

public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    float spread = 45f * 0.0174f;
    float baseSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
    double startAngle = Math.Atan2(speedX, speedY)- spread/2;
    double deltaAngle = spread/8f;
    double offsetAngle;
    int = (player.maxMinions);
    {
        offsetAngle = startAngle + deltaAngle * i;
        Terraria.Projectile.NewProjectile(position.X, position.Y, baseSpeed*(float)Math.Sin(offsetAngle), baseSpeed*(float)Math.Cos(offsetAngle), item.shoot, damage, knockBack, item.owner);
    }
    return false;
}
    }
}
error at:
Code:
    int = (player.maxMinions);
Your syntax is off. Here is some corrected code, with which you probably wanted to do:
Code:
public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    float spread = 45f * 0.0174f;
    float baseSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
    double startAngle = Math.Atan2(speedX, speedY)- spread/2;
    double deltaAngle = spread/8f;
    double offsetAngle;
    // Whut? >> int = (player.maxMinions);
    for(int i = 0; i < player.maxMinions; ++i)
    {
        offsetAngle = startAngle + deltaAngle * i;
        Terraria.Projectile.NewProjectile(position.X, position.Y, baseSpeed*(float)Math.Sin(offsetAngle), baseSpeed*(float)Math.Cos(offsetAngle), item.shoot, damage, knockBack, item.owner);
    }
    return false;
}
 
Your syntax is off. Here is some corrected code, with which you probably wanted to do:
Code:
public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    float spread = 45f * 0.0174f;
    float baseSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
    double startAngle = Math.Atan2(speedX, speedY)- spread/2;
    double deltaAngle = spread/8f;
    double offsetAngle;
    // Whut? >> int = (player.maxMinions);
    for(int i = 0; i < player.maxMinions; ++i)
    {
        offsetAngle = startAngle + deltaAngle * i;
        Terraria.Projectile.NewProjectile(position.X, position.Y, baseSpeed*(float)Math.Sin(offsetAngle), baseSpeed*(float)Math.Cos(offsetAngle), item.shoot, damage, knockBack, item.owner);
    }
    return false;
}
It works! Thanks, and sorry for having to ask. Also, I tried i < player.maxMinions, but without removing int, which led to that mistake in my code. :merchantconfused:
 
When you call the AI() hook yourself, the vanilla AI never gets called. You'll need to move that code to either PreAI or PostAI.

Also, you could try the following at the end of your PostAI hook to see what the ai array is doing.
Code:
Main.NewText("ai[0]: " + projectile.ai[0] + ", ai[1]: " + projectile.ai[1]);
The vanilla AI will always get called unless PreAI returns false; that's actually why it's necessary to set an NPC's aiStyle to -1 when you're using completely custom AI.
 
general question: how can i make a weapon that acts like a mana using clentaminator? any ideas?
I'd say: create a ModItem which uses the properties of the Clentaminator and make it use mana. Shouldn't be too difficult to pull off.
Most of the 'transformation' of terrain is done in the bullet code, so you don't have to worry about that.
 
Back
Top Bottom