Standalone [1.3] tModLoader - A Modding API

Setup has been running for almost 5 hours now. Has something gone wrong and it hasn't crashed yet, or is it just going slowly for me for some reason? (2-3 year old desktop, Windows 7, using at its peak 97% of 8 GB RAM)

---

My purpose with decompiling is only to get a closer look at the code behind tModLoader, because I am attempting to port an earlier one of my mods into the game but I cannot find a method for Buffs that handles NPCs. The Update function only handles players, and from testing by changing the function directly to handle NPCs it cannot find a method.

EDIT: It just froze. I had gone to the wrong folder location to look for 'src,' so when I just tried again, I found that it had all been decompiled within the first 20 minutes that I opened setup. Derp.

Anyway - I see that there is not an Update function for NPCs within Buffs. I added a prototype myself, but when I try to run the solution, it asks me to open it in Steam (since my version is the Steam version.) What can I do about this?

EDIT: I started Steam and now I can run it. Derp. But now, I'm getting an IOError - it can't find Content\Images\TileCracks.xnb...even though I can clearly see it in the folder. What's up?

EDIT: Figured out how to get things up and running.

Re-post:

I am trying to port an item from one of my older projects; a magic item that shoots a projectile that inflicts a buff on NPCs it hits. I am trying to add an Update function to ModBuff that processes the buff effects on NPCs, since it currently only has an Update function to process the buff effects on Players. The Update function I added, however, does not appear to be doing anything. I checked the NPC.cs code and it appears that NPCs do not even process buffs? Need explanation.

FINAL EDIT: I figured out how to add NPC ModBuff handling in 10 give or take a few lines. I am now going to try and figure out how to suggest it on GH... Ask me how to do it and I'll give you the snippets. GH is scary.
 
Last edited:
I just did my scripts! haven't gotten other things in without getting the basics correct though
Code:
using System;
using System.Windows.Input;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Trekko727Mod.Items
{
    public class SASKnife : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "SAS Knife";
            item.damage = 35;
            item.melee = true;
            item.width = 36;
            item.height = 36;
            item.position.Y = 2;
            item.toolTip = "This is a modded sword.";
            item.useTime = 18;
            item.useAnimation = 20;
            item.useStyle = 0;
            item.knockBack = 6;
            item.value = 10000;
            item.channel = true;
            item.rare = 2;
            item.useSound = 1;
            item.autoReuse = false;
            }

        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 void UseStyle(Player player)
        {
                int counter = 0;
                if (counter > 10 && item.channel == true)
                {
                    // position the itemlocation over the head
                    } else if (counter >10 && item.channel == true){
                    // spawn the projectile
                    } else if (item.channel == true){
                    counter++;
                    } else {
                // copy in the code for useStyle of 1 for the swing
                }
        }
    }
}
 
It appears that most of the sprite handling for projectiles is hardcoded. I do not believe there is a way to do this without some serious fiddling.
Lol I just remembered that I had a txt file of all the Ai stlyes 1.2.4.1
All the things in Terraria can be extracted
Im pretty sure I can go through it and find what Im looking for :p
 
It looks very complicated!
What I have tried to do is
1. Download Visual Studio Community
2. Open up example mod
3. Open up C# files in VS
4. Stare at the code and learn what should do what and how it does that.
5. Attempt at writing code for a simple item so that you can begin learning.
On a final note, if you try to do this for awhile you should be able to type C# soon!

Hope this helps;)
 
