tModLoader Official tModLoader Help Thread

how do i use a float reference on the useTime on an item for an example

item.useTime = .4f; //or 0.4f, 0.4, .4, etc.
 
how do i use a float reference on the useTime on an item for an example

item.useTime = .4f; //or 0.4f, 0.4, .4, etc.
item.useTime is an integer, and is the number of frames/ticks between uses. You can't use something every half tick because half ticks don't exist, and the same applies to any other fraction of a tick.
 
I have the following problem with the Calamity Mod:

I've made a potion that completely prevents enemies from spawning... Except for the Dungeon Guardian. The Dungeon Guardian always spawns at least once - the buff only prevents additional Guardians from spawning. I don't know whether it's possible to prevent the Dungeon Guardian from spawning at all.
 
I've been trying to make a debuff that happens while the boss is active "like the wall of flesh" but every place i've looked i can't find any info on that exact code and it's all i need. can someone post JUST that code? or point me in the right direction?
 
When I got to Build & Reload I get the error "Make sure to have exactly one class extending mod". I know I'm being very vague so if you need more info tell me but I keep getting this error for some reason and I don't know why so I don't know how to fix it .
I think you should show your code.
 
I could use some help making a pet that can attack, but is not a minion. I know that it should be possible cause I've seen other mods that do this, but I haven't found an example and have no experience with pets myself.

I tried making my pet projectile shoot another projectile to give it a damage value, but not only does nothing happen, it also makes the pet glitch out and fall through the floor. Here's my code:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace WayfaringMerchant.Projectiles
{
   public class PDCube : ModProjectile
   {
       public override void SetStaticDefaults()
       {
           DisplayName.SetDefault("TX06 Personal Defense Cube Prototype");
           Main.projFrames[projectile.type] = 1;
           Main.projPet[projectile.type] = true;
       }

       public override void SetDefaults()
       {
           projectile.CloneDefaults(ProjectileID.CompanionCube);
           projectile.width = 34;
            projectile.height = 34;
           aiType = 26;
           projectile.tileCollide = true;
       }

       public override bool PreAI()
       {
           Player player = Main.player[projectile.owner];
           //player.turtle = false; // Relic from aiType
           return true;
       }

       public override void AI()
       {
           Player player = Main.player[projectile.owner];
           WMPlayer modPlayer = player.GetModPlayer<WMPlayer>();
           if (player.dead)
           {
               modPlayer.ComradeCube = false;
           }
           if (modPlayer.ComradeCube)
           {
               projectile.timeLeft = 2;
           }
           
           for (int i = 0; i < 200; i++)
            {
                NPC target = Main.npc[i];

                //Getting the shooting trajectory
                float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
                float shootToY = target.position.Y + (float)target.height * 0.5f - projectile.Center.Y;
                float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));

                //If the distance between the projectile and the live target is active
                if (distance < 400f && !target.friendly && target.active)  //distance < 520 this is the projectile1 distance from the target if the tarhet is in that range the this projectile1 will shot the projectile2
                {
                    if (projectile.ai[0] > 10f)//this make so the projectile1 shoot a projectile every 2 seconds(60 = 1 second so 120 = 2 seconds)
                    {
                        //Dividing the factor of 2f which is the desired velocity by distance
                        distance = 1.6f / distance;

                        //Multiplying the shoot trajectory with distance times a multiplier if you so choose to
                        shootToX *= distance * 3;
                        shootToY *= distance * 3;
                        int damage = 30;  //this is the projectile2 damage                 
                                          //Shoot projectile and set ai back to 0
                        Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, 88, damage, 0, Main.myPlayer, 0f, 0f); //Spawning a projectile mod.ProjectileType("FlamethrowerProj") is an example of how to spawn a modded projectile. if you want to shot a terraria prjectile add instead ProjectileID.Nameofterrariaprojectile
                        Main.PlaySound(SoundID.Item12, projectile.position);
                        projectile.ai[0] = 0f;
                       i = 0;
                    }
                }
            }
            projectile.ai[0] += 1f;
       }
   }
}
I used that method for a sentry before, but it doesn't seem to work here. Any ideas?
 
Is there a way to edit mods before tmodloader loads them? Because I need to edit them but it tells me an error and closes my game in the middle of loading my mods
Launch tModLoader, click in the Terraria/tModLoader window when it opens, and then hold (left?) Shift as the Re-Logic splash screen disappears. tModLoader will then not load mods, allowing you to go into the mod list to disable problematic mods before reloading the mods.
 
