Standalone [1.3] tModLoader - A Modding API

NPCtoBanner gets the banner number from the npc. You still need to NPC.killCount[bannernumber] to ger the kill counts.

how do i turn that into a score i can use

like where or how do i use that code u told me to use
 
NPCtoBanner method returns the banner number and the killCount array is indexed by the banner number, so probably something like this:
Code:
int BlueSlime = NPC.killCount[Item.NPCtoBanner(NPCID.BlueSlime)];
 
Still no projectile shows up

projectile
Code:
 public class SolarisP : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Solarius";
            projectile.width = 68;
            projectile.height = 64;
            projectile.friendly = true;
            projectile.penetrate = -1;
            projectile.aiStyle = 75;
            projectile.type = ProjectileID.Arkhalis;
            Main.projFrames[projectile.type] = 28;
            projectile.ownerHitCheck = true;
            projectile.melee = true;
            projectile.tileCollide = false;
            projectile.light = 2f;
        }

weapon
Code:
 public override void SetDefaults()
        {
            item.name = "Solarius";
            item.damage = 200;
            item.melee = true;
            item.width = 48;
            item.height = 48;
            item.useTime = 15;
            item.useAnimation = 1;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 4f;
            item.noUseGraphic = true;
            item.channel = true;
            item.value = 100000;
            item.rare = 9;
            item.useSound = 1;
            item.autoReuse = false;
            item.shoot = mod.ProjectileType("SolarisP");
            item.shootSpeed = 15f;
        }

where's the fail at?
I'm thinking in the weapon, but... I have no idea

also, remember all my questions about homing and boomerangs? well, now I want a homing boomerang... It's half working. I want it to work like the possessed hatchet, but It doesn't. It tries to home on things through blocks, and homes on on thing and keeps returning till it's dead then goes to another. I want it to only hit 1 thing once then return to the player. also, if I try to shoot it left, for example, and there is a target on the right, it will go right with out going left at all. I want it to curve, not go abruptly.

