Standalone [1.3] tModLoader - A Modding API

Can you post the entire code in a code block?
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using imkSushisModDropsAddon.NPCs;

namespace imkSushisModDropsAddon {
public class imkSushisModDropsAddon : Mod
{
       public override void SetModInfo(out string name, ref ModProperties properties)
    {
        name = "imkSushisModDropsAddon";
        properties.Autoload = true;
    }
    public override void Load()
    {
    if ((item.type == 3335 ) && player.extraAccessory)
        {
            flag2 = true;
        }
    }
}}
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using imkSushisModDropsAddon.NPCs;

namespace imkSushisModDropsAddon {
public class imkSushisModDropsAddon : Mod
{
       public override void SetModInfo(out string name, ref ModProperties properties)
    {
        name = "imkSushisModDropsAddon";
        properties.Autoload = true;
    }
    public override void Load()
    {
    if ((item.type == 3335 ) && player.extraAccessory)
        {
            flag2 = true;
        }
    }
}}

What exactly are you trying to do? It looks like you're trying to do something with the Demon Heart, but at any rate you shouldn't be doing that in the Load method of your Mod override.
 
What exactly are you trying to do? It looks like you're trying to do something with the Demon Heart, but at any rate you shouldn't be doing that in the Load method of your Mod override.
What method should I be trying to use?
I am making the Demon Heart work in Normal Mode, and I need the ability to use it first.
 
What method should I be trying to use?
I am making the Demon Heart work in Normal Mode, and I need the ability to use it first.
Since there hasn't been an answer yet, allow me:
First you'll want to make a class that derives from GlobalItem. In there, you'll basically want to put in the Demon Heart functionality, taking away the expert mode check:
Code:
public class MyGlobalItem : GlobalItem
{
    public override bool CanUseItem(Item item, Player player)
    {
        if (item.type == 3335 && player.itemAnimation > 0 && !player.extraAccessory && player.itemTime == 0)
        {
            player.itemTime = item.useTime;
            player.extraAccessory = true;
            NetMessage.SendData(4, -1, -1, Main.player[player.whoAmI].name, player.whoAmI, 0f, 0f, 0f, 0, 0, 0);
        }
        return true;
    }
}
Now I'm not sure if this will also play the use animation.. (untested).
 
can you help with the animation please?
[DOUBLEPOST=1457393388,1457393269][/DOUBLEPOST]and after animation, how do you make a mob randomly teleport?
 
can you help with the animation please?
Problem is: animations for projectiles and NPCs (which I think you refer to as monsters) are both handled differently.
The ModNPC class has an overridable function:
Code:
public override void FindFrame(int frameHeight)
{
}
In there you can use npc.frameCounter as some sort of 'timer' for the speed of your animation. Then you can check that value against something of your choosing (higher value = slower animation), reset npc.frameCounter and do something like npc.frame.Y = npc.frame.Y + frameHeight; to set the correct animation frame.
Also, don't forget to set Main.npcFrameCount[npc.type] to the correct amount of frames in the SetDefaults method of your NPC.

Now for ModProjectiles you'll want to integrate the animating into the AI. Set Main.projFrames[projectile.type] to the correct amount of animation frames in your SetDefaults method and repeat the same process as with the NPC, but inside the PreAI, AI of PostAI function. Also, you can just set projectile.frame to the current frame ID (since we don't have frameHeight of some sorts).

