Standalone [1.3] tModLoader - A Modding API

shadow does the freeze thing happen when u go in mod browser?

ModItem.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, "OrcaFin", 1);
Got an error after fixing like 4 other errors
error CS0117: 'Terraria.ModLoader.ModItem' does not contain a definition for 'NewItem'
I wanna know what i should replace NewItem with so it matches with ModItem
 
Not sure if this was mentioned already, but I seem to have ran into a bug where no projectiles are seen even though my ammo is being used. The same thing happens when I try to use spears and yoyos; I can't see them and they don't appear to break any grass so it's not just a visual bug.
 
Not sure if this was mentioned already, but I seem to have ran into a bug where no projectiles are seen even though my ammo is being used. The same thing happens when I try to use spears and yoyos; I can't see them and they don't appear to break any grass so it's not just a visual bug.

Going to interject here quickly and note the following:
Zekrom2 had a similar (if not identical issue), but following this thread since the post I haven't seen it resolved, he could however help shed some light on this issue if he solved it in the interim perhaps.
Further, in the events Jopojelly or the others see the following string, they might be able to identify why the ammo consumption and 'invisibility of projectiles' is occuring and this might be of some use to you.

Hey guys, I made a modded bullet but for some reason when I shoot it from my modded gun, it does not appear and does not deal any damage. Yet it still consumes ammo. This is my projectile code:
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TheDankMod.Projectiles
{
    public class TheLazerShot : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "The Lazor Shot";
            projectile.width = 8;
            projectile.height = 8;
            projectile.aiStyle = 1;
            projectile.friendly = true;
            projectile.ranged = true;
            projectile.penetrate = 1;
            projectile.timeLeft = 600;
            projectile.alpha = 255;
            projectile.light = 0.5f;
            projectile.extraUpdates = 1;
            ProjectileID.Sets.TrailCacheLength[projectile.type] = 5;
            ProjectileID.Sets.TrailingMode[projectile.type] = 0;
            projectile.aiStyle = 75;
            projectile.hide = true;

        }

        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            projectile.penetrate--;
            if (projectile.penetrate <= 0)
            {
                projectile.Kill();
            }
            else
            {
                if (projectile.velocity.X != oldVelocity.X)
                {
                    projectile.velocity.X = -oldVelocity.X;
                }
                if (projectile.velocity.Y != oldVelocity.Y)
                {
                    projectile.velocity.Y = -oldVelocity.Y;
                }
                Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 10);
            }
            return false;
        }

        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
            for (int k = 0; k < projectile.oldPos.Length; k++)
            {
                Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
                Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
                spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
            }
            return true;
        }
    }
}

This is my gun's code :
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TheDankMod.Items.Weapons
{
    public class TheLazorShot : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "The Lazor Shot";
            item.damage = 20;
            item.ranged = true;
            item.width = 80;
            item.height = 60;
            item.toolTip = "'IMMA FIRIN' MAH LAZAHHHHH'";
            item.useTime = 20;
            item.useAnimation = 20;
            item.useStyle = 5;
            item.noMelee = true; //so the item's animation doesn't do damage
            item.knockBack = 4;
            item.value = 10000;
            item.rare = 2;
            item.UseSound = SoundID.Item11;
            item.autoReuse = true;
            item.shoot = 10; //idk why but all the guns in the vanilla source have this
            item.shootSpeed = 16f;
            item.useAmmo = AmmoID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 1);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            if (type == ProjectileID.Bullet) // or ProjectileID.WoodenArrowFriendly
            {
                type = mod.ProjectileType("The Lazer Shot"); // or ProjectileID.FireArrow;
            }
            return true; // return true to allow tmodloader to call Projectile.NewProjectile as normal
        }

        // What if I wanted this gun to have a 38% chance not to consume ammo?
        /*public override bool ConsumeAmmo(Player player)
        {
            return Main.rand.NextFloat() > .38f;
        }*/

        // What if I wanted it to work like Uzi, replacing regular bullets with High Velocity Bullets?
        // Uzi/Molten Fury style: Replace normal Bullets with Highvelocity
        /*public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            if (type == ProjectileID.Bullet) // or ProjectileID.WoodenArrowFriendly
            {
                type = ProjectileID.BulletHighVelocity; // or ProjectileID.FireArrow;
            }
            return true; // return true to allow tmodloader to call Projectile.NewProjectile as normal
        }*/

        // What if I wanted it to shoot like a shotgun?
        // Shotgun style: Multiple Projectiles, Random spread
        /*public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            int numberProjectiles = 4 + Main.rand.Next(2); // 4 or 5 shots
            for (int i = 0; i < numberProjectiles; i++)
            {
                Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(30)); // 30 degree spread.
                Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
            }
            return false; // return false because we don't want tmodloader to shoot projectile
        }*/

        // What if I wanted an inaccurate gun? (Chain Gun)
        // Inaccurate Gun style: Single Projectile, Random spread
        /*public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(30));
            speedX = perturbedSpeed.X;
            speedY = perturbedSpeed.Y;
            return true;
        }*/

        // What if I wanted multiple projectiles in a even spread? (Vampire Knives)
        // Even Arc style: Multiple Projectile, Even Spread
        /*public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            float numberProjectiles = 3 + Main.rand.Next(3); // 3, 4, or 5 shots
            float rotation = MathHelper.ToRadians(45);
            position += Vector2.Normalize(new Vector2(speedX, speedY)) * 45f;
            for (int i = 0; i < numberProjectiles; i++)
            {
                Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .2f; // Watch out for dividing by 0 if there is only 1 projectile.
                Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
            }
            return false;
        }*/

        // Help, my gun isn't being held at the handle! Adjust these 2 numbers until it looks right.
        /*public override Vector2? HoldoutOffset()
        {
            return new Vector2(10, 0);
        }*/
    }
}
 
