Standalone [1.3] tModLoader - A Modding API

Yes! You can :) I've done this myself. What I'd do is make a consumable item, and add the following to the method when the item is consumed.

First, of all. dayTime yes/no?
Code:
dayTime     bool     Returns true if it's daytime, false if it's nighttime. (Terraria v. 1.1.2)
Now, when exactly is it daytime or nighttime? Well..
Code:
time     double  

Used in conjuction with Main.dayTime to determine time of day. (Terraria v. 1.1.2)

If Main.dayTime == true, Main.time goes from 0.0 (dawn) to 54000.0 (nightfall) and resets.

If Main.dayTime == false, Main.time goes from 0.0 (nightfall) to 32400.0 (dawn) and resets. 16200.0 (midnight) is in the middle.

So for example, you could do:
Code:
Main.dayTime = false;
Main.time = 16200.0;

This should set the world's time at midnight.
Taken from: http://tconfig.wikia.com/wiki/Main_Class

Thanks @Gorateron :D
And if its no problem im confused on what i should put in a npc.cs (npc name)
Could you help :)
 
At the moment I have it so that if a world contains absolutely no modded thing, there is no difference in world file format. So worlds that contain nothing modded actually can be ported back to vanilla. So far it's been my goal to keep it this way.

If a world or player contains a modded item, then instead of writing an ID, it writes the maximum possible integer, the mod name, the item name, and any custom data the mod maker wants to write (I don't remember the exact order but it's on the Github). If a world contains a modded tile or wall, then it writes a bunch of 255s, then writes tables mapping modded tile and wall IDs to their mod name and internal name.
Call me optimistic, but would it be possible to store the mod data in a separate file next to the world file? IE, there'd be a WorldName.wld (essentially a vanilla world) and a WorldName.modwld that contained the mod data. This way, someone could copy the .wld file to the vanilla directory for whatever reason. Later on, they could copy the world back to where it used to be and resume playing with tModLoader. The biggest issue that I could see here would be validating mod data back into a world that would have changed since it was last played in tModLoader.

Is this plausible, or just wishful thinking on my part?
 
1. Maybe I'm stupid but how to make armor set emit particles as a setbonus?

2. Anyway of making explosion when a weapons damages enemy?

3. How to make a gun use one ammo and shoot another projectile? For example: item.shoot = 286 and item.useAmmo = 14 - It shoots basic musket bullets but it needs to shoot explosive bullets.
 
Last edited:
Sorry to msg again @bluemagic123 could you in the future add support for multiplayer
Yes, I will add that in the future.

Call me optimistic, but would it be possible to store the mod data in a separate file next to the world file? IE, there'd be a WorldName.wld (essentially a vanilla world) and a WorldName.modwld that contained the mod data. This way, someone could copy the .wld file to the vanilla directory for whatever reason. Later on, they could copy the world back to where it used to be and resume playing with tModLoader. The biggest issue that I could see here would be validating mod data back into a world that would have changed since it was last played in tModLoader.

Is this plausible, or just wishful thinking on my part?
Huh, you know what, that's actually a good idea. That would definitely be possible, and also make it so that I don't need to make as many changes to the source code.

1. Maybe I'm stupid but how to make armor set emit particles as a setbonus?

2. Anyway of making explosion when a weapons damages enemy?

3. How to make a gun use one ammo and shoot another projectile? For example: item.shoot = 286 and item.useAmmo = 14 - It shoots basic musket bullets but it needs to shoot explosive bullets.
1. You can just create the dust in the ArmorSet hook. Although, I might have to add something extra for when they're in the vanity slots.
2. To make an explosion, you increase the projectile's size while keeping its center in the same place and set its timeLeft field to a low number.
3. If I had to guess, I would try setting the item's shoot field to what you want to shoot. If that doesn't work, then you can override the Shoot hook.

Is there support for ammo items like Endless Musket Pouch or items that automatically store ammo as you pick it up?
You can make items similar to the Endless Musket Pouch by not setting the item's consumable field to true.
For items that automatically store ammo, first I'll have to add an OnPickup hook for items, then you'll need to store, save, and load custom data for your item. Then you'll need to set consumable to true, and on the ConsumeAmmo hook decrement the custom data and return false.
 
For some reason when I am using these codes:

public override void SaveCustomData(BinaryWriter writer)

public override void LoadCustomData(BinaryReader reader)

I get these compile errors among building my mod:

error CS0246: The type or namespace name 'BinaryWriter' could not be found (are you missing a using directive or an assembly reference?)

error CS0246: The type or namespace name 'BinaryReader' could not be found (are you missing a using directive or an assembly reference?)