Randomly teleporting an NPC falls under AI, and I do recommend you to try and make that yourself (using Terraria's source preferably).
 
public override void FindFrame(int frameHeight)
{
npc.frameCounter = 2;
npc.frame.Y = npc.frame.Y + frameHeight;
Main.npcFrameCount[npc.type] = 3;
}

Would this be a working setup?
 
public override void FindFrame(int frameHeight)
{
npc.frameCounter = 2;
npc.frame.Y = npc.frame.Y + frameHeight;
Main.npcFrameCount[npc.type] = 3;
}

Would this be a working setup?
Nope :p
First of all, you'll want to set the npcFrameCount value in the SetDefaults method of your NPC.
Then you'll want to add one to frameCounter. When frameCounter exceeds a certain value of your choosing, you'll want to set npc.frame.Y and also make sure to set it back if it exceeds the total amount of frames there are. Example:
Code:
public override void SetDefaults()
{
    // Rest of your SetDefaults stuff.
    Main.npcFrameCount[npc.type] = 3;
}

public override void FindFrame(int frameHeight)
{
    npc.frameCounter++;
    if(npc.frameCounter >= 30) // Switches frames every half second.
    {
        npc.frameCounter = 0.0;
        npc.frame.Y = npc.frame.Y + frameHeight;        
        if (npc.frame.Y >= frameHeight * Main.npcFrameCount[npc.type])
                    npc.frame.Y = 0;
    }
}
 
Nope :p
First of all, you'll want to set the npcFrameCount value in the SetDefaults method of your NPC.
Then you'll want to add one to frameCounter. When frameCounter exceeds a certain value of your choosing, you'll want to set npc.frame.Y and also make sure to set it back if it exceeds the total amount of frames there are. Example:
Code:
public override void SetDefaults()
{
    // Rest of your SetDefaults stuff.
    Main.npcFrameCount[npc.type] = 3;
}

public override void FindFrame(int frameHeight)
{
    npc.frameCounter++;
    if(npc.frameCounter >= 30) // Switches frames every half second.
    {
        npc.frameCounter = 0.0;
        npc.frame.Y = npc.frame.Y + frameHeight;       
        if (npc.frame.Y >= frameHeight * Main.npcFrameCount[npc.type])
                    npc.frame.Y = 0;
    }
}
Waaaaaaa.... I dont understand what that is
 
Need help My ore doesnt seem to be generating from what i can tell. Although the mod does load.
Below are the NewOreTile, The New Ore (Item) and The Mod Gen for the Generation of the Ore. I could have names mixed up.

Have been getting this error -

Index was outside the bounds of the array.
at Terraria.World.Generation.StructureMap.CanPlace(Rectangle area, Boolean[] validTiles, Int32 padding)
at Terraria.GameContent.Biomes.CaveHouseBiome.Place(Point origin, StructureMap structures)
at Terraria.World.Generation.Biomes`1.Place(Int32 x, Int32 y, StructureMap structures)
at Terraria.WorldGen.<>c__DisplayClass93.<generateWorld>b__37(GenerationProgress progress)
at Terraria.GameContent.Generation.PassLegacy.Apply(GenerationProgress progress)
at Terraria.World.Generation.WorldGenerator.GenerateWorld(GenerationProgress progress)
at Terraria.WorldGen.generateWorld(Int32 seed, GenerationProgress customProgressObject)
at Terraria.WorldGen.do_worldGenCallBack(Object threadContext)
at Terraria.WorldGen.worldGenCallBack(Object threadContext)


Code:
ExampleMod - The Gen code

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
using Terraria.GameContent.Generation;

namespace DarkArmorReforged.Tiles.Block
{
    public class ExampleMod : ModWorld
    {


public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

tasks.Insert(ShiniesIndex + 1, new PassLegacy("New Ore", delegate (GenerationProgress progress)
{
progress.Message = "Adding New Ore...";

for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
{
WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("OreTile"), false, 0f, 0f, false, true);
}
}));
}
}
}

Code:
The Tile Code

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

namespace DarkArmorReforged.Tiles.Block
{
    public class OreTile : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            AddMapEntry(new Color(200, 200, 200));

        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            r = 0.5f;
            g = 0.5f;
            b = 0.5f;
        }
    }
}

Code:
Ore Item, is also craftable.

using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;

namespace DarkArmorReforged.Items.Ores
{
    public class NewOre : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "New Ore";
            item.width = 12;
            item.height = 12;
            item.maxStack = 999;
            AddTooltip("Crafts an Example Ore");
            item.useTurn = true;
            item.autoReuse = true;
            item.useAnimation = 15;
            item.useTime = 10;
            item.useStyle = 1;
            item.consumable = true;
            item.createTile = mod.TileType("NewOre");
            ItemID.Sets.ExtractinatorMode[item.type] = item.type;

        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "EquipMaterial");
                        recipe.AddTile(TileID.WorkBenches);
                        recipe.SetResult(this, 10);
            recipe.AddRecipe();
        }

        public override void ExtractinatorUse(ref int resultType, ref int resultStack)
        {
            if (Main.rand.Next(30) == 0)
            {
                resultType = mod.ItemType("FoulOrb");
                if (Main.rand.Next(5) == 0)
                {
                    resultStack += Main.rand.Next(2);
                }
            }
        }
    }
}
 
Hello hello Terraria community. So I've had Terraria on the Xbox for a long long time, but I just recently in August picked it up for the PC and got back into it again. Im just now coming around to getting into mods, but I have absolutely no experience with coding. If I want to create my own mod, where should I start? I am a complete beginner, never made a mod for any game before, but I am very interested and of course willing to learn. Any help is very appreciated, and thanks in advance.
 
Hello hello Terraria community. So I've had Terraria on the Xbox for a long long time, but I just recently in August picked it up for the PC and got back into it again. Im just now coming around to getting into mods, but I have absolutely no experience with coding. If I want to create my own mod, where should I start? I am a complete beginner, never made a mod for any game before, but I am very interested and of course willing to learn. Any help is very appreciated, and thanks in advance.
Well for starters you should learn c# and after that look how the example mod works. And if you need help you can always come here to ask for help :p
 
Really important question would a second form boss be in a seperate cs file ? and then linked to the main boss ? How would i go about this and also would the animation on the first form support the second form or would that be seperate too ?
 
Index was outside the bounds of the array.
at Terraria.World.Generation.StructureMap.CanPlace(Rectangle area, Boolean[] validTiles, Int32 padding)
at Terraria.GameContent.Biomes.CaveHouseBiome.Place(Point origin, StructureMap structures)
at Terraria.World.Generation.Biomes`1.Place(Int32 x, Int32 y, StructureMap structures)
at Terraria.WorldGen.<>c__DisplayClass93.<generateWorld>b__37(GenerationProgress progress)
at Terraria.GameContent.Generation.PassLegacy.Apply(GenerationProgress progress)
at Terraria.World.Generation.WorldGenerator.GenerateWorld(GenerationProgress progress)
at Terraria.WorldGen.generateWorld(Int32 seed, GenerationProgress customProgressObject)
at Terraria.WorldGen.do_worldGenCallBack(Object threadContext)
at Terraria.WorldGen.worldGenCallBack(Object threadContext)
Your code is fine. I forgot about a bug we fixed after the release related to this. You'll have to move your generation pass to later than the "Buried Chests" pass for the time being. (change "shinies")

Really important question would a second form boss be in a seperate cs file ? and then linked to the main boss ? How would i go about this and also would the animation on the first form support the second form or would that be seperate too ?
You can do it either way. For example, Eye of Chtulu just changes it's behavior when it is at half health. Golem spawns the floating head which is a separate npc.

The animation can all be on the same sheet. You can just check for the condition you want in the FindFrame method. Here is how it looks for EoC (num is frame height):
Code:
this.frameCounter += 1.0;
                if (this.frameCounter < 7.0)
                {
                    this.frame.Y = 0;
                }
                else if (this.frameCounter < 14.0)
                {
                    this.frame.Y = num;
                }
                else if (this.frameCounter < 21.0)
                {
                    this.frame.Y = num * 2;
                }
                else
                {
                    this.frameCounter = 0.0;
                    this.frame.Y = 0;
                }
                if (this.ai[0] > 1f)
                {
                    this.frame.Y = this.frame.Y + num * 3;
                    return;
                }
            }

