Standalone [1.3] tModLoader - A Modding API

Using modplayer, I am trying to get projectiles to randomly fire at the closest npc to you. What would I use to define the closest npc?
 
Small question! I'd like to use both Tmodloader and vanilla Terraria, so I did a small thing. I had to manually install Tmod copying the content of the folder into my terraria steam folder, and I managed to keep both Tmod "terraria.exe" and vanilla.exe by changing the former's name into Tmod.exe. For now it SEEMS that the system works, with my Steam launching vanilla Terraria when I need to do stuff there, and the tmod.exe launching tmod when I want to play a modded version of the game. My doubt is: Is this a safe thing to do? Will I have problem doing this, or there's the risk of walking into weird save shenanigans?
 
How do you automatically update tModLoader? Or do you just paste the tModLoader files everytime you want to update it?
Yeah, you can either just paste the new tModLoader files or run the installer jar file.

Small question! I'd like to use both Tmodloader and vanilla Terraria, so I did a small thing. I had to manually install Tmod copying the content of the folder into my terraria steam folder, and I managed to keep both Tmod "terraria.exe" and vanilla.exe by changing the former's name into Tmod.exe. For now it SEEMS that the system works, with my Steam launching vanilla Terraria when I need to do stuff there, and the tmod.exe launching tmod when I want to play a modded version of the game. My doubt is: Is this a safe thing to do? Will I have problem doing this, or there's the risk of walking into weird save shenanigans?
That should be a safe thing to do. The save file locations are referenced to in the actual code of the exe, so nothing will go wrong there. I actually did this back in the tAPI days, and the only bad thing that happened was that my hours playing tAPI weren't recorded by Steam.
 
Using modplayer, I am trying to get projectiles to randomly fire at the closest npc to you. What would I use to define the closest npc?
I don't know why you'd want to do that in modPlayer, but I did something similar for a projectile of my own. Essentially what you need to do is iterate through all NPC's in the world, check the distance from each NPC to your desired position and use the shortest one. Here's the function that I used, though you may need to modify it.
Code:
public NPC FindNearest(Vector2 pos)
        {
            //Vector2 wLocation = new Vector2(x, y); //get the location of Whip
            NPC nearest = null;
            float oldDist = 1001;
            float newDist = 1000;
            for (int i = 0; i < Terraria.Main.npc.Length; i++) //Do once for each NPC in the world
            {
                //if (ignoreList.Contains(Terraria.Main.npc[i].whoAmI))
                if (Terraria.Main.npc[i].friendly == true)//Don't target town NPCs
                    continue;
                if (Terraria.Main.npc[i].active == false)//Don't target dead NPCs
                    continue;
                if (Terraria.Main.npc[i].damage == 0)//Don't target non-aggressive NPCs
                    continue;
                if (nearest == null) //if no NPCs have made it past the previous few checks
                    nearest = Terraria.Main.npc[i]; //become the nearest NPC
                else
                {
                    oldDist = Vector2.Distance(pos, nearest.position);//Check the distance to the nearest NPC that's earlier in the loop
                    newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position);//Check the distance to the current NPC in the loop
                    if (newDist < oldDist)//If closer than the previous NPC in the loop
                        nearest = Terraria.Main.npc[i];//Become the nearest NPC
                }
            }
                return nearest; //return the npc that is nearest to the vector 'pos'
        }
All you need to do is give this function the center of your player as a vector (which it is already) and it will return a reference to the NPC that is nearest to you. Be warned: if there are no NPC's in existence, this will return null, so you will need to check for that and skip any code that uses the npc.
 
Haang on, haaaaaang on...
Why would you want to give the vanilla tiles a different ID exactly? ;)
Well, for crafting purposes! For example, I want item A to be accessible only in worlds with Mythril, and item B - in worlds with orichalcum. I don't know why that guy would want to do that, but *I* think it's actually a good way to balance some stuff. Because, you know, second set of HM ores is OP, unlike the first one. So yeah, balance.
 
I don't know why you'd want to do that in modPlayer, but I did something similar for a projectile of my own. Essentially what you need to do is iterate through all NPC's in the world, check the distance from each NPC to your desired position and use the shortest one. Here's the function that I used, though you may need to modify it.
Code:
public NPC FindNearest(Vector2 pos)
        {
            //Vector2 wLocation = new Vector2(x, y); //get the location of Whip
            NPC nearest = null;
            float oldDist = 1001;
            float newDist = 1000;
            for (int i = 0; i < Terraria.Main.npc.Length; i++) //Do once for each NPC in the world
            {
                //if (ignoreList.Contains(Terraria.Main.npc[i].whoAmI))
                if (Terraria.Main.npc[i].friendly == true)//Don't target town NPCs
                    continue;
                if (Terraria.Main.npc[i].active == false)//Don't target dead NPCs
                    continue;
                if (Terraria.Main.npc[i].damage == 0)//Don't target non-aggressive NPCs
                    continue;
                if (nearest == null) //if no NPCs have made it past the previous few checks
                    nearest = Terraria.Main.npc[i]; //become the nearest NPC
                else
                {
                    oldDist = Vector2.Distance(pos, nearest.position);//Check the distance to the nearest NPC that's earlier in the loop
                    newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position);//Check the distance to the current NPC in the loop
                    if (newDist < oldDist)//If closer than the previous NPC in the loop
                        nearest = Terraria.Main.npc[i];//Become the nearest NPC
                }
            }
                return nearest; //return the npc that is nearest to the vector 'pos'
        }
