Standalone [1.3] tModLoader - A Modding API

A "Help me please, coders!" post.
Having issues with making a weapon that was working fine earlier, the problem is this is differ to coding mods in tAPI, so I do not get how to do this. In tAPI there was a .json where all the weapon stats went, and then a .cs for special things like particles, character modifications, etc. Here you only use .cs (I think) so this is different for meh. I know how to make the weapon work, but not how to add particles like the fiery greatsword, my issue. Also, anyone know how to make the sword turn with your mouse or character movement? Mine only fires in the direction you were facing when you clicked.
Ok, so I have the code set to the correct path (Sup.Items) for namespace, and then public class has Greatsword (name of my cs file and image), and it says file not found error is expected when I try to compile. I have the exact same code for the other weapon in terms of location only with a different name, and it works. Help?
Code:
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Sup.Items
{
    public class Greatsword : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Ghastly Flames Sword";
            item.damage = 215;
            item.melee = true;
            item.width = 66;
            item.height = 66;
            item.toolTip = "A ghastly sword crafted from the flames of vulcan's forge.";
            item.useTime = 32;
            item.useAnimation = 32;
            item.useStyle = 1;
            item.knockBack = 19;
            item.value = 10000;
            item.rare = 2;
            item.useSound = 1;
            item.autoReuse = true;
        }
        public override void UseItemEffects(Player p, Rectangle rect)
        {
            for (int i = 0; i < 3; i++)
            {
                int dust = Dust.NewDust(rect, 6, p.velocity.X, p.velocity.Y, 1, Color.White, 1f);
            }
        }
    }
}
Removed for reasons.|Sup\Items\Greatsword.cs(37,78) : error CS1022: Type or namespace definition, or end-of-file expected
1.I wonder if I am just annoying people with my coding problems?
2.Uhhhg, coding, why do you hate me so much! I have never done anything to you! :(
 
Last edited:
A "Help me please, coders!" post.
Having issues with making a weapon that was working fine earlier, the problem is this is differ to coding mods in tAPI, so I do not get how to do this. In tAPI there was a .json where all the weapon stats went, and then a .cs for special things like particles, character modifications, etc. Here you only use .cs (I think) so this is different for meh. I know how to make the weapon work, but not how to add particles like the fiery greatsword, my issue. Also, anyone know how to make the sword turn with your mouse or character movement? Mine only fires in the direction you were facing when you clicked.
Ok, so I have the code set to the correct path (Sup.Items) for namespace, and then public class has Greatsword (name of my cs file and image), and it says file not found error is expected when I try to compile. I have the exact same code for the other weapon in terms of location only with a different name, and it works. Help?
Code:
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Sup.Items
{
    public class Greatsword : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Ghastly Flames Sword";
            item.damage = 215;
            item.melee = true;
            item.width = 66;
            item.height = 66;
            item.toolTip = "A ghastly sword crafted from the flames of vulcan's forge.";
            item.useTime = 32;
            item.useAnimation = 32;
            item.useStyle = 1;
            item.knockBack = 19;
            item.value = 10000;
            item.rare = 2;
            item.useSound = 1;
            item.autoReuse = true;
        }
        public override void UseItemEffects(Player p, Rectangle rect)
        {
            for (int i = 0; i < 3; i++)
            {
                int dust = Dust.NewDust(rect, 6, p.velocity.X, p.velocity.Y, 1, Color.White, 1f);
            }
        }
    }
}
Removed for reasons.|Sup\Items\Greatsword.cs(37,78) : error CS1022: Type or namespace definition, or end-of-file expected
1.I wonder if I am just annoying people with my coding problems?
2.Uhhhg, coding, why do you hate me so much! I have never done anything to you! :(
There is no UseItemEffects hook. Check the documentation, you'll want to replace it with MeleeEffects. Also, you'll need to "using Terraria".
 
Anyone know how to make the particle effect that happens when a wooden arrow hits the ground? I'm making a similar projectile to a wooden arrow.
 
Also, there's no point in having both DurabilitySave and durability
Yeah, finally. Much gratitude. Delete the DurabilitySave and it still works like a charm. Brilliant. I would like to ask about the possibility to reserve prefixes while it is thrown damage... Don't want it to be melee, since I'm making a whole new class.

Move onto the next question about music... I'm in the mood for changing the vanilla bgm. Pasting your codes and they work just fine. But all the mod musics I input sound too loudly compared to vanilla ones. I simulated how Example mod specify the settings of music but it doesn't work in my case.
This is what I write in my mod.cs
Code:
music = this.GetSoundSlot(SoundType.Music, "Sounds/Music/Hell2");
And this is the additional Hell2.cs
Code:
using Microsoft.Xna.Framework.Audio;
using Terraria;
using Terraria.ModLoader;

namespace wch.Sounds.Music
{
    public class Hell2 : ModSound
    {
        public override void PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type)
        {
            soundInstance.Volume = volume * 0.5f;
        }
    }
}
 
Yeah, finally. Much gratitude. Delete the DurabilitySave and it still works like a charm. Brilliant. I would like to ask about the possibility to reserve prefixes while it is thrown damage... Don't want it to be melee, since I'm making a whole new class.

Move onto the next question about music... I'm in the mood for changing the vanilla bgm. Pasting your codes and they work just fine. But all the mod musics I input sound too loudly compared to vanilla ones. I simulated how Example mod specify the settings of music but it doesn't work in my case.
This is what I write in my mod.cs
Code:
music = this.GetSoundSlot(SoundType.Music, "Sounds/Music/Hell2");
And this is the additional Hell2.cs
Code:
using Microsoft.Xna.Framework.Audio;
using Terraria;
using Terraria.ModLoader;

