Standalone [1.3] tModLoader - A Modding API

I have a few questions; you know with projectiles like bullets how they create the tile they hit's dust when they hit a tile? like so:
how do I make it do that with modded projectiles?
also I made a throwing-knife like item but when I use it I don't want it to appear in my hand, does anyone know how to do that?
Using the OnTileCollide hook, you'll need to call this method in the Collision class:
public static void HitTiles(Vector2 Position, Vector2 Velocity, int Width, int Height)
For your throwing knife, set item.noUseGraphic to true.
 
Hello, is there any chance you could make a tutorial on how make a mod? I know C# Myself, but that doesn't mean its not confusing.
 
Try this, replacing ????s with real values and BoosterSmoke with your mod dust, or with a vanilla dust. For a jetpack, you might also want to give the dust some y velocity and a little x velocity based on
Code:
public override void WingUpdate(Player player, bool inUse)
{
    if (inUse || player.jump > 0)
    {
        int dust = ModDust.NewDust(new Vector2(????, ???), 8, 8, mod, "BoosterSmoke");
    }
}

If you are interested, this is the Booster v0.8 code from one of my mods, it acts just like a jetpack. Notice that some of the code is superfluous as I adapted it from Vanilla Jetpack code and didn't care to change it.
Code:
public override void WingUpdate(Player player, bool inUse)
        {
           // ErrorLogger.Log("WingUpdate");
            if (inUse || player.jump > 0)
            {
                player.rocketDelay2--;
                if (player.rocketDelay2 <= 0)
                {
                    Main.PlaySound(2, Style: mod.GetSoundSlot(SoundType.Item, "Sounds/Item/BoosterSound"));
                    //Main.PlaySound(2, (int)player.position.X, (int)player.position.Y, 13);
                    player.rocketDelay2 = 10;
                }
                int num84 = 2;
                if (player.controlUp)
                {
                    num84 = 4;
                }
                num84 = 1;
                for (int num85 = 0; num85 < num84; num85++)
                {
                //    int type = 6;
                    if (player.head == 41)
                    {
                        int arg_5D0E_0 = player.body;
                    }
                    float scale = 1.75f;
                    int alpha = 100;
                    float x3 = player.position.X + (float)(player.width / 2) + 16f;
                    if (player.direction > 0)
                    {
                        x3 = player.position.X + (float)(player.width / 2) - 26f;
                    }
                    float num86 = player.position.Y + (float)player.height - 18f;
                    if (num85 == 1 || num85 == 3)
                    {
                        x3 = player.position.X + (float)(player.width / 2) + 8f;
                        if (player.direction > 0)
                        {
                            x3 = player.position.X + (float)(player.width / 2) - 20f;
                        }
                        num86 += 6f;
                    }
                    if (num85 > 1)
                    {
                        num86 += player.velocity.Y;
                    }

                    int dust = ModDust.NewDust(new Vector2(x3, num86), 8, 8, mod, "BoosterSmoke");
                    Main.dust[dust].scale = 2;
                  //  Main.dust[dust].position = position - Main.dust[dust].scale * new Vector2(4, 4);

                  //  int num87 = Dust.NewDust(new Vector2(x3, num86), 8, 8, type, 0f, 0f, alpha, default(Color), scale);
                    Dust expr_5E21_cp_0 = Main.dust[dust];
                    expr_5E21_cp_0.velocity.X = expr_5E21_cp_0.velocity.X * 0.1f;
                    Main.dust[dust].velocity.Y = Main.dust[dust].velocity.Y * 1f + 2f * player.gravDir - player.velocity.Y * 0.3f;
                    Main.dust[dust].noGravity = true;
                 //   Main.dust[num87].shader = GameShaders.Armor.GetSecondaryShader(player.cWings, this);
                    if (num84 == 4)
                    {
                        Dust expr_5EB9_cp_0 = Main.dust[dust];
                        expr_5EB9_cp_0.velocity.Y = expr_5EB9_cp_0.velocity.Y + 6f;
                    }
                }
                player.wingFrameCounter++;
                if (player.wingFrameCounter > 4)
                {
                    player.wingFrame++;
                    player.wingFrameCounter = 0;
                    if (player.wingFrame >= 3)
                    {
                        player.wingFrame = 0;
                    }
                }
            }
            else if (!player.controlJump || player.velocity.Y == 0f)
            {
                player.wingFrame = 3;
            }
        }
Hey - it keeps saying no suitable method found to override. I see no problem in the code - maybe its something else?

