Standalone [1.3] tModLoader - A Modding API

I just learnt how to make NPC drops but I want to know how to make a specific NPC drop an item with a specific chance of that item dropping from that NPC, if anyone can help it will be greatly appreciated. Thanks!
 
I just learnt how to make NPC drops but I want to know how to make a specific NPC drop an item with a specific chance of that item dropping from that NPC, if anyone can help it will be greatly appreciated. Thanks!

ExampleGlobalNPC in the examplemod of modloader ^^
For with a custom NPC, this is just mod.NPCType("npc_name") or just with Npcloot of the customnpc. (but, i use never that, strange '.')
 
If you want something to function identical to a bomb, just set its AI Style to 16. Or do you want something specific, like area damage or destroying tiles?
Yeah I'd like to up the area damage a bit
[doublepost=1467543360,1467542961][/doublepost]and how would you apply an ai style to an item, i thought they were only for npcs?
 
Yeah I'd like to up the area damage a bit
[doublepost=1467543360,1467542961][/doublepost]and how would you apply an ai style to an item, i thought they were only for npcs?

Projectiles have AIs too, usually something simple like going in a straight path, but something like the Razorblade Typhoon for instance has a relatively complicated AI.

If all you want to do is up the damage, just make a new ModProjectile, set its AI Style to 16 and the damage to whatever you like. Remember you also need to make an item to create the projectile.

If you get stuck, the Example Mod has some good examples.
 
Projectiles have AIs too, usually something simple like going in a straight path, but something like the Razorblade Typhoon for instance has a relatively complicated AI.

If all you want to do is up the damage, just make a new ModProjectile, set its AI Style to 16 and the damage to whatever you like. Remember you also need to make an item to create the projectile.

If you get stuck, the Example Mod has some good examples.
Ok thanks, I'll try it out
 
So I tried it out and I got it to be used correctly but when the bomb is thrown the it's invisible, you can only see the bomb smoke, and it doesn't explode. I have the png file in both folders and the names all match.
here is the projectile code:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace GintamaMod.Projectiles
{
public class JustAway : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "JustAway";
projectile.width = 29;
projectile.height = 25;
projectile.aiStyle = 16;
projectile.friendly = true;
projectile.penetrate = 5;
projectile.timeLeft = 60;
projectile.thrown = true;
projectile.alpha = 255;
projectile.light = 0.5f;
projectile.extraUpdates = 1;
aiType = ProjectileID.Bomb;
}

public override bool OnTileCollide(Vector2 oldVelocity)
{
projectile.penetrate--;
if (projectile.penetrate <= 0)
{
projectile.Kill();
}
else
{
if (projectile.velocity.X != oldVelocity.X)
{
projectile.velocity.X = -oldVelocity.X;
}
if (projectile.velocity.Y != oldVelocity.Y)
{
projectile.velocity.Y = -oldVelocity.Y;
}
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 10);
}
return false;
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
for (int k = 0; k < projectile.oldPos.Length; k++)
{
Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
}
return true;
}
}
}
 
In the class where is your block just add this line of code in the SetDefults
Code:
adjTiles = new int[] { TileID.Anvils };
you should find both mythril anvil and the forge there.
Thanks.
[doublepost=1467582949,1467582917][/doublepost]How can I make the String of my yoyo longer ???
 
So I tried it out and I got it to be used correctly but when the bomb is thrown the it's invisible, you can only see the bomb smoke, and it doesn't explode. I have the png file in both folders and the names all match.
here is the projectile code:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace GintamaMod.Projectiles
{
public class JustAway : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "JustAway";
projectile.width = 29;
projectile.height = 25;
projectile.aiStyle = 16;
projectile.friendly = true;
projectile.penetrate = 5;
projectile.timeLeft = 60;
projectile.thrown = true;
projectile.alpha = 255;
projectile.light = 0.5f;
projectile.extraUpdates = 1;
aiType = ProjectileID.Bomb;
}

public override bool OnTileCollide(Vector2 oldVelocity)
{
projectile.penetrate--;
if (projectile.penetrate <= 0)
{
projectile.Kill();
}
else
{
if (projectile.velocity.X != oldVelocity.X)
{
projectile.velocity.X = -oldVelocity.X;
}
if (projectile.velocity.Y != oldVelocity.Y)
{
projectile.velocity.Y = -oldVelocity.Y;
}
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 10);
}
return false;
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
for (int k = 0; k < projectile.oldPos.Length; k++)
{
Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
}
return true;
}
}
}

The reason it's invisible is because you set alpha to 255, which makes it fully transparent. Set it to a lower value, or just remove it outright.

As for it not exploding, that's presumably caused by your OnTileCollide killing the projectile. Instead of projectile.Kill();, try projectile.timeLeft = 3;.
 
The reason it's invisible is because you set alpha to 255, which makes it fully transparent. Set it to a lower value, or just remove it outright.