namespace wch.Sounds.Music
{
    public class Hell2 : ModSound
    {
        public override void PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type)
        {
            soundInstance.Volume = volume * 0.5f;
        }
    }
}
You probably aren't autoloading sounds
 
if u use canequipaccessory in either globalitem or moditem and block the use of a certain accessory while another accessory is equipped you cannot equip it normally or via right click but can still right click it from the social slot into the accessory slot even when it should not be possible cause the other accessory is still equipped. is that a bug?
 
You probably aren't autoloading sounds
Code:
        public wch()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
You mean this? I did it. Remember last time I have trouble adding my ak47 sounds? You told me to do this back then...

EDIT: BTW, the indication of the durability works fine except its being under the item. What parameter should I change so it can be always on the item?
 
Last edited:
Code:
        public wch()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
You mean this? I did it. Remember last time I have trouble adding my ak47 sounds? You told me to do this back then...

EDIT: BTW, the indication of the durability works fine except its being under the item. What parameter should I change so it can be always on the item?
Oh, you'll want to follow all the instructions: https://github.com/bluemagic123/tModLoader/wiki/ModSound

Code:
            soundInstance = sound.CreateInstance();
            soundInstance.Volume = volume * .5f;
            Main.PlaySoundInstance(soundInstance);


To be above the item, draw the numbers in postDrawInInventory.
 
soundInstance = sound.CreateInstance(); soundInstance.Volume = volume * .5f; Main.PlaySoundInstance(soundInstance);
The music is so loud even if I followed this and changed the volume to .1f... No idea why... Seems it doesn't work?
 
Hmm, put some errorlogger.log statements in there, so you know if the code is even being called
Code:
        public override void PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type)
        {
            ErrorLogger.Log("haahah");
            Main.NewText(Main.time.ToString(), 50, 255, 130, false);
            soundInstance = sound.CreateInstance();
            soundInstance.Volume = volume * 0.1f;
            Main.PlaySoundInstance(soundInstance);
        }
You're right, it's not even called. No logs or in-game messages have been received. How should I deal with this?:sigh:
 
Code:
        public override void PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type)
        {
            ErrorLogger.Log("haahah");
            Main.NewText(Main.time.ToString(), 50, 255, 130, false);
            soundInstance = sound.CreateInstance();
            soundInstance.Volume = volume * 0.1f;
            Main.PlaySoundInstance(soundInstance);
        }
You're right, it's not even called. No logs or in-game messages have been received. How should I deal with this?:sigh:
I'd check the file paths....or maybe I should check the tmodloader code and make sure it's set up correctly for doing music....
 
How to prevent generation of Crimson/Corruption/Hallow stripes after beating WoF?

I think I found it. But I can't override StartHardmode(). I can't figure out what uses it. Help?
 
Last edited:
K, wait for your voice!
K, looks like it's not possible. You'll want to lower the levels in some other audio editing program.

How to prevent generation of Crimson/Corruption/Hallow stripes after beating WoF?

I think I found it. But I can't override StartHardmode(). I can't figure out what uses it. Help?
There is currently no hook for that, so it's not possible.
[doublepost=1461477788,1461477724][/doublepost]
if u use canequipaccessory in either globalitem or moditem and block the use of a certain accessory while another accessory is equipped you cannot equip it normally or via right click but can still right click it from the social slot into the accessory slot even when it should not be possible cause the other accessory is still equipped. is that a bug?
Maybe, if you send me a zip of a project I can confirm the bug and do a fix.
 
K, looks like it's not possible. You'll want to lower the levels in some other audio editing program.
See. Actually that's what I'm tryna do. Thx anyways.

And I got puzzled by another issue. It's about the attack speed of the melee weapons. It seems a melee weapon's attack interval has nothing to do with the use time? I dunno whether my guess is right, but I noticed whatever I changed the use time of a melee weapon, the attack interval doesn't change too much. Although I set a weapon's use time to 50, the dps of it still remains ridiculously high. Maybe the attack interval of a melee weapon does have something to do with the use time. The connection might not be that magnificent like guns and bows... Is there anything here I failed to notice?

EDIT: BTW, I'm tryna use the OnCraft to do something - the resupply item of the throwing knife. It will restore some ammo of the relative throwing knife. But how should I refer to the recipe in Recipe recipe? Like if I wanna refer to the torch recipe, what should I do?
 
Last edited:
See. Actually that's what I'm tryna do. Thx anyways.

And I got puzzled by another issue. It's about the attack speed of the melee weapons. It seems a melee weapon's attack interval has nothing to do with the use time? I dunno whether my guess is right, but I noticed whatever I changed the use time of a melee weapon, the attack interval doesn't change too much. Although I set a weapon's use time to 50, the dps of it still remains ridiculously high. Maybe the attack interval of a melee weapon does have something to do with the use time. The connection might not be that magnificent like guns and bows... Is there anything here I failed to notice?

EDIT: BTW, I'm tryna use the OnCraft to do something - the resupply item of the throwing knife. It will restore some ammo of the relative throwing knife. But how should I refer to the recipe in Recipe recipe? Like if I wanna refer to the torch recipe, what should I do?
I'm not sure what you mean by "attack interval", I don't think there is a field named that. Also, you can just check the vanilla item field spreadsheet and learn from there if you want to. Are you actually talking about how many times it can hit on a single swing?

I'm not sure what you mean. The recipe is passed in, you don't need to "refer to" it at all, it's just there. Maybe you can explain what you mean, which OnCraft method you are using, and what you need to know to do it correctly.
 
Back
Top Bottom