EDIT: I changed the override to virtual, but the GetSoundSlot seems to be acting up.
Here's the coding -
Code:
sing System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Items {
public class PoisonGasp : ModItem
{
    public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
    {
        equips.Add(EquipType.Wings);
        return true;
    }

    public override void SetDefaults()
    {
        item.name = "Poison Gasp";
        item.width = 24;
        item.height = 28;
        item.toolTip = "A breath from the void";
        item.value = 10000;
        item.rare = 8;
        item.accessory = true;
        item.defense = 8;
        item.lifeRegen = 19;
        item.expert = true;
    }
   
     public virtual void WingUpdate(Player player, bool inUse)
        {
           // ErrorLogger.Log("WingUpdate");
            if (inUse || player.jump > 0)
            {
                player.rocketDelay2--;
                if (player.rocketDelay2 <= 0)
                {
                    Main.PlaySound(2, Style: mod.GetSoundSlot(SoundType.Item, "Sounds/Item/BoosterSound"));
                    //Main.PlaySound(2, (int)player.position.X, (int)player.position.Y, 13);
                    player.rocketDelay2 = 10;
                }
                int num84 = 2;
                if (player.controlUp)
                {
                    num84 = 4;
                }
                num84 = 1;
                for (int num85 = 0; num85 < num84; num85++)
                {
                //    int type = 6;
                    if (player.head == 41)
                    {
                        int arg_5D0E_0 = player.body;
                    }
                    float scale = 1.75f;
                    int alpha = 100;
                    float x3 = player.position.X + (float)(player.width / 2) + 16f;
                    if (player.direction > 0)
                    {
                        x3 = player.position.X + (float)(player.width / 2) - 26f;
                    }
                    float num86 = player.position.Y + (float)player.height - 18f;
                    if (num85 == 1 || num85 == 3)
                    {
                        x3 = player.position.X + (float)(player.width / 2) + 8f;
                        if (player.direction > 0)
                        {
                            x3 = player.position.X + (float)(player.width / 2) - 20f;
                        }
                        num86 += 6f;
                    }
                    if (num85 > 1)
                    {
                        num86 += player.velocity.Y;
                    }

                    int dust = ModDust.NewDust(new Vector2(x3, num86), 8, 8, mod, "DarkMatter");
                    Main.dust[dust].scale = 2;
                  //  Main.dust[dust].position = position - Main.dust[dust].scale * new Vector2(4, 4);

                  //  int num87 = Dust.NewDust(new Vector2(x3, num86), 8, 8, type, 0f, 0f, alpha, default(Color), scale);
                    Dust expr_5E21_cp_0 = Main.dust[dust];
                    expr_5E21_cp_0.velocity.X = expr_5E21_cp_0.velocity.X * 0.1f;
                    Main.dust[dust].velocity.Y = Main.dust[dust].velocity.Y * 1f + 2f * player.gravDir - player.velocity.Y * 0.3f;
                    Main.dust[dust].noGravity = true;
                 //   Main.dust[num87].shader = GameShaders.Armor.GetSecondaryShader(player.cWings, this);
                    if (num84 == 4)
                    {
                        Dust expr_5EB9_cp_0 = Main.dust[dust];
                        expr_5EB9_cp_0.velocity.Y = expr_5EB9_cp_0.velocity.Y + 6f;
                    }
                }
                player.wingFrameCounter++;
                if (player.wingFrameCounter > 4)
                {
                    player.wingFrame++;
                    player.wingFrameCounter = 0;
                    if (player.wingFrame >= 3)
                    {
                        player.wingFrame = 0;
                    }
                }
            }
            else if (!player.controlJump || player.velocity.Y == 0f)
            {
                player.wingFrame = 3;
            }
        }

    public override void UpdateAccessory(Player player)
    {
        Dust.NewDust(player.Center, 0, 0, mod, "DarkMatter", (Main.rand.NextFloat() - .5f) * 1f, (Main.rand.NextFloat() - .5f) * 1f);
        {
            player.wingTimeMax = 280;
        }
    }
   

    public override void VerticalWingSpeeds(ref float ascentWhenFalling, ref float ascentWhenRising,
       ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend)
    {
        ascentWhenFalling = 0.85f;
        ascentWhenRising = 0.65f;
        maxCanAscendMultiplier = 2f;
        maxAscentMultiplier = 2f;
        constantAscend = 1.5f;
    }


    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(null, "DarkMatter", 60);
        recipe.AddTile(null, "ExampleWorkbench");
        recipe.SetResult(this);
        recipe.AddRecipe();
    }
}}
 
A virtual void is a void used for inheritance so it won't help you.

As for your error, it's because you mispelled or forgot somthing in a line with "public override void."
 
