• Journey's End on PC - Find info here and here. Please report bugs and issues for PC 1.4 and 1.4.1 to Re-Logic here.
  • Journey's End on Mobile - Find info here. Report bugs for Mobile 1.4 to DR Studios at this link and give as much detail as possible.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Console and Switch - The latest news can be found here. To report a bug, please use this link.

Standalone [1.3] tModLoader - A Modding API

dinidini4000

Skeletron Prime
K, I assumed you wanted an npc that kept multiplying itself when hit.

Here is what you can add to ExampleSword.cs
Code:
        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.OnFire, 60);
            //NPC.NewNPC((int)target.Center.X, (int)target.Center.Y, mod.NPCType("ModNPCNameHere"));
            NPC.NewNPC((int)target.Center.X, (int)target.Center.Y, NPCID.LostGirl);
        }


this looks good

side note how do u add those soundless videos
 

jopojelly

Retinazer
tModLoader
this looks good

side note how do u add those soundless videos
ShareX: https://getsharex.com/
and
GfyCat: http://gfycat.com/

Basically, I have shareX set up so that when I press Shift-Printscreen, I drag a rectangle for the capture region, Move around in Terraria, click the stop button when done, and a few seconds later the url is automatically copied to my clipboard. I then post it using the Media button that is right next to the Image button, you can just paste the gfycat url there.

More Info: Make sure ShareX has ffmpeg installed (task settings, Capture/Screen Recorder, screen recording options, download), make sure gfycat is chosen as the file upload destination. Gfycat has a 15 second limit, but it is natively supported by the forums, so i use it.
 

wch

Terrarian
My browser seems to be out of order recently. I really had a hard time getting in the forum.
Anyways, I get some questions about tiles.
So I'm trying to make some craftable altars, some sorta Man-made Demon Altars.
Code:
        public override void SetDefaults()
        {
            item.name = "Man-made Demon Altar";
            item.width = 12;
            item.height = 12;
            item.maxStack = 999;
            item.useTurn = true;
            item.autoReuse = true;
            item.useAnimation = 15;
            item.useTime = 10;
            item.useStyle = 1;
            item.consumable = true;
            item.createTile = mod.TileType("ManmadeDemonAltarTile");
        }
