tModLoader I need help with custom sounds

RailgunZx

Terrarian
I have a custom sound that I plan to eventually use with a custom projectile but right now I can't even figure out how to get the sound to play when assigned to a sword swing.

Here is the code for my sound:
Code:
using Microsoft.Xna.Framework.Audio;
using Terraria.ModLoader;
using Terraria;


namespace hyperfrostw.Sounds.Item
{
    class masterswordbeamsound : ModSound
    {
        public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType Type)
        {
           
            soundInstance = sound.CreateInstance();
            soundInstance.Volume = volume * .5f;
            soundInstance.Pan = pan;
            soundInstance.Pitch = -1.0f;
            return soundInstance;
        }
    }
}

And here is the code used in the sword item:
Code:
item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/masterswordbeamsound");

Can someone tell me why the sound doesn't play?

Thanks
 
well today i had a problem with custom sounds too and i must say that can be cause of line
soundInstance.Volume = volume * .5f;
i found when you change volume in game sometimes it makes sound dissapear when you have this value higher or lower than 1
try changing it to 1f and it should work
 
well today i had a problem with custom sounds too and i must say that can be cause of line

i found when you change volume in game sometimes it makes sound dissapear when you have this value higher or lower than 1
try changing it to 1f and it should work
Didn't work. I even tried removing the
Code:
volume *
and it still didn't work.
 
Didn't work. I even tried removing the
Code:
volume *
and it still didn't work.
for me your code works good so maybe this is problem with audio file.Try another one just to see if it works if yes then it can be problem with bitrate that can be fixed if you use Audacity or some site to convert file to something like 320kb/s. That helped me so maybe it will help you too.
 
for me your code works good so maybe this is problem with audio file.Try another one just to see if it works if yes then it can be problem with bitrate that can be fixed if you use Audacity or some site to convert file to something like 320kb/s. That helped me so maybe it will help you too.
I CAN'T BELIEVE IT! This whole time it was because the bitrate was too high. I guess this is what I get for trying to get perfect audio quality, lol. Thanks for your help. I can now continue with my mod lol
 
for me your code works good so maybe this is problem with audio file.Try another one just to see if it works if yes then it can be problem with bitrate that can be fixed if you use Audacity or some site to convert file to something like 320kb/s. That helped me so maybe it will help you too.

Ok so I was able to get the sound working normally but now I can't seem to figure out how to make it play on my custom projectile. This is the code I have for the projectile:
Code:
using Terraria.ModLoader;
using Terraria.ID;
using Terraria;

namespace hyperfrostw.Projectiles
{
    class masterswordbeam : ModProjectile
    {

        public override void SetDefaults()
        {
            projectile.name = "Sword Beam";
            projectile.width = 36; //MAKE SURE THIS IS ACCURATE
            projectile.height = 36; //^^^^^
            projectile.timeLeft = 240; //customize this
            projectile.penetrate = 3;
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.tileCollide = true;
            projectile.ignoreWater = true;

            // projectile.aiStyle = 0; //find out if I need this. 27 is enchanted beam
           
        }

        public virtual void PlaySound()
        {
           Main.PlaySound(SoundLoader.customSoundType, projectile.position, mod.GetSoundSlot(SoundType.Item, "Sounds/Item/masterswordbeamsound"));
           
        }

        /*public override void AI()
        {
            projectile.type = 173;
          
        }*/


         public override bool Autoload(ref string name, ref string texture)
         {
             texture = "Terraria/Projectile_" + ProjectileID.EnchantedBeam;

             return true;
         }



    }
}
 
Back
Top Bottom