Ok this is the 3rd time I've had to ask this because I really just want to play with tmod. Can someone help me please, when i first installed 0.9.0.1 it said an error when i tried loading it from the download so someone told me to load it from the steam library, so i did but it loaded up vanilla, so i tried loading from the download again and that opened vanilla aswell. How can i get tmod to work???
 
Ok this is the 3rd time I've had to ask this because I really just want to play with tmod. Can someone help me please, when i first installed 0.9.0.1 it said an error when i tried loading it from the download so someone told me to load it from the steam library, so i did but it loaded up vanilla, so i tried loading from the download again and that opened vanilla aswell. How can i get tmod to work???
Look in: C:\Program Files (x86)\Steam\steamapps\common\Terraria
If Terraria.exe looks like the left, you still have Vanilla. Since this is the case, either you installed incorrectly or your antivirus overreacted and reverted the file. Just install again, make sure the tree turns into the one on the right. (The filesize will be be 8XXX KB not 7XXX KB too.) If you successfully replace Terraria.exe, it is literally impossible for vanilla terraria to launch. (If it asks you to overwrite, yes!)
3gyUha0.png
 
when install tmodloader 0.9.0.2 and start terraria, it launches like i didnt even install tomdloader. any suggestions??


Edit: now it works but now mid through loading the mods it crashes with a big scary crash log D:
 
Last edited:
it said this
An error occurred while loading CosmieticVariety This mod has automatically been disabled

Object reference not set to an instance of an object.
at EnemyMods.NPCs.gNPC.SetDefaults(NPC npc) in c:\Users\Kenneth\Documents\my games\Terraria\ModLoader\Mod Sources\EnemyMods\NPCs\gNPC.cs:line 29
at Terraria.ModLoader.NPCLoader.SetupNPC(NPC npc)
at Terraria.NPC.SetDefaults(Int32 Type, Single scaleOverride)
at Terraria.NPC.SetDefaultsKeepPlayerInteraction(Int32 Type)
at Terraria.NPC.CloneDefaults(Int32 Type)
at CosmeticVariety.NPCs.Starzar.SetDefaults() in c:\Users\benma\OneDrive\Documents\My Games\Terraria\ModLoader\Mod Sources\CosmeticVariety\NPCs\Starzar.cs:line 14
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

HELP!
 
For some reason, enemies aren't dropping money. I'm currently using:


Thorium Mod
Calamity Mod
Zoaklen Mod
Reduced Grinding Mod
RPG classes mod
Dushy's Upgrade mod

It's really frustrating how I always have like no money.
 
Every single weapon that Summons an entity on screen doesn't work, like the flare gun, slime staff, and it applies to modded weps too. Can someone plz help(I'm sorry for bothering everyone again
 
when i make a sword, i can change item width and height, but i do not notice any effect of changing it, as hitbox of my sword seem to stay just as big as my sprite size which stay the same size as well. So what are those for?
 
View attachment 152072
hey, sorry for silly questions, still how do i fix ?
See the yellow triangle next to 'Terraria' in references? that means that Visual Studio can't find the file anymore. Remove the reference and add it again. Also, make sure you are referencing tModLoader's .exe not vanilla .exe, if you have a side-by-side installation.

when i make a sword, i can change item width and height, but i do not notice any effect of changing it, as hitbox of my sword seem to stay just as big as my sprite size which stay the same size as well. So what are those for?
I think that width and height change the item's appearance when dropped in the world. I think that item.scale is what you want to change. But I could be wrong.
 
Hi guys, I don't see a bug or feature request thing in the OP and the former programmer in me has been tickled.

In short, when trying to build a mod without the "build.txt" file existing in the mod's source folder, everything *appears* to work properly but it fails miserably. If you use tModReader to extract the result, essentially all the input files are missing. Any chance of adding a simple check for the existence of the "build.txt" file during the build phase?
 
EDIT: Nevermind. I removed and reequiped all my equipment and things seem to have fixed themselves and I can't cause it to happen again. So.. I guess.. move along, nothing to see here.

EDIT 2: Thanks to another member posting about this same issue, it turns out that putting a dye in the head slot is what caused it: https://forums.terraria.org/index.p...der-a-modding-api.23726/page-733#post-1156016

I'm working on getting the TML GOG patches working and I've come across some unusual behavior. Before I make a github issue, I want to see if any of you steam users can reproduce this, because there is every possibility that it could just be an issue on the GOG patching side.

Basically, the Balloon Animal and Bundled Party Balloons vanity accessories display below the character's feet instead of above their head. The left image shows the problem in patched GOG Terraria and the right image from vanilla Terraria shows what it should look like.
View attachment 151690
Steam user here, and I have the exact same problem. I first noticed it with "Bundle of Balloons", and it indeed happens with all others I've tried -- all of them appear just like in your picture, roughly half of it depicted underneath the character. This is the only significant problem I've encountered so far using the latest tMod.



Apologies in case this has since been addressed.
 
Hi guys another question. The answer is likely no but is there a way to directly access player data? Specifically, I'd like to be able to access the player's equipment array and increase the size of array that holds accessories. It seems to be hard coded to 7.
 
When im trying to use ranged type weapon nothing happens. if im facing right every weapon is in daedalus bow position and if im facing left every weapon aims into the ground. They don't shoot anything and don't consume ammo.

Edit1: also my game crashes every 10 mins.
 
Last edited:
Back
Top Bottom