Standalone [1.3] tModLoader - A Modding API

Also, how would you do this?
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EnergyMod.NPCs {
public class EnemyDrops : GlobalNPC
{
public override void NPCLoot(NPC npc)
{
if(npc.type == 2 && Main.rand.Next(10) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SoaringEnergy"));
}
}
}
}
Here is what I had. I am using this to add drops to existing npc.
 
Is there any way to make it a custom color? Like new Color(233, 203, 24, 0)
You can set item.color to whatever you want.

Okay, so I used the example mod's code as a starter for my NPC. I changed the ai AND animation to Lihzahrd, and then I added in my edited version of the Lihzahrd sprites. However, the enemy that spawns is still really screwed up...

The enemy in its screwed-up state: http://prntscr.com/9q8x67
The code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LihzarhdExpansion.NPCs
{
    public class Chameleon : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Chameleon";
            npc.displayName = "Chameleon";
            npc.width = 18;
            npc.height = 40;
            npc.damage = 14;
            npc.defense = 6;
            npc.lifeMax = 200;
            npc.soundHit = 1;
            npc.soundKilled = 2;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
            npc.aiStyle = 3;
            Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Zombie];
            aiType = NPCID.Lihzahrd;
            animationType = NPCID.Lihzahrd;
        }

        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0.5f : 0f;
        }

        public override void HitEffect(int hitDirection, double damage)
        {
            for (int i = 0; i < 10; i++)
            {
                int dustType = Main.rand.Next(139, 143);
                int dustIndex = Dust.NewDust(npc.position, npc.width, npc.height, dustType);
                Dust dust = Main.dust[dustIndex];
                dust.velocity.X = dust.velocity.X + Main.rand.Next(-50, 51) * 0.01f;
                dust.velocity.Y = dust.velocity.Y + Main.rand.Next(-50, 51) * 0.01f;
                dust.scale *= 1f + Main.rand.Next(-30, 31) * 0.01f;
            }
        }
    }
}

Thanks for any help.
Wait, it has the same animation type as the Lihzahrd, but the same frame count as zombies?
Main.npcFrameCount[type] needs to be set to how many frames your spritesheet has.

Also, how would you do this?
The Sarcophagus in the ExampleMod drops the Nazar with a 1/50 chance as an example.
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.Items.Weapons
{
    public class DarkMatterBow : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Dark Matter Bow";
            item.damage = 65;
            item.ranged = true;
            item.width = 16;
            item.height = 32;
            item.toolTip = "You thought Phantasm was fast? Well this is faster!";
            item.toolTip2 = "All Arrows turn into Dark Matter Arrows.";
            item.useTime = 6;
            item.useAnimation = 6;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 2;
            item.value = 325060;
            item.rare = 7;
            item.useSound = 11;
            item.autoReuse = true;
            item.shootSpeed = 13f;
            item.useAmmo = 1;
        }
public virtual bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int mod.ProjectileType ("DarkMatterArrow"), ref int damage, ref float knockBack)
    }
}
You'll need to use the Shoot hook: https://github.com/bluemagic123/tMo...f-int-type-ref-int-damage-ref-float-knockback
And change the type parameter to what you want.

When I put that into the code of my bow I get this error


c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\Items\Weapons\DarkMatterBow.cs(32,111) : error CS1026: ) expected
 
Hey guys, I need your help.
Is there anyway to force an item to grab no prefix? I can't seem to find a way to do it.
I've tried to use item.prefix = 0; and item.Prefix(0); on the SetDefaults() function but when the item is actually generated it still gets prefixed.
 
Try looking in the logs. Most likely the modders haven't set their .tmod files for tModReader to be allowed to read them.

for one mod it was written that the author didn't allow to read it but for others it look like this
"Unpacking PlasmaMod
Found files Resources, Windows, Other in PlasmaMod"

and that's all, a folder with the mod's name in the Output is just empty. maybe it's because the mod was made for tmodloader 0.6? but mods for 0.7 are also cannot be unpacked.
 
So what is this part of the NPC code? http://prntscr.com/9qcsjp

Is this where it spawns, or where it doesn't, because while it says Main.dayTime, my enemy never spawns during the day, only at night.
Yes, that determines when/where the enemy can spawn. And you see the '!' before Main.dayTime? '!' means basically that you're checking it against false, so it means 'if not Main.dayTime'.
 
Yes, that determines when/where the enemy can spawn. And you see the '!' before Main.dayTime? '!' means basically that you're checking it against false, so it means 'if not Main.dayTime'.
Aha! And removing that exclamation point would make it spawn in the day?

Also, where do I choose spawnrate?
 
Aha! And removing that exclamation point would make it spawn in the day?