Hey, I have a question @bluemagic123.
Can you make a projectile "implode", or pull enemies towards it's center, and have it created at the cursor?
I actually just programmed such a spell. It's a bit messy, but it uses 80 mana to create a portal at the cursor that pulls in any NPCs close enough, excluding town NPCs.
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace MyMod.Items.Weapons
{
    public class Abyss : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Abyss";
            item.damage = 20;
            item.magic = true;
            item.mana = 80;
            item.width = 28;
            item.height = 30;
            item.toolTip = "Suck 'em in.";
            item.useTime = 15;
            item.useAnimation = 15;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = -1;
            item.value = 10000;
            item.rare = 7;
            item.useSound = 8;
            item.autoReuse = false;
            item.shoot = mod.ProjectileType("AbyssProjectile");
            item.shootSpeed = 0.0f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient("Spell Tome", 1);
            recipe.AddIngredient("Hallowed Bar", 20);
            recipe.AddIngredient("Soul of Night", 24);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace MyMod.Projectiles
{
    public class AbyssProjectile : ModProjectile
    {
        public Vector2 mpos;
      
        public override void SetDefaults()
        {
            projectile.name = "Abyss Projectile";
            projectile.width = 50;
            projectile.height = 65;
            projectile.alpha = 0;
            projectile.scale = 1.0f;
            projectile.timeLeft = 1000;
            projectile.penetrate = 7;
            projectile.hostile = false;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.tileCollide = false;
            projectile.ignoreWater = true;
            mpos = new Vector2(-1f, -1f);
        }
  
        public override void AI()
        {
          
            if (mpos.X == -1f && mpos.Y == -1f) {
                projectile.position = mpos = Main.MouseWorld - new Vector2(projectile.width/2, projectile.height/2);
            }

            for (int i = 0; i < 201; i++) {
                if (!Main.npc[i].boss && !Main.npc[i].townNPC) {
                    double dist = Math.Sqrt(Math.Pow(projectile.position.X-Main.npc[i].position.X,2)+Math.Pow(projectile.position.Y-Main.npc[i].position.Y,2));
                    if (dist <= 400.0f) {
                        if (Main.npc[i].position.X < projectile.position.X && Main.npc[i].velocity.X < 3.0f) {
                            Main.npc[i].velocity.X += (float)dist/300.0f;
                        } else if (Main.npc[i].position.X > projectile.position.X && Main.npc[i].velocity.X > -3.0f) {
                            Main.npc[i].velocity.X -= (float)dist/300.0f;
                        }
                        if (Main.npc[i].position.Y < projectile.position.Y && Main.npc[i].velocity.Y < 3.0f) {
                            Main.npc[i].velocity.Y += (float)dist/100.0f;
                        } else if (Main.npc[i].position.Y > projectile.position.Y && Main.npc[i].velocity.Y > -3.0f) {
                            Main.npc[i].velocity.Y -= (float)dist/100.0f;
                        }
                    }
                }
            }
        }
      
        public override bool? CanHitNPC(NPC target) {
            if (target.townNPC) {
                return false;
            }
            return true;
        }
    }
}
How do I do .cs coding!!!!!!
I highly suggest just opening up the Example Mod and tooling around with it. If you have no prior experience in programming, then I would suggest starting with a different language, personally.
 
What I have tried to do is
1. Download Visual Studio Community
2. Open up example mod
3. Open up C# files in VS
4. Stare at the code and learn what should do what and how it does that.
5. Attempt at writing code for a simple item so that you can begin learning.
On a final note, if you try to do this for awhile you should be able to type C# soon!

Hope this helps;)
either that or go Khan Academy (its free and online) learn javascript (everything is similar)
 
How do I do .cs coding!!!!!!
I think you should try something more basic than C# coding. Then try and do some basic stuff. If you want to mod, you'll need to know these basic things:

1. Basic classes, namespaces and methods
2. Arrays
3. Variables
4. Using other classes
5. Mind-boggling math (mostly when making advanced AIs)
 
guys? one question
any way to spawn projectile?
Code:
  public override bool PreShoot(Player player,Vector2 ShootPos,Vector2 ShootVelocity,int projType,int Damage,float knockback)
        {
            Projectile.NewProjectile(ShootPos.X,ShootPos.Y,projType,Damage,knockback,Main.myPlayer);
            return false;
        }
EDIT: I know theres a function called
Code:
                    public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
      return base.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack);
}
 
I made a command file that you can double click on mac and as long as you have mono installed it will open the installer. I attached it if you wanna include it in the mac download.

(apparently you can't upload .commands so here is media fire)
https://www.mediafire.com/?wnf201evu1xwbja
Never mind this won't work because you need to set the permission to run this file and i don't know how to automate that.

PS. I don't think Mac version can build mods. Log says its looking for mono files that even though I have mono installed. Cant build example mod or very simple 1 item mods i made to test it.
 
Back
Top Bottom