And its texture like(which I've cut from the vanilla texture):
ManmadeDemonAltarTile.png

Then, ofc., I put it in the game, and it appears to be some error blocks... I guess the game probably doesn't regard this as an altar, but a normal tile block, just like the dirt block. I checked the examplemod and found there are actually some extra settings about these special tiles, which I think they're telling the game that these are sprites. Maybe I should add some of those "Main" stuff to define this.
But, well, I don't know how should I set up for this altar, so it would look like what it should look like just like the vanilla altar, when I place it. This is just a crafting station which can craft same items as the true altars, but doesn't need to be exactly the same as the true altar. It can be removed, and can't be smashed by hammers. So I made this altar, anyway.
 

Eldrazi

Eater of Worlds
My browser seems to be out of order recently. I really had a hard time getting in the forum.
Anyways, I get some questions about tiles.
So I'm trying to make some craftable altars, some sorta Man-made Demon Altars.
Code:
        public override void SetDefaults()
        {
            item.name = "Man-made Demon Altar";
            item.width = 12;
            item.height = 12;
            item.maxStack = 999;
            item.useTurn = true;
            item.autoReuse = true;
            item.useAnimation = 15;
            item.useTime = 10;
            item.useStyle = 1;
            item.consumable = true;
            item.createTile = mod.TileType("ManmadeDemonAltarTile");
        }
And its texture like(which I've cut from the vanilla texture):
View attachment 89442
Then, ofc., I put it in the game, and it appears to be some error blocks... I guess the game probably doesn't regard this as an altar, but a normal tile block, just like the dirt block. I checked the examplemod and found there are actually some extra settings about these special tiles, which I think they're telling the game that these are sprites. Maybe I should add some of those "Main" stuff to define this.
But, well, I don't know how should I set up for this altar, so it would look like what it should look like just like the vanilla altar, when I place it. This is just a crafting station which can craft same items as the true altars, but doesn't need to be exactly the same as the true altar. It can be removed, and can't be smashed by hammers. So I made this altar, anyway.
Do you already have your ModTile code? If so, could you show us?
I could tell you how you'd go about creating it right away, but would rather see how you went about it in the first place ;)
 

Yxng Hxpe

Official Terrarian
C:\Program Files (x86)\Steam\steamapps\common\Terraria

then use the terraria_v1.3.0.8 or what els its called

try that
[DOUBLEPOST=1450665137,1450665070][/DOUBLEPOST]so its possible to give a effect on hit enemy

and possible to spawn item on hit enemy

but is it possible to spawn a enemy on hit enemy?
it can harm my computer
 

Eldrazi

Eater of Worlds
it can harm my computer
What exactly will harm your computer?
The file called Terraria_v1.3.0.8 is just the vanilla executable. Renaming some files will not really harm your computer (unless you change the file type of course, which I do not recommend). If you did something wrong in the process, you can always check the file integrity from the game in question to get the 'correct' files back. Can't go wrong any way.
 

wch

Terrarian
Do you already have your ModTile code? If so, could you show us?
I could tell you how you'd go about creating it right away, but would rather see how you went about it in the first place ;)
Oh! I forgot to post my Tile codes, here you are:
Code:
    public class ManmadeDemonAltarTile : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            drop = mod.ItemType("ManmadeDemonAltarItem");
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }
 

Eldrazi

Eater of Worlds
Oh! I forgot to post my Tile codes, here you are:
Code:
    public class ManmadeDemonAltarTile : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            drop = mod.ItemType("ManmadeDemonAltarItem");
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }
Haha, that's no probs, I can work with this! ;)
So, I'll try to explain first and then show it in-code (note that I'm doing this from the top of my head, so bear with me :p):
First off, let's take a look at your sprite. We can tell right away that the tile consists of 3 parts horizontally and 2 parts vertically. Another important thing to note: if you look at your vertical parts, you can see that the top part is 16 pixels in height, whilst the bottom one is 18 pixels. Now all these things considered, we can look at the following code:
Code:
public override void SetDefaults()
{
    Main.tileFrameImportant[Type] = true;
    Main.tileSolid[Type] = false; // You'll probably want to be able to walk through the object, since that's possible with all altars.
    Main.tileNoAttach[Type] = true; // We do not want this tile to attach to anything.
    
    TileObjectData.newTile.Width = 3; // A width of 3 'pieces'.
    TileObjectData.newTile.Height = 2; // A height of 2 'pieces'.
    TileObjectData.newTile.Origin = new Point16(0, 0); // The origin of the tile. You might want to change the Y value of this Point16, since most tiles are placed from the bottom left corner in Terraria (which would make it (0, 1) probably).
    TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0); // Make sure that we need to place this altar on solid tiles, based on the width (which is 3, as set before).
    TileObjectData.newTile.UsesCustomCanPlace = true; // Yeah, we use a custom Can Place.
    TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; // Allright, so here we get to the point where the topper piece is 16 pixels in height and the bottom piece is 18 pixels.
                                                                                                               // You start with the top most tile when assigning these values, so make sure you work from top to bottom.
    TileObjectData.newTile.CoordinateWidth = 16; // Each of the tile 'pieces' is 16 pixels in width.
    TileObjectData.newTile.CoordinatePadding = 2; // And a padding of 2 pixels.
    TileObjectData.addTile(Type); // And make sure you finish it off, so that this data is actually used.

    // We do not need to set the 'drop', since when using tiles that conist of multiple pieces, you'll want to override the KillMultiTile function.
}