I just checked - I do not. And by the way - have you finished the Bubbline? I would love to use that!
That second piece of code was just there so you could see a complete example with sounds, dusts, and multiple item frames. Change it back to override. Update tModLoader to v0.5. If you want that sounds, here it is, otherwise comment that out or use a vanilla sound. If you use the sound, make sure to place it in Mod Sources/[modname]/Sounds/Item/. Here is current version of cavestory with bubbline.
 
You have v0.5, right? And you are extending ModItem, right?
Ok - I updated to v0.5 and now it keeps saying Vector2 could not be found. I used the coding you had given me, and I cannot find a solution.
[DOUBLEPOST=1441894226,1441894019][/DOUBLEPOST]
Hey - is there a way to add rider enemies, such as the Scutlix and the Brain Scrambler, or orbiting like the Creepers and the Brain of Cthulhu?
 
Well, I have problems with my NPC animation.
SetDefaults:
Code:
    public override void SetDefaults()
    {
        npc.name = "Sorcerer";
        npc.townNPC = true;
        npc.friendly = true;
        npc.width = 32;
        npc.height = 54;
        npc.aiStyle = 7;
        npc.damage = 10;
        npc.defense = 15;
        npc.lifeMax = 250;
        npc.soundHit = 1;
        npc.soundKilled = 1;
        npc.knockBackResist = 0.5f;
        Main.npcFrameCount[npc.type] = 24;
        NPCID.Sets.ExtraFramesCount[npc.type] = 9;
        NPCID.Sets.AttackFrameCount[npc.type] = 4;
        NPCID.Sets.DangerDetectRange[npc.type] = 700;
        NPCID.Sets.AttackType[npc.type] = 0;
        NPCID.Sets.AttackTime[npc.type] = 90;
        NPCID.Sets.AttackAverageChance[npc.type] = 30;
        animationType = NPCID.Guide;
    }
RUFirO9.png
 
Hey - is there a way to add rider enemies, such as the Scutlix and the Brain Scrambler, or orbiting like the Creepers and the Brain of Cthulhu?
That's pretty easy to do. At least, pretty easy if you know how to program.
That's also the kind of thing where you have to know how to program.

Well, I have problems with my NPC animation.
SetDefaults:
Code:
    public override void SetDefaults()
    {
        npc.name = "Sorcerer";
        npc.townNPC = true;
        npc.friendly = true;
        npc.width = 32;
        npc.height = 54;
        npc.aiStyle = 7;
        npc.damage = 10;
        npc.defense = 15;
        npc.lifeMax = 250;
        npc.soundHit = 1;
        npc.soundKilled = 1;
        npc.knockBackResist = 0.5f;
        Main.npcFrameCount[npc.type] = 24;
        NPCID.Sets.ExtraFramesCount[npc.type] = 9;
        NPCID.Sets.AttackFrameCount[npc.type] = 4;
        NPCID.Sets.DangerDetectRange[npc.type] = 700;
        NPCID.Sets.AttackType[npc.type] = 0;
        NPCID.Sets.AttackTime[npc.type] = 90;
        NPCID.Sets.AttackAverageChance[npc.type] = 30;
        animationType = NPCID.Guide;
    }
RUFirO9.png
You need to set Main.npcFrameCount[npc.type] to the total number of frames your NPC has. Then ExtraFramesCount needs to be set to the number of frames that are below the walking frames.
 
Add "using Microsoft.Xna.Framework;" to top.
Hey - this code doesn't work. I want to spawn a projectile at the cursor, here's the code;
Code:
public override bool UseItem(Player player)
        {
            Projectile.NewProjectile((int)(Main.screenPosition.X + Main.mouseX), (int)(Main.screenPosition.Y + Main.mouseY), mod.ProjectileType("Bloodburst"), 0f, Main.npc, Main.mouseX, Main.mouseY);
            return true;
        }
 
Hey - this code doesn't work. I want to spawn a projectile at the cursor, here's the code;
Code:
public override bool UseItem(Player player)
        {
            Projectile.NewProjectile((int)(Main.screenPosition.X + Main.mouseX), (int)(Main.screenPosition.Y + Main.mouseY), mod.ProjectileType("Bloodburst"), 0f, Main.npc, Main.mouseX, Main.mouseY);
            return true;
        }
Well, given that the method signature is

public static int NewProjectile(float X, float Y, float SpeedX, float SpeedY, int Type, int Damage, float KnockBack, int Owner = 255, float ai0 = 0f, float ai1 = 0f)

I'm not sure why you have most of those, especially Main.npc. What are you trying to do? Are you sure you don't want to override Shoot?
 
Back
Top Bottom