Is there something I need to add to the code or...?


 
Hi @bluemagic123 , may'be I am stupid, but question is question.
1. How to make ranged weapon use one bullet, but shooting a few?
2. How I can create effect for armor like the Molten armor?
 
Yes, I will add that in the future.


Huh, you know what, that's actually a good idea. That would definitely be possible, and also make it so that I don't need to make as many changes to the source code.


1. You can just create the dust in the ArmorSet hook. Although, I might have to add something extra for when they're in the vanity slots.
2. To make an explosion, you increase the projectile's size while keeping its center in the same place and set its timeLeft field to a low number.
3. If I had to guess, I would try setting the item's shoot field to what you want to shoot. If that doesn't work, then you can override the Shoot hook.


You can make items similar to the Endless Musket Pouch by not setting the item's consumable field to true.
For items that automatically store ammo, first I'll have to add an OnPickup hook for items, then you'll need to store, save, and load custom data for your item. Then you'll need to set consumable to true, and on the ConsumeAmmo hook decrement the custom data and return false.


Oh ok. thanks, ill wait until that's added if it is to add that item
 
For some reason when I am using these codes:

public override void SaveCustomData(BinaryWriter writer)

public override void LoadCustomData(BinaryReader reader)

I get these compile errors among building my mod:

error CS0246: The type or namespace name 'BinaryWriter' could not be found (are you missing a using directive or an assembly reference?)

error CS0246: The type or namespace name 'BinaryReader' could not be found (are you missing a using directive or an assembly reference?)


Is there something I need to add to the code or...?
You need to add "using System.IO;" to the top.

Hi @bluemagic123 , may'be I am stupid, but question is question.
1. How to make ranged weapon use one bullet, but shooting a few?
2. How I can create effect for armor like the Molten armor?
1. You'll need to override the Shoot hook then call Projectile.NewProjectile multiple times.
2. https://github.com/bluemagic123/tMo...-bool-isarmorsetitem-head-item-body-item-legs
https://github.com/bluemagic123/tMo...blic-virtual-void-updatearmorsetplayer-player
You'll need to look through the source code for how player.meleeDamage is used.
 
I know this sounds stupid but...
How do I use C#?
I didnt know much (or really any) about that to begin with, but I find it easier to download the example mod and (with notepad++ or similar) reverse engineer the codes until you can make a completely new [insert item name here]!
[DOUBLEPOST=1439162525,1439162416][/DOUBLEPOST]Judging by recent comments, I take it that the new update allows for us to make projectiles? If so, could I get a basic copy of a code of one to see how it works?
 
I didnt know much (or really any) about that to begin with, but I find it easier to download the example mod and (with notepad++ or similar) reverse engineer the codes until you can make a completely new [insert item name here]!
[DOUBLEPOST=1439162525,1439162416][/DOUBLEPOST]Judging by recent comments, I take it that the new update allows for us to make projectiles? If so, could I get a basic copy of a code of one to see how it works?
It theoretically allows you to make projectiles, but since I haven't tested them it seems like they don't actually work yet.
 
This is a truly interesting project. I am at a crossroad as to what I am going to do with my mod now....

I feel that, if tAPI is not going to be updated to 1.3, then I might as well try to use this, but I feel as if the monumental task of porting everything over will kill me.

I have already been considering throwing in the towel with Terraria modding, but maybe I will make a whole new mod... Crossover Reborn seems to fit!

Ugh, lets go learn C#... I seem to be getting the hang of it.

@bluemagic123 what do you think i should do? :)
 
This is a truly interesting project. I am at a crossroad as to what I am going to do with my mod now....

I feel that, if tAPI is not going to be updated to 1.3, then I might as well try to use this, but I feel as if the monumental task of porting everything over will kill me.

I have already been considering throwing in the towel with Terraria modding, but maybe I will make a whole new mod... Crossover Reborn seems to fit!

Ugh, lets go learn C#... I seem to be getting the hang of it.

@bluemagic123 what do you think i should do? :)
You should do what you want to do. Converting the json parts to cs shouldn't be too hard (it's essentially just a different syntax), although converting a large amount of stuff can be tedious. In the end, it will depend on how much effort you're willing to put in and how rewarding you expect success will feel.
 
I'm not sure what you are planning for projectiles, but the number one thing I'd want is the ability to have them run their own custom AI loop instead of being forced to use one that already exists in Terraria. I've been able to "fake it" pretty well so far though by reassigning the aiStyle of another projectile. Hooks for hitting an NPC and hitting a tile would also be nice if that's workable.
 
Back
Top Bottom