I could use some help making a pet that can attack, but is not a minion. I know that it should be possible cause I've seen other mods that do this, but I haven't found an example and have no experience with pets myself.

I tried making my pet projectile shoot another projectile to give it a damage value, but not only does nothing happen, it also makes the pet glitch out and fall through the floor. Here's my code:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace WayfaringMerchant.Projectiles
{
   public class PDCube : ModProjectile
   {
       public override void SetStaticDefaults()
       {
           DisplayName.SetDefault("TX06 Personal Defense Cube Prototype");
           Main.projFrames[projectile.type] = 1;
           Main.projPet[projectile.type] = true;
       }

       public override void SetDefaults()
       {
           projectile.CloneDefaults(ProjectileID.CompanionCube);
           projectile.width = 34;
            projectile.height = 34;
           aiType = 26;
           projectile.tileCollide = true;
       }

       public override bool PreAI()
       {
           Player player = Main.player[projectile.owner];
           //player.turtle = false; // Relic from aiType
           return true;
       }

       public override void AI()
       {
           Player player = Main.player[projectile.owner];
           WMPlayer modPlayer = player.GetModPlayer<WMPlayer>();
           if (player.dead)
           {
               modPlayer.ComradeCube = false;
           }
           if (modPlayer.ComradeCube)
           {
               projectile.timeLeft = 2;
           }
          
           for (int i = 0; i < 200; i++)
            {
                NPC target = Main.npc[i];

                //Getting the shooting trajectory
                float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
                float shootToY = target.position.Y + (float)target.height * 0.5f - projectile.Center.Y;
                float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));

                //If the distance between the projectile and the live target is active
                if (distance < 400f && !target.friendly && target.active)  //distance < 520 this is the projectile1 distance from the target if the tarhet is in that range the this projectile1 will shot the projectile2
                {
                    if (projectile.ai[0] > 10f)//this make so the projectile1 shoot a projectile every 2 seconds(60 = 1 second so 120 = 2 seconds)
                    {
                        //Dividing the factor of 2f which is the desired velocity by distance
                        distance = 1.6f / distance;

                        //Multiplying the shoot trajectory with distance times a multiplier if you so choose to
                        shootToX *= distance * 3;
                        shootToY *= distance * 3;
                        int damage = 30;  //this is the projectile2 damage                
                                          //Shoot projectile and set ai back to 0
                        Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, 88, damage, 0, Main.myPlayer, 0f, 0f); //Spawning a projectile mod.ProjectileType("FlamethrowerProj") is an example of how to spawn a modded projectile. if you want to shot a terraria prjectile add instead ProjectileID.Nameofterrariaprojectile
                        Main.PlaySound(SoundID.Item12, projectile.position);
                        projectile.ai[0] = 0f;
                       i = 0;
                    }
                }
            }
            projectile.ai[0] += 1f;
       }
   }
}
I used that method for a sentry before, but it doesn't seem to work here. Any ideas?

Maybe try replacing projectile.ai[0] with a different global variable, because the aiType the projectile uses might use projectile.ai[0] for controlling movement
 
Does anybody know how to make a custom grass draw properly, with tile merging and stuff? I would like it to draw like it does in vanilla:
Capture 2019-07-19 20_56_46.png

But it draws like this instead:
Capture 2019-07-19 20_55_42.png

I've looked at the source, and can't find anything, or at least anything that works. I attempted to override PreDraw to draw it manually, but there must be a much more consise way of doing it. If you can help that'd be great :)
 

Attachments

  • WitheredGrass.cs
    13.3 KB · Views: 166
  • WitheredGrass.png
    WitheredGrass.png
    20.9 KB · Views: 116
Maybe try replacing projectile.ai[0] with a different global variable, because the aiType the projectile uses might use projectile.ai[0] for controlling movement
Doesn't seem to work either, no matter what I try, either the minion doesn't shoot anything or falls through the floor at some point. Screw minions.
But thanks for trying to help.

