Standalone [1.3] tModLoader - A Modding API

So I figured how to display the chatbox for typing in, however there's no way for me to do anything when the enter key is pressed yet. So I had to improvise.. with tools...


rvIgblv.gif


This really is becoming a mess isn't it? Anyway, you can enable the chatbox with the following line:
Code:
Terraria.Main.chatMode = true;
Not sure how to make it do something when you press enter though, so that's why I made an execute tool to execute the last thing I type in and to open the chatbox in the first place. The Terraria.Main.Update method contains the code that decides when to open the chatbox, so having a hook for that to detect key presses could really help.

You don't actually have to detect when enter is pressed in this case, you can simply check for a change in the chat box.

Code:
if(Main.chatLine[0].text!=lastChatLine)
{
    lastChatLine = Main.chatLine[0].text;
    //do stuff with the command
}
 
I tried using this code to make a blue slime(for now to test) drop an item, but npcType isnt used here? its whats used in the main vanilla npc.cs so what would i use instead? thanks.
Code:
using System;
using Terraria;
using Terraria.ModLoader;

namespace WyvernCore.NPCs 
{
public class WyvernCoreNPC : GlobalNPC
{
    public override void NPCLoot(NPC npc)
    {
        if (npcType == 1)  //wyvern head id is 87
        {
            if (Main.rand.Next(1) == 0)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WyvernScale"));
            }
        }
    }
}
}
 
I tried using this code to make a blue slime(for now to test) drop an item, but npcType isnt used here? its whats used in the main vanilla npc.cs so what would i use instead? thanks.
Code:
using System;
using Terraria;
using Terraria.ModLoader;

namespace WyvernCore.NPCs
{
public class WyvernCoreNPC : GlobalNPC
{
    public override void NPCLoot(NPC npc)
    {
        if (npcType == 1)  //wyvern head id is 87
        {
            if (Main.rand.Next(1) == 0)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("WyvernScale"));
            }
        }
    }
}
}
"npcType" is probably a local variable declared somewhere in the code. Here you need to use "npc.type" instead.
 
@bluemagic123 I kind of asked this earlier but would it be possible to increase the damage of a sword by collecting a certain item (fallen stars in my case)? Or craft them into the sword to deal more damage without actually creating a brand new sword?
 
@bluemagic123 I kind of asked this earlier but would it be possible to increase the damage of a sword by collecting a certain item (fallen stars in my case)? Or craft them into the sword to deal more damage without actually creating a brand new sword?
By collecting items, do you mean keeping them in the inventory or actually picking them up?
 
At the moment it's possible to increase the damage based on how many are in the inventory, but you'd have to have programming experience to do that.
Ok thanks.

Edit: I guess I'll start with something simple like when you kill bosses you get more attack.
 
Last edited:
If I remember correctly, the stack should be an Item field, just like the type.
Is the "type" the item ID? Sorry to ask so many questions... object browser can only tell me so much...

Here's my code, can you tell me what's crashing it? "Index was outside the bounds of the array."
Code:
if(player.HasItem(3))
       {
         for(int i=0; i < player.inventory.GetLength(0); i++)
         {
           for(int j = 0; j < player.inventory.GetLength(1); j++)
           {
             if (player.inventory[i * j].type == 3)
             {
               player.meleeDamage += 0.25f * player.inventory[i * j].stack;
             }
           }
         }
       }
 
Is the "type" the item ID? Sorry to ask so many questions... object browser can only tell me so much...

Here's my code, can you tell me what's crashing it? "Index was outside the bounds of the array."
Code:
if(player.HasItem(3))
       {
         for(int i=0; i < player.inventory.GetLength(0); i++)
         {
           for(int j = 0; j < player.inventory.GetLength(1); j++)
           {
             if (player.inventory[i * j].type == 3)
             {
               player.meleeDamage += 0.25f * player.inventory[i * j].stack;
             }
           }
         }
       }
player.inventory is a 1-dimensional array. So you'd just need a single for loop, which checks player.inventory.Length.
 
@bluemagic123 Ok I actually almost got it to work for the increase damage per item in your inventory but since I'm still new to C# (I used to code in java quite a bit and also the IDE I have helps a lot) I don't actually know how to make it not keep going (one of the things that should be super simple) so I just get infinite damage.

Edit: and here is the code so you can tell me what I need to put in here

Code:
public override void UpdateInventory(Player player)
        {
            if (player.HasItem(75))
            {
                item.damage += 1;
            }
        }
 
@bluemagic123 Ok I actually almost got it to work for the increase damage per item in your inventory but since I'm still new to C# (I used to code in java quite a bit and also the IDE I have helps a lot) I don't actually know how to make it not keep going (one of the things that should be super simple) so I just get infinite damage.
Are you incrementing the damage each turn? Try setting the damage to some constant plus whatever damage you want to add instead.
 
@bluemagic123 Ok I actually almost got it to work for the increase damage per item in your inventory but since I'm still new to C# (I used to code in java quite a bit and also the IDE I have helps a lot) I don't actually know how to make it not keep going (one of the things that should be super simple) so I just get infinite damage.

Edit: and here is the code so you can tell me what I need to put in here

Code:
public override void UpdateInventory(Player player)
        {
            if (player.HasItem(75))
            {
                item.damage += 1;
            }
        }
Replace it with this:
Code:
if(player.HasItem(75))
            {
                for(int i=0; i < player.inventory.GetLength(0); i++)
                {
                    if (player.inventory[i].type == 75)
                        {
                            item.damage += 1 * player.inventory[i].stack;
                        }
                }
            }
the first if statement isn't necessary, but prevents unnecessary code running if the criteria aren't met.

That code makes every item in the first stack (maybe others) of whatever 75 is increase the damage by one. Theoretically, it wouldn't work for multiple stacks and I don't know how to fix that. I need to sleep anyways.
 
Back
Top Bottom