Also, where do I choose spawnrate?
Well, as you can see this function returns a floating number. The number you return determines the spawnrate. If you return 0, the NPC will not spawn. You see the 0.5? That's the value that is returned if all checks are true. If you want to change the spawn rate, you'll want to change that number.
 
Well, as you can see this function returns a floating number. The number you return determines the spawnrate. If you return 0, the NPC will not spawn. You see the 0.5? That's the value that is returned if all checks are true. If you want to change the spawn rate, you'll want to change that number.
Okay, I raised the spawnrate to 5.5. I've found a few in the jungle, but not in the forest biome. Does this have something to do with how they are copying the AI of Buggy?
 
Hey @Eldrazi, do you know anyway to block an item from getting any prefixs and from being reforgeable?
Can't seem to find a way to do it.. I've tried to use item.prefix = 0; and item.Prefix(0); on the SetDefaults() function but that only changes the prefix for the item on the recipe.
 
Could you please make a more Mac-friendly version of this? It's kinda annoying to have to do all that stuff and anyway when it asks me to drag my Terraria executable file, I can't do it. My Terraria file is a .app file. This would be greatly appreciated. Thanks
 
Could you please make a more Mac-friendly version of this? It's kinda annoying to have to do all that stuff and anyway when it asks me to drag my Terraria executable file, I can't do it. My Terraria file is a .app file. This would be greatly appreciated. Thanks
.app files on Mac are actually directories. You can right-click it and click 'Explore Directory' (or something like that, I'm not exactly sure what it states, since I don't own a Mac). You can put all necessary files in there.
Other than that, making an installer that works for every new version can be quite a pain. Giving us some files we need to copy-paste is really the best way to go about this (if you were to ask me).
Hey @Eldrazi, do you know anyway to block an item from getting any prefixs and from being reforgeable?
Can't seem to find a way to do it.. I've tried to use item.prefix = 0; and item.Prefix(0); on the SetDefaults() function but that only changes the prefix for the item on the recipe.
I'm not really sure, but I'll try taking a look for ya ;)
 
.app files on Mac are actually directories. You can right-click it and click 'Explore Directory' (or something like that, I'm not exactly sure what it states, since I don't own a Mac). You can put all necessary files in there.
Other than that, making an installer that works for every new version can be quite a pain. Giving us some files we need to copy-paste is really the best way to go about this (if you were to ask me).

I'm not really sure, but I'll try taking a look for ya ;)

Thanks :D. I took a look in the source and it seems that it's either Item.cs NewItem() or Prefix() that's screwing me over. But the items don't seem to have any specific property that defines if they can have prefixes, it's just a bunch of IFs checking if the item has a certain .type.
If it helps, my item is an Endless Pouch just with diferente bullets.
 
Please, i'm crying((( How to delete vanilla craft from the game? With small example...My last question;(
You'll need to know how to program and know the internal structure of Terraria a bit. Let me give you a hint: you'll want to look at Main.recipe.
Thanks :D. I took a look in the source and it seems that it's either Item.cs NewItem() or Prefix() that's screwing me over. But the items don't seem to have any specific property that defines if they can have prefixes, it's just a bunch of IFs checking if the item has a certain .type.
If it helps, my item is an Endless Pouch just with diferente bullets.
I can't seem to figure it out ATM... It sure has something to do with Item.NewItem...
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.Items.Weapons
{
    public class DarkMatterBow : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Dark Matter Bow";
            item.damage = 65;
            item.ranged = true;
            item.width = 16;
            item.height = 32;
            item.toolTip = "You thought Phantasm was fast? Well this is faster!";
            item.toolTip2 = "All Arrows turn into Dark Matter Arrows.";
            item.useTime = 6;
            item.useAnimation = 6;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 2;
            item.value = 325060;
            item.rare = 7;
            item.useSound = 11;
            item.autoReuse = true;
            item.shootSpeed = 13f;
            item.useAmmo = 1;
        }
public virtual bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int mod.ProjectileType ("DarkMatterArrow"), ref int damage, ref float knockBack)
    }
}


When I put that into the code of my bow I get this error


c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\Items\Weapons\DarkMatterBow.cs(32,111) : error CS1026: ) expected

Umm... I'm no expert in tModLoader, nor have any experience in tModLoader, but you set up and used the hook wrong. If you wanted it to make it shoot, you would need to do it like this...

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)
{
    Projectile.newProjectile(position.X, position.Y, speedX, speedY, mod.ProjectileType("DarkMatterArrow"), damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type DarkMatterArrow using the original stats
    return false; //Makes sure to not fire the original projectile
}
 
You'll need to know how to program and know the internal structure of Terraria a bit. Let me give you a hint: you'll want to look at Main.recipe.

I can't seem to figure it out ATM... It sure has something to do with Item.NewItem...
I'm pretty good know programming, but don't know exactly vanilla things. Also, i know what i need to use Main.recipe
 
Back
Top Bottom