All you need to do is give this function the center of your player as a vector (which it is already) and it will return a reference to the NPC that is nearest to you. Be warned: if there are no NPC's in existence, this will return null, so you will need to check for that and skip any code that uses the npc.
I don't want to spoil your fun, but I'd advice you not to loop through the NPCs using Main.npc.Length. Reason being that the last index of that array is a faulty NPC (when something is not right when spawning/setting the defaults of the NPC). You'll basically want to avoid using the last index of that array, so Main.npc.Lenght - 1 would work (although it's really not that pretty :p ).
Well, for crafting purposes! For example, I want item A to be accessible only in worlds with Mythril, and item B - in worlds with orichalcum. I don't know why that guy would want to do that, but *I* think it's actually a good way to balance some stuff. Because, you know, second set of HM ores is OP, unlike the first one. So yeah, balance.
Hmmm, that's... Allright... Well I guess you'll want to make changes using GlobalTile, then (and possibly make the Orichalcum anvil uncraftable, so you can program it yourself). Hmmmm...
 
Small question! I'd like to use both Tmodloader and vanilla Terraria, so I did a small thing. I had to manually install Tmod copying the content of the folder into my terraria steam folder, and I managed to keep both Tmod "terraria.exe" and vanilla.exe by changing the former's name into Tmod.exe. For now it SEEMS that the system works, with my Steam launching vanilla Terraria when I need to do stuff there, and the tmod.exe launching tmod when I want to play a modded version of the game. My doubt is: Is this a safe thing to do? Will I have problem doing this, or there's the risk of walking into weird save shenanigans?
u do know the vanilla can be run fine from the extra terraria.exe the tmodloader makes on installing so u dont need to do this just install normal and both can be used just the one on steam will be modded and vanilla is in the steam files
 
  • Like
Reactions: OFF
I have some issues with multiplayer. Me and my friend did almost everything know to mankind to make a server. But it either crashes the game and it says connection lost, or it just stays on a screen like: joining server or found server. Can ANYONE type down what i need to do step by step on how to make a multiplayer server for my friend? We really want to play Tremor mod.
 
Uhh, for a while there tModLoader was working amazingly until this happened:

Code:
System.DllNotFoundException: Unable to load DLL 'CSteamworks': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Steamworks.NativeMethods.SteamAPI_RestartAppIfNecessary(AppId_t unOwnAppID)
   at Terraria.Social.Steam.CoreSocialModule.Initialize()
   at Terraria.Social.SocialAPI.Initialize(Nullable`1 mode)
   at Terraria.Program.LaunchGame(String[] args)

Do you know why? I've tried tMod v1.6, 1.7 and 1.7.1.1, and all do the same error. The vanilla .exe works fine though.
 
Uhh, for a while there tModLoader was working amazingly until this happened:

Code:
System.DllNotFoundException: Unable to load DLL 'CSteamworks': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Steamworks.NativeMethods.SteamAPI_RestartAppIfNecessary(AppId_t unOwnAppID)
   at Terraria.Social.Steam.CoreSocialModule.Initialize()
   at Terraria.Social.SocialAPI.Initialize(Nullable`1 mode)
   at Terraria.Program.LaunchGame(String[] args)

Do you know why? I've tried tMod v1.6, 1.7 and 1.7.1.1, and all do the same error. The vanilla .exe works fine though.
I think you missed file CSteamworks.dll in ***/common/Terraria
 
I have some issues with multiplayer. Me and my friend did almost everything know to mankind to make a server. But it either crashes the game and it says connection lost, or it just stays on a screen like: joining server or found server. Can ANYONE type down what i need to do step by step on how to make a multiplayer server for my friend? We really want to play Tremor mod.
 
Is it possible to make an item or accessory that works as a substitute to a crafting material(like wood) but is never consumed?

So if I equip it I don't need wood in crafting at all. Like with Alchemy Station that reduces the amount of crafting items to be used by 33.3% but instead with a 100% reducion of a certain material.
 
Back
Top Bottom