And here is the corresponding texture file:
PJtxljs.png


Hope you can learn from this example.
 
Thankyou, i can now generate ore, i will not be downloading the Thorium Mod as i had been working on a better copy for my self. Which is awesome as.

This requires code for the health then ? I want the boss to change behaviour once it hits half way health.
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
using Terraria.GameContent.Generation;

namespace Enderuim.Tiles   
    {
        public class EnderuimOre : ModWorld
        {
            public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Crazy Ore", delegate (GenerationProgress progress){;
            {
                progress.Message = "Growing Enderuim Crystals...";

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("EnderuimOre"), false, 0f, 0f, false, true);
                }
            };
        }));
    }
}}
This code doesnt seem to be generating anything, I was wondering if you could point whats wrong out...
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
using Terraria.GameContent.Generation;

namespace Enderuim.Tiles  
    {
        public class EnderuimOre : ModWorld
        {
            public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Crazy Ore", delegate (GenerationProgress progress){;
            {
                progress.Message = "Growing Enderuim Crystals...";

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("EnderuimOre"), false, 0f, 0f, false, true);
                }
            };
        }));
    }
}}
This code doesnt seem to be generating anything, I was wondering if you could point whats wrong out...
I think this issue has been resolved about... Two-three posts above here...?
 
As jopojelly said

I forgot about a bug we fixed after the release related to this. You'll have to move your generation pass to later than the "Buried Chests" pass for the time being. (change "shinies")

Also this part is for the tile : Did you name it correctly as you have crazy ore than you have EnderuimOre ? Unless you called it that. Where you have crazy ore is the actual ore item.

WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("EnderuimOre"), false, 0f, 0f, false, true);
[DOUBLEPOST=1457435909,1457435735][/DOUBLEPOST]Eldrazi is it possible to change the tiles to support 4x4 and up ? for objects which ore longer. Like long tables ect.
 
Back
Top Bottom