public override void KillMultiTile(int i, int j, int frameX, int frameY)
{
    // The first parameters are the X and then the Y coordinate of this tile in 'world space'.
    // Then the width and the height of the tile in pixels and then the ID of the tile we want to drop.
    Item.NewItem(i * 16, j * 16, 48, 32, mod.ItemType("ManmadeDemonAltarItem"));
}
I hope that this helps you a bit (there is an easier way to do this, but this way you might understand the principles a bit better :p).
Again, this is from the top of my head, so if anything is not working as it should, let me know!
 

wch

Terrarian
Haha, that's no probs, I can work with this! ;)
So, I'll try to explain first and then show it in-code (note that I'm doing this from the top of my head, so bear with me :p):
First off, let's take a look at your sprite. We can tell right away that the tile consists of 3 parts horizontally and 2 parts vertically. Another important thing to note: if you look at your vertical parts, you can see that the top part is 16 pixels in height, whilst the bottom one is 18 pixels. Now all these things considered, we can look at the following code:
Code:
public override void SetDefaults()
{
    Main.tileFrameImportant[Type] = true;
    Main.tileSolid[Type] = false; // You'll probably want to be able to walk through the object, since that's possible with all altars.
    Main.tileNoAttach[Type] = true; // We do not want this tile to attach to anything.
   
    TileObjectData.newTile.Width = 3; // A width of 3 'pieces'.
    TileObjectData.newTile.Height = 2; // A height of 2 'pieces'.
    TileObjectData.newTile.Origin = new Point16(0, 0); // The origin of the tile. You might want to change the Y value of this Point16, since most tiles are placed from the bottom left corner in Terraria (which would make it (0, 1) probably).
    TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0); // Make sure that we need to place this altar on solid tiles, based on the width (which is 3, as set before).
    TileObjectData.newTile.UsesCustomCanPlace = true; // Yeah, we use a custom Can Place.
    TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; // Allright, so here we get to the point where the topper piece is 16 pixels in height and the bottom piece is 18 pixels.
                                                                                                               // You start with the top most tile when assigning these values, so make sure you work from top to bottom.
    TileObjectData.newTile.CoordinateWidth = 16; // Each of the tile 'pieces' is 16 pixels in width.
    TileObjectData.newTile.CoordinatePadding = 2; // And a padding of 2 pixels.
    TileObjectData.addTile(Type); // And make sure you finish it off, so that this data is actually used.

    // We do not need to set the 'drop', since when using tiles that conist of multiple pieces, you'll want to override the KillMultiTile function.
}

public override void KillMultiTile(int i, int j, int frameX, int frameY)
{
    // The first parameters are the X and then the Y coordinate of this tile in 'world space'.
    // Then the width and the height of the tile in pixels and then the ID of the tile we want to drop.
    Item.NewItem(i * 16, j * 16, 48, 32, mod.ItemType("ManmadeDemonAltarItem"));
}
I hope that this helps you a bit (there is an easier way to do this, but this way you might understand the principles a bit better :p).
Again, this is from the top of my head, so if anything is not working as it should, let me know!
Thanks for so many detailed codes and explainations. So I duplicated them into my tile, and there seems to be a little problem.
The compiler told me that it can't find Point16 and AnchorData. Original words may be "can't find class or namespace", don't know whetherI translate it right or not, just stuff like that. You may check this out.
 

Eldrazi

Eater of Worlds
Thanks for so many detailed codes and explainations. So I duplicated them into my tile, and there seems to be a little problem.
The compiler told me that it can't find Point16 and AnchorData. Original words may be "can't find class or namespace", don't know whetherI translate it right or not, just stuff like that. You may check this out.
Ah yeah, I can see why.
You will need to include the following code at the top of your file:
Code:
using Terraria.Enums;
using Terraria.ObjectData;
using Terraria.DataStructures;
Quite a lot of namespace usings there! :p
 

wch

