Standalone [1.3] tModLoader - A Modding API

Edit:. Nevermind, I found out that GlobalNPC is what I were looking for, since I wanted to change the propperties of all monsters...
I asked this question a while back and the simple answer is that there is no easy way to change the price of items just for a single shop.
Actually, there is one, I used to make a variable to check if the player have the shop opened, if the player opened a shop and the variable is not equal to the shop id, the shop item prices were changed by script.
It's suggested that either only the main player have that checking, or the main mod itself, or there will be a great sale if players are visitting the same shop on multiplayer.
 
Last edited:
Actually, there is one, I used to make a variable to check if the player have the shop opened, if the player opened a shop and the variable is not equal to the shop id, the shop item prices were changed by script.
It's suggested that either only the main player have that checking, or the main mod itself, or there will be a great sale if players are visitting the same shop on multiplayer.

That is an interesting idea, similar to one I had thought of, but much better. Still, I wouldn't call that an easy way as it requires more than just setting some API exposed values. If the member asking the question has the knowledge necessary to implement this, then I would say it is the best option that I've come across. :guidesmile:
 
Ok I Am having an problem with Tmodloader, Anytime I Install tmodloader to terraria i get this weird thing where the game freezes then resumes and it keeps doing this without tmod terraria runs with no problems, any way to fix this?
 
Really small, way smaller than Thorium, Tremor, Calamity, or any of your mods.

Edit: Well, maybe not yours, yours are quite small.

Edit to Edit: Well, I've never seen inside yours, but, mine takes like five seconds to load, so it's pretty small.

Edit to Edit to Edit: Actually, probably about two seconds.

Another Edit: If it was to big, how would I put it on the Terraria Forums then, I've tried creating a homepage, but I don't know how. I know these are so many questions, and probably have obvious answers, but if you could get back to me eventually, that would be great!
I mean the filesize, just go to the folder and look at it.

So... Someone know how I can get the npc mod refference?
I'm trying the npc's "GetModInfo<>" and it is asking for NPCInfo instead of the NPC class I've made.
If you want the ModNPC object:https://github.com/bluemagic123/tModLoader/wiki/Mod#public-modnpc-getnpcstring-name
If you want a ModNPC of an existing in game world npc, npc.modNPC

Ok I Am having an problem with Tmodloader, Anytime I Install tmodloader to terraria i get this weird thing where the game freezes then resumes and it keeps doing this without tmod terraria runs with no problems, any way to fix this?
That sounds odd, OS?
 
If you want the ModNPC object:https://github.com/bluemagic123/tModLoader/wiki/Mod#public-modnpc-getnpcstring-name
If you want a ModNPC of an existing in game world npc, npc.modNPC
Actually, I've found what I were doing wrong.
I were looking for GlobalNPC instead, since I wanted to change the scripts for all npcs, not ModNPC, which seems to mess
with only a npc.
Only after checking the wiki documentation I found out about the GlobalNPC.

Now I have two working mods :guidegrin:
 
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!
 
Back
Top Bottom