Standalone [1.3] tModLoader - A Modding API

I've spent the last day and a half trying to do this. I've looked at examplemods, tutorials, even the source code itself. I just want to at half health (5000 hp), have my boss change sprites. I know it's something simple or my code has one thing off, so if anyone can, please help me.

Here's the code that i've been using:

//Boss second stage texture
public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
{
if (npc.life <= 5000)
{
spriteBatch.Draw(mod.GetTexture("NPCs/Boss/BigBoy2"), npc.Center, null, Color.Red * (255f / 255f), 0f, new Vector2(100, 100), 3f, SpriteEffects.None, 0f);
}
return true;
}


I should also mention i'm new to this so ;p
Loading textures at runtime like you are doing there is really not a good way to do it. If you are writing your own animation AI, you could just put both variations into the one texture and adjust your AI accordingly. But if you have no control over the animation, you'll need to load it in once when the mods are loaded then access it from there.

In your main mod class, create something like this.
Code:
public static Texture2D[] nameOfTexture;

public override void Load()
{
    nameOfTexture = GetTexture("NPCs/Boss/BigBoy2");
}
Then you can reference it in the PreDraw hook.
Code:
public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
{
    if (npc.life <= 5000)
    {
        spriteBatch.Draw(YourModsName.nameOfTexture, npc.Center - Main.screenPosition, null, Color.Red * (255f / 255f), 0f, new Vector2(100, 100), 3f, SpriteEffects.None, 0f);
        return false; //DON'T draw the normal boss texture
    }
    return true;
}
Of course, replace YourModsName with the class name of your mod and nameOfTexture with whatever you want. Notice that I'm also subtracting Main.screenPosition from npc.Center so that your NPC will actually be drawn on screen, not some crazy coordinates that you'd need a 100800p screen to see.
 
the new update broke: keybinding, clear mod browser credentials button, and that all I have found so far.

I will let you know if I find more things that needs fixing.
 
the new update broke: keybinding, clear mod browser credentials button, and that all I have found so far.
Can you please elaborate? What keybinding? And how is it broken?
For the button, how is it broken? Does it not work when clicked? Does it not display in the right language?
 
Hello i have a problem with the new version:
I have following mods installed:
HelpfulNPCs
OreConversion
OreSeeds
CookieMod
PortableStorage
TheOneLibrary
Avtomatmod
HamstarHelpers
BuildPlanner
SmeltableTools
ServerBrowser
MagicalThings
DiscordRP
IcePlus
BossChecklist
RecipeBrowser
GadgetBox
VeinMiner
BlockarozArmor
FabusMod
MechTransfer
WheresMyItems
TheLuggage
Wireless
WikiSearch
WhatAmmoDoesItShoot
ArmorHairDye
TPUnchained
ShaderLib
TerrariaPlus
telespells
SecretDyes
Project_C
NonResetTimer
MorePotions
MoreChestLoot
MoreAccessories
MoAddon
MaxStackPlus
MagicStorage
Lottery
ItemMagnet
ItemCustomizer
ItemChecklist
DNIWpnUpgr
FKTModSettings
DualWielding
dropyourweapon
Loot
JPANsBagsOfHoldingMod
SolutionsMod
EmojiSupport
CheatSheet

And it crashed on step: "setting up".
There is no log either it just stops responding and i have to close it
 
Can you please elaborate? What keybinding? And how is it broken?
For the button, how is it broken? Does it not work when clicked? Does it not display in the right language?
The keybinding are broken to the point if I try to edit any thing it locks up, which forces me to alt-f4 out of the game. ( I click on edit a key-bind, press any key, the game locks up the mouse, can't click anything, esc key doesn't do anything, so at that point alt-f4 is the only way to get out of the game) The button just crashes the game. In the case of the language it's English as it's all I understand. Sorry for the delayed response. :)

This is my crash-log.

05/07/2018 08:56:55 AM
System.NullReferenceException: Object reference not set to an instance of an object.
at TerrariaOverhaul.Extensions.SetField(Type type, String fieldName, Object val, Object obj, Nullable`1 flags) in C:\Users\Merser\Documents\My Games\Terraria/ModLoader\Mod Sources\TerrariaOverhaul\Extensions.cs:line 1738
at TerrariaOverhaul.MethodSwapping.Interface_ModLoaderMenus(Main main, Int32 selectedMenu, String[] buttonNames, Single[] buttonScales, Int32[] buttonVerticalSpacing, Int32& offY, Int32& spacing, Int32& numButtons, Boolean& backButtonDown)
at Terraria.Main.DrawMenu(GameTime gameTime)
at Terraria.Main.do_Draw(GameTime gameTime)
at Terraria.Main.DoDraw(GameTime gameTime)
at Terraria.Main.Draw(GameTime gameTime)
at Microsoft.Xna.Framework.Game.DrawFrame()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
at Microsoft.Xna.Framework.GameHost.OnIdle()
at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Microsoft.Xna.Framework.WindowsGameHost.Run()
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs)
 
Keybinding now work, Clear mod-browsers credentials still crashes the game though. :(
Your previous post mentions TerrariaOverhaul in the error, which is a hint that the bug is with that not tmodloader. I just verified and yeah, overhaul breaks the clear mod browser credentials button.
 
Hey I was so hyped to use your software and once everthing loaded i got this message and i dont know how to fix it ive unstalled and reaenstalled the software and even terria nad it still wont work plz help
d adsadwa.PNG
 
Hey I was so hyped to use your software and once everthing loaded i got this message and i dont know how to fix it ive unstalled and reaenstalled the software and even terria nad it still wont work plz helpView attachment 200158
looks like you have an old mod. Hold shift, click continue, once you get to the main menu, update all your mods on the mod browser, then reload.
 
is there any good way to decompile the terraria.exe that comes with tmodloader and have the ability to rebuild it without errors?

would like to change lines in the code, THEN use tmodloader with mods.
yes, i own the game, have since it initially came out.
you have no hooks yet for what i like to do. much easier to do it my way than write code for hours

tried to decompile terraria fresh from a steam download, decompile says i need 1.3.5.1 to work.
tried to decompile terraria that came with tmodloader, says require terraria server not in same directory

i am :red: at creating code. can alter lines upon lines as long as it exists.
 
Ugh...i just can't seem to get this Load Failed thing off my game...after this update and other major mods im trying to play with...(Overhaul, Calamity, Spirit, Thorium, Grealm) it happens 95% percent of the time and its unbearably unplayable...i tried deleting some resource mods i dont use and it wont go away...have i updated the tmodloader incorrectly or some mod update is causing this...D:<
 
Holding shift bypasses loading mods. Or, just open \Documents\My Games\Terraria\ModLoader\Mods and delete problem mods.
Thank you so much i fixed it
[doublepost=1525998604,1525998583][/doublepost]
Ugh...i just can't seem to get this Load Failed thing off my game...after this update and other major mods im trying to play with...(Overhaul, Calamity, Spirit, Thorium, Grealm) it happens 95% percent of the time and its unbearably unplayable...i tried deleting some resource mods i dont use and it wont go away...have i updated the tmodloader incorrectly or some mod update is causing this...D:<
m8 just hold shift when the game is loading then delete the mods
 
Back
Top Bottom