Standalone [1.3] tModLoader - A Modding API

I've noticed a potential bug/problem.
If you don't put an argument after a command, and a command requires an argument, it can crash the game
Fix:
Code:
if (args.Length != 0) {/* your code*/}//set args.Lenght equal to the amount of arguments you want
That isn't a bug; it's up to the programmer to make sure they don't create an index out of bounds exception in their code.
 
My problems always seem to fix themselves when i check crash logs, I looked into the crashlogs, decided to try again, and it started working :D
 
How do I get a projectile to inflict a certain debuff?
Also how do I get an accessory to put dust around the player?
 
Last edited:
How do I get a projectile to inflict a certain debuff?
Also how do I get an accessory to put dust around the player?
Try these out.
ModProjectile:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
target.AddBuff(Terraria.ID.BuffID.OnFire, 60);
}

ModItem:
public override void UpdateAccessory(Player player)
{
Dust.NewDust(player.Center, 0, 0, DustID.Blood, (Main.rand.NextFloat() - .5f) * 10f, (Main.rand.NextFloat() - .5f) * 10f);
// Create unending blood gushing from player body.
}
Note: the UpdateAccessory method only works when in equipment slot, not social slot. We are working on implementing hooks in tModLoader for some social hooks we didn't get around to yet. But for now, have at it.
 
Last edited:
Does anyone know how to make a projectile so it spawns the tile it hit's dust?
 
You can use OnTileCollide in your projectile.
here's the method:
Code:
public override bool OnTileCollide(Vector2 oldVelocity){

}
 
You can use OnTileCollide in your projectile.
here's the method:
Code:
public override bool OnTileCollide(Vector2 oldVelocity){

}
ah, Thank You!
 
I've got a few questions:

1. Is it possible to change the text of a chat with a townNPC while you're still talking with them?
2. Is it possible (again in the chat with a townNPC) to close the chat manually? Instead of having to walk away from the NPC or clicking 'Close'
3. And last one, which method is internally called earlier, the 'GetChat' or the 'SetChatButtons' function?

Ty for taking the time to read (and maybe answer) this.
 
Sounds like a NÖÖB question, but does this support NPCs, both human town stuff and enemies / bosses?

EDIT: Just that u said "I hate town NPCs" in the news section xD
 
I've got a few questions:

1. Is it possible to change the text of a chat with a townNPC while you're still talking with them?
2. Is it possible (again in the chat with a townNPC) to close the chat manually? Instead of having to walk away from the NPC or clicking 'Close'
3. And last one, which method is internally called earlier, the 'GetChat' or the 'SetChatButtons' function?

Ty for taking the time to read (and maybe answer) this.
1. That is possible depending on what you mean by "still talking". You can only change the text chat when a chat button is clicked, by modifying Main.npcChatText to whatever string you want.

2. Like with above, this is only possible with buttons. You'll have to use this code:
Code:
Main.player[Main.myPlayer].talkNPC = -1;
Main.player[Main.myPlayer].sign = -1;
Main.npcChatCornerItem = 0;
Main.editSign = false;
Main.npcChatText = "";

3. First of all, GetChat is only called when you right-click the NPC to talk to it. Then, SetChatButtons is called every single tick the NPC chat window is opened. Not really sure why the source code is like that, but I'm not willing to rewrite how NPC chats are handled :P

Sounds like a NÖÖB question, but does this support NPCs, both human town stuff and enemies / bosses?
The example mod has some examples: a town NPC, enemies, and a boss.
 
1. That is possible depending on what you mean by "still talking". You can only change the text chat when a chat button is clicked, by modifying Main.npcChatText to whatever string you want.

2. Like with above, this is only possible with buttons. You'll have to use this code:
Code:
Main.player[Main.myPlayer].talkNPC = -1;
Main.player[Main.myPlayer].sign = -1;
Main.npcChatCornerItem = 0;
Main.editSign = false;
Main.npcChatText = "";

3. First of all, GetChat is only called when you right-click the NPC to talk to it. Then, SetChatButtons is called every single tick the NPC chat window is opened. Not really sure why the source code is like that, but I'm not willing to rewrite how NPC chats are handled :p


The example mod has some examples: a town NPC, enemies, and a boss.
Tyvm that's all I ever needed!

EDIT: It's working like a frecking charm, awesome!
 
Last edited:
How i can make my npc to only spawn in under world.......
I have been trying everything for the last couple of hours and cannot figure it out :(.

and just if you are wondering what my code looks like, heres the CanSpawnmethod. (btw i can get him spawn everywhere but idk how to make him only to spawn in to the underworld):

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
return 1;
}
Cant figure it out, THX for the awesome modding API

 
Last edited:
How i can make my npc to only spawn in under world.......
I have been trying everything for the last couple of hours and cannot figure it out :(.

and just if you are wondering what my code looks like, heres the CanSpawnmethod. (btw i can get him spawn everywhere but idk how to make him only to spawn in to the underworld):

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
return 1;
}
Cant figure it out, THX for the awesome modding API

You'll need to do something like this:

return spawnInfo.spawnTileY > Main.maxTilesY - 200 ? 1 : 0;

This will return 1 if the NPC is spawning low enough, and 0 if the NPC is not spawning low enough.
 
Allright... I've got just one more question... When talking to a NPC there is a 'Close' button by default. Is there any way to check if that button has been clicked (or even better: a way to remove that button)? Ty in advance.
 
So could this work like tapi and tconfig to download mods people have created and play or is it just a mod creator?
 
its kinda like both
[DOUBLEPOST=1441751689,1441751634][/DOUBLEPOST]this is kinda off topic but how do I register my terraria thing with the terraria forums?
 
like hooking up your terraria copy to terraria forums to become an "Official Terrarian"
 
what do I do then?
 
Back
Top Bottom