the code
Code:
public NPC FindNearest(Vector2 pos)
        {

            NPC nearest = null;
            float oldDist = 1001;
            float newDist = 1000;
            for (int i = 0; i < Terraria.Main.npc.Length - 1; i++)
            {
                if (!Collision.CanHit(pos, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
                    continue;
                if (!Terraria.Main.npc[i].CanBeChasedBy(projectile))
                    continue;
                if (nearest == null)
                    nearest = Terraria.Main.npc[i];
                else
                {
                    oldDist = Vector2.Distance(pos, nearest.position);
                    newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position);
                    if (newDist < oldDist)
                        nearest = Terraria.Main.npc[i];
                }
            }
            return nearest;
        }
        int maxSpeed = 16;
        public override void AI()
        {
            NPC nearest = this.FindNearest(projectile.Center);
            Vector2 acceleration;
            if (nearest != null) // extremely important
            {
                acceleration = (nearest.position - projectile.position);
            }
            else
            {
                acceleration = Vector2.Zero; // maintain speed -- or whatever else you want to do here
            }
            projectile.velocity += acceleration * 1.5f;
            projectile.velocity *= 0.95f;
            if (projectile.velocity.Length() > maxSpeed)
            {
                projectile.velocity.Normalize();
                projectile.velocity *= maxSpeed;
            }
        }
        public override void PostAI()
        {
            if (projectile.ai[0] == 1)
            {
                Player myOwner = Main.player[projectile.owner]; //find the owner of this projectile
                Vector2 toMe = Vector2.Normalize(myOwner.Center - projectile.Center); //find the distance from this projectile to it's owner and convert to a unit vector.
                projectile.velocity += toMe * 1f; //add the above vector to this projectile's velocity -- change 1f to change the return speed
            }

        }

also, can anyone help me with the boss ai?



pls help me
H'ok... The Solarius item wasn't working because item.useAnimation was 1. I don't know how small it can be, but vanilla uses 25 there. Also, in the projectile, you've got 'projectile.type = ProjectileID.Arkhalis;' which will make the item a cosmetic clone of Arkhalis. If you want to use your own sprite, you'll need 'aiType = ProjectileID.Arkhalis;' instead.

Now, if you want to delay the projectile from homing in on enemies, then create an int to use as a timer, then place your homing code inside an if statement that checks if your int is above a specific value, and if it isn't, increase the timer. To adjust how quickly your projectile accelerates, change the 1.5f in the line 'projectile.velocity += acceleration * 1.5f;'

To make the projectile return to the player when it hits something, set 'projectile.ai[0]' to 1. The hooks onHitNPC, onHitPVP and onTileCollide are where you'll want to do this.
 
could they add a feature where u click like a button and it truns off tmodloader but if uc lick it again it truns back to tmodloader?
 
I have the GOG version and when i try to install it i do all like it said in the instructions!But when i try to launch the game it says Terraria.exe is not a valid win32 application!
HELP!?
 
How to allow Mod Loader to use more RAM? I am getting OutOfMemory error in the big worlds with some mods.
 
i have quite much no idea how to make a mod so i edited examplemod, and i want to add the effects from "adamantite armor" and "ancient cobalt armor" to the mod's armor...how do i do it
 
I've found a lot more sounds that are bugged.
  • All desert creature noises
  • Mana/heart crystal use sounds
  • Bomb explosions
  • Any zombie cries
  • Basically a lot of NPC sounds
Seriously, is there no way to fix this?
There is a workaround available. It is described in the related git issue, here: https://github.com/bluemagic123/tModLoader/issues/28
This issue is known and there is no known underlying cause of it. Use the workaround for now, it's worked fine for me (also an OSX user).
 
Just a little question, but is it possible to increase the usetime/useanimation of items and weapons through Global Item with formulas? I had tried
public override void UpdateInventory(Item item, Player player) with a requirement of a ModPlayer bool and the formula item.useAnimation = (int)(item.useAnimation * .15); but the results weren't in my favor... Setting the useTime and useAnimation to whole numbers worked fine, but unfortunately, that's not my intention.

Any help would be much appreciated!
 
Just a little question, but is it possible to increase the usetime/useanimation of items and weapons through Global Item with formulas? I had tried
public override void UpdateInventory(Item item, Player player) with a requirement of a ModPlayer bool and the formula item.useAnimation = (int)(item.useAnimation * .15); but the results weren't in my favor... Setting the useTime and useAnimation to whole numbers worked fine, but unfortunately, that's not my intention.

Any help would be much appreciated!
They have to be whole numbers. It doesn't make sense to have a fraction of a frame. As for using UpdateInventory to do it, it runs every tick, so eventually it gets to 0 pretty quick. I'm actually not sure the best approach, but maybe in the canuse hook to modify the useTimes. You still need to figure out how to change it temporarily.
 
Hello, I have a small modding question. I'm trying to make a script that will activate an event once per day. Something like this:
Code:
if (Main.time % #ofticksperday = 0)
    { do stuff }

but I'm not sure where I need to put this snippet to have it run continuously, like I want. Where does this need to go?
 
Hello, I have a small modding question. I'm trying to make a script that will activate an event once per day. Something like this:
Code:
if (Main.time % #ofticksperday = 0)
    { do stuff }

but I'm not sure where I need to put this snippet to have it run continuously, like I want. Where does this need to go?
Probably ModWorld.PostUpdate is best for this type of thing.
 
Probably ModWorld.PostUpdate is best for this type of thing.

Thanks, I'll try that. Follow up: in a previous reply, you talked about looping through chests at world gen and adding items. (Basically, I'm trying to do this once per day for certain chests). http://forums.terraria.org/index.php?threads/1-3-tmodloader-a-modding-api.23726/page-372#post-921068 Some of the replies expressed concern at using a fixed number for the upper bound of chestindex. Do you know what the actual ramifications are for attempting to access more chests than exist in the world are? And is there a better way to find the number of chests in the world? Thanks again for your help.
 
Hi you peepz, can you at least tell me the code for a new drill or pick please. I cannot code with json files:sigh:
 
Why can I not get on public servers when this is installed?
 
Hi you peepz, can you at least tell me the code for a new drill or pick please. I cannot code with json files:sigh:

You should look at the ExamplePick in the ExampleMod, it has everything you need to make a pickaxe. Just make a copy of that file and change whatever you want. (Note that item.pick is the pickaxe power) You can also use item.CloneDefaults to copy the properties of an existing item, then you only need to change the properties that will be different. For example:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace NameofYourMod.Items
{
    public class NameOfYourPickaxeOrDrill : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.SomeVanillaPickOrDrill);
            item.name = "My Pickaxe";
            item.damage = 10;
            item.useTime = 5;
            item.useAnimation = 5;
            item.pick = 100;
            item.knockBack = 6;
            item.value = 10000;
            item.rare = 2;
        }
    }
}
 
Why can I not get on public servers when this is installed?
Because several network messages have changed to facilitate mods, and we don't want people joining vanilla servers and wrecking havoc. Just run the vanilla exe. The installer should have saved a copy for you
[doublepost=1467403290,1467403136][/doublepost]
Thanks, I'll try that. Follow up: in a previous reply, you talked about looping through chests at world gen and adding items. (Basically, I'm trying to do this once per day for certain chests). http://forums.terraria.org/index.php?threads/1-3-tmodloader-a-modding-api.23726/page-372#post-921068 Some of the replies expressed concern at using a fixed number for the upper bound of chestindex. Do you know what the actual ramifications are for attempting to access more chests than exist in the world are? And is there a better way to find the number of chests in the world? Thanks again for your help.
This is the vanilla approach. I'm checking for null, so it doesn't matter. This same pattern is used for projectiles and NPC operations. I see no reason for the code to fail.
 
It won't work. :(

The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.

I use the GOG version of Terraria if it helps.
 
This is the vanilla approach. I'm checking for null, so it doesn't matter. This same pattern is used for projectiles and NPC operations. I see no reason for the code to fail.

Alright, thanks again!
 
Last edited:
how do i get my normal terraria.
 
Back
Top Bottom