Edit:
Got it to work somehow after all, the only problem is that the pet only fires if the player is airborne `:confused:
 
Last edited:
I need some help finding out how to disable mods without opening Terraria.

I pilled on too many mods, there isn't enough memory for me to load the game up, but the mods aren't disabling after the game crashes.

This leads into a loop where the game restarts and then tries to load up all of the mods, leading it into a crash again.

I tried completely wiping my local files (I use steam) and repairing to base game, then reinstalling Tmodloader, but it also reinstalled all of the game crashing mods.

I've been searching through the tmodloader files for about an hour now, but in essence I'm either at a loss or I'm afraid to touch anything.

Anyone have any advice?
 
I need some help finding out how to disable mods without opening Terraria.

I pilled on too many mods, there isn't enough memory for me to load the game up, but the mods aren't disabling after the game crashes.

This leads into a loop where the game restarts and then tries to load up all of the mods, leading it into a crash again.

I tried completely wiping my local files (I use steam) and repairing to base game, then reinstalling Tmodloader, but it also reinstalled all of the game crashing mods.

I've been searching through the tmodloader files for about an hour now, but in essence I'm either at a loss or I'm afraid to touch anything.

Anyone have any advice?
Go to Documents\My Games\Terraria\ModLoader\Mods and delete enabled.json.
 
Does anybody know how to make a custom grass draw properly, with tile merging and stuff? I would like it to draw like it does in vanilla: View attachment 224379
But it draws like this instead:
View attachment 224380
I've looked at the source, and can't find anything, or at least anything that works. I attempted to override PreDraw to draw it manually, but there must be a much more consise way of doing it. If you can help that'd be great :)


If you can't figure out how to merge grasses, why not create multiple textures and draw them so they connect between different blocks?
[doublepost=1563745758,1563745659][/doublepost]
Go to Documents\My Games\Terraria\ModLoader\Mods and delete enabled.json.

AH-HA! I WAS looking in the wrong place.

Thank you. I appreciate it alot. :D
 
Um, i tried installing the latest version of tmodloader (0.11.2.2) in terraria, but when i try launching it, Steam shows that it's in initialisation for a second, then closes and Terraria dosen't launch. I made sure to delete teraria entierly and reinstalling it before putting it in, and i made sure that i took the same version as my system type (linux). Is there something i might have done wrong ? Also, your automatic installer dosen't work in said version.
 
Um, i tried installing the latest version of tmodloader (0.11.2.2) in terraria, but when i try launching it, Steam shows that it's in initialisation for a second, then closes and Terraria dosen't launch. I made sure to delete teraria entierly and reinstalling it before putting it in, and i made sure that i took the same version as my system type (linux). Is there something i might have done wrong ? Also, your automatic installer dosen't work in said version.
There's a new release. 0.11.3 now, try that one. Also the installer may not work super well on linux, unfortunately. Manually install it, and use the kickstart script. You may have to grant file permissions (chmod +x) on the terraria file and server file.
 
How do I save world events? I want a thing to be fishable only once, but it only works for the current session.
Code:
else if (player.ZoneBeach && liquidType == 0 && Main.rand.Next(5) == 0 && !WMWorld.fishedHat)
               {
                   caughtType = mod.ItemType("MerchantHat");
                   WMWorld.fishedHat = true;
               }
And here's my world file:
Code:
public class WMWorld : ModWorld
   {
       public static bool gaveHat;
       public static bool fishedHat;
       
       public override void Initialize()
           {
               gaveHat = false;
               fishedHat = false;
           }
           
       public override TagCompound Save()
        {
            return new TagCompound
            {
                {"gaveHat", gaveHat},
               {"fishedHat", fishedHat},
            };
        }
       
       public override void Load(TagCompound tag)
        {
            gaveHat = tag.GetBool("gaveHat");
           gaveHat = tag.GetBool("fishedHat");
        }
       
       public override void NetSend(BinaryWriter writer)
        {
            BitsByte flags = new BitsByte();
            flags[0] = gaveHat;
           flags[1] = fishedHat;
        }
       
       public override void NetReceive(BinaryReader reader)
        {
            BitsByte flags = reader.ReadByte();
            gaveHat = flags[0];
           fishedHat = flags[1];
       }
   }
(I fully admit that I don't really understand the structure of the world file, I modeled it after the example mod's)
 
So, how can I check if an item is a mod item, and get an unique id or something for it? I need that because I'm trying to save and load item infos, but If I add a new item to the mod or possibly change the mods loaded, the item may end up being a completelly different item the next time I load the game.
 
Back
Top Bottom