Terrarian
Ah yeah, I can see why.
You will need to include the following code at the top of your file:
Code:
using Terraria.Enums;
using Terraria.ObjectData;
using Terraria.DataStructures;
Quite a lot of namespace usings there! :p
Yeah, it's compiled. However, it seems my demon altars have become more and more and overwhelming me - when I smash one, I got seven of them... Something wrong?
 

Eldrazi

Eater of Worlds
Yeah, it's compiled. However, it seems my demon altars have become more and more and overwhelming me - when I smash one, I got seven of them... Something wrong?
Have you removes the 'drop = mod.ItemType("ManmadeDemonAltarItem");' line from your SetDefaults function?
 

wch

Terrarian
Have you removes the 'drop = mod.ItemType("ManmadeDemonAltarItem");' line from your SetDefaults function?
Hey, yeah, em... like you said, it works like a charm.
And well, I may ask this question I've asked several times... why would you always know so many expressions! I actually want to learn about them, but I don't where to find them.
Like those "item.damage" "item.scale" before, I don't know where should I look for them, let alone there would be even more complicated codes now, like those extraUpdate or those Main stuff... stuff, like "Main.npc.displayName"... just, where can I learn about all of this?:sigh:I'm not prone to ask these simplistic codes over and over, since they may be unneccessary, and will take your time.
 

Eldrazi

Eater of Worlds
Hey, yeah, em... like you said, it works like a charm.
And well, I may ask this question I've asked several times... why would you always know so many expressions! I actually want to learn about them, but I don't where to find them.
Like those "item.damage" "item.scale" before, I don't know where should I look for them, let alone there would be even more complicated codes now, like those extraUpdate or those Main stuff... stuff, like "Main.npc.displayName"... just, where can I learn about all of this?:sigh:I'm not prone to ask these simplistic codes over and over, since they may be unneccessary, and will take your time.
Well, I'm just fiddling around with a lot of this code. When I don't understand how something works, I usually look into the source code to see what they use the variable/function in question for (although this might require a broader programming knowledge, not really sure ;)).
Another thing I do (when I'm not really sure what something does) is just change the values around to see what the effect in-game is. Believe me when I tell you it's a lot of trial and error (and by a lot, I mean a LOT). Also, keep asking questions when you're unable to figure something out or can't find info on the subject. Asking questions really helped me to get started with modding Terraria ;)

And last thing: if I didn't had the time to answer your questions I wouldn't, so don't worry 'bout that. More than glad to help.
 

raptor722

Terrarian
If you mean hit instantly, make your weapon shoot very slowly (like maybe a shootSpeed of 1 or 2), then give the projectile a number of extraUpdates equal to speed*X pixels of distance you want your laser to reach. In the projectile's preAI or postAI, make it create dusts, so it will not look completely invisible.
Can you post here how the preAI or postAI looks like the projectile it fine but i dont see it as you said
 

blushiemagic

Retinazer
tModLoader
@bluemagic123 maybe it would be a good idea to add a FAQ sections to the front page to answer some of the questions that people keep asking (like the 'null' problem)
The problem is, people won't actually read it. I mean, making an error message pop up for loading the mod telling what exactly is going wrong didn't even help.

I know for certain that some people don't even read the installation instructions, or a file called README.
 

Eldrazi

Eater of Worlds
@bluemagic123 maybe it would be a good idea to add a FAQ sections to the front page to answer some of the questions that people keep asking (like the 'null' problem)
The problem is, people won't actually read it. I mean, making an error message pop up for loading the mod telling what exactly is going wrong didn't even help.
I agree with @bluemagic123 ... A lot of the answers (to a lot of those questions) can be found on the wiki, which is a good read if you want to mod with tModLoader.
There has probably gone a lot of time in the making of the wiki, so I'd suggest that everyone reads the whole thing, because it answered a LOT of my questions before I even asked them ;)
 
Top Bottom