As for it not exploding, that's presumably caused by your OnTileCollide killing the projectile. Instead of projectile.Kill();, try projectile.timeLeft = 3;.
So I can see them now but now the explosion is invisible and if the bomb lands on the ground w/o bouncing it just stays there then disappears after a while.

Heres the code im left with now:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace GintamaMod.Projectiles
{
public class JustAway : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "JustAway";
projectile.width = 29;
projectile.height = 25;
projectile.aiStyle = 16;
projectile.friendly = true;
projectile.penetrate = -1;
projectile.thrown = true;
projectile.light = 0.5f;
projectile.extraUpdates = 1;


}


public override bool OnTileCollide(Vector2 oldVelocity)
{
projectile.penetrate--;
if (projectile.penetrate <= 0)
{
projectile.timeLeft = 5;

}
else
{
if (projectile.velocity.X != oldVelocity.X)
{
projectile.velocity.X = -oldVelocity.X;
}
if (projectile.velocity.Y != oldVelocity.Y)
{
projectile.velocity.Y = -oldVelocity.Y;
}
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 10);
}
return false;
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
for (int k = 0; k < projectile.oldPos.Length; k++)
{
Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
}
return true;
}
}
}
 
I am not sure how to fix this, but a lot of mods are not working for me. I have latest versions of the mods and tmodloader. I make a Large, Expert world. And when it loads, it stops at "Generating Structures...Minecart Tracks." But when I don't use mods it works fine. How do i fix this?
 
I am not sure how to fix this, but a lot of mods are not working for me. I have latest versions of the mods and tmodloader. I make a Large, Expert world. And when it loads, it stops at "Generating Structures...Minecart Tracks." But when I don't use mods it works fine. How do i fix this?
It might be a specific mod that your using, try them all out separatly and see which one is broken
 
So I can see them now but now the explosion is invisible and if the bomb lands on the ground w/o bouncing it just stays there then disappears after a while.

Heres the code im left with now:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace GintamaMod.Projectiles
{
public class JustAway : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "JustAway";
projectile.width = 29;
projectile.height = 25;
projectile.aiStyle = 16;
projectile.friendly = true;
projectile.penetrate = -1;
projectile.thrown = true;
projectile.light = 0.5f;
projectile.extraUpdates = 1;


}


public override bool OnTileCollide(Vector2 oldVelocity)
{
projectile.penetrate--;
if (projectile.penetrate <= 0)
{
projectile.timeLeft = 5;

}
else
{
if (projectile.velocity.X != oldVelocity.X)
{
projectile.velocity.X = -oldVelocity.X;
}
if (projectile.velocity.Y != oldVelocity.Y)
{
projectile.velocity.Y = -oldVelocity.Y;
}
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 10);
}
return false;
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
for (int k = 0; k < projectile.oldPos.Length; k++)
{
Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
}
return true;
}
}
}

So as I feared, some of the bomb code is type-locked, and I don't exactly know how much. If this doesn't work, then you'll have to dig into the source code yourself:
  1. Change projectile.timeLeft = 5; back to projectile.Kill();
  2. Put this in your code:
Code:
public override bool PreKill(int timeLeft)
{
    projectile.maxPenetrate = -1;
    projectile.penetrate = -1;
    int area = 60;
    projectile.position.X = projectile.position.X - (float)(area / 2);
    projectile.position.Y = projectile.position.Y - (float)(area / 2);
    projectile.width += area;
    projectile.height += area;
    projectile.tileCollide = false;
    projectile.velocity *= 0.01f;
    projectile.Damage();
    projectile.scale = 0.01f;
    return true;
}

This is a very long shot, and I doubt it will work, but it's the best I can do without transcribing the entire Projectile class.
 
So as I feared, some of the bomb code is type-locked, and I don't exactly know how much. If this doesn't work, then you'll have to dig into the source code yourself:
  1. Change projectile.timeLeft = 5; back to projectile.Kill();
  2. Put this in your code:
Code:
public override bool PreKill(int timeLeft)
{
    projectile.maxPenetrate = -1;
    projectile.penetrate = -1;
    int area = 60;
    projectile.position.X = projectile.position.X - (float)(area / 2);
    projectile.position.Y = projectile.position.Y - (float)(area / 2);
    projectile.width += area;
    projectile.height += area;
    projectile.tileCollide = false;
    projectile.velocity *= 0.01f;
    projectile.Damage();
    projectile.scale = 0.01f;
    return true;
}

This is a very long shot, and I doubt it will work, but it's the best I can do without transcribing the entire Projectile class.
Ok I'll try that, thanks for all your help
 
Can't seem to publish my mod anymore for the next update, possibly too big now that I've added wav files? Total folder size for working directory is 26.2mb, tmod file 11mb. This is the error I get:

The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at Terraria.ModLoader.IO.UploadFile.UploadFiles(String address, IEnumerable`1 files, NameValueCollection values)
at Terraria.ModLoader.UI.UIModSourceItem.Publish(UIMouseEvent evt, UIElement listeningElement)

Can the timeout window be increased? Or another way of uploading mods?
 
Last edited:
Back
Top Bottom