Standalone [1.3] tModLoader - A Modding API

Hello again. I have a few questions.

Is there a way to add a new piece of advice to the pool of advice that the Guide gives you?

I've added two custom NPC's to my mod, but if I exit and re-enter my world, they will have disappeared and show up again soon afterwards. Is this a bug, or do I need to set something within my NPC's class file to make them persistent. In my case, both require a custom tile to be in the housing. Could this be affecting their persistence?

Earlier, you said that you weren't going to use playerLayers to change the player's appearance. Have you changed your mind, or am I mis-reading the planned updates?
 
Hello again. I have a few questions.

Is there a way to add a new piece of advice to the pool of advice that the Guide gives you?

I've added two custom NPC's to my mod, but if I exit and re-enter my world, they will have disappeared and show up again soon afterwards. Is this a bug, or do I need to set something within my NPC's class file to make them persistent. In my case, both require a custom tile to be in the housing. Could this be affecting their persistence?

Earlier, you said that you weren't going to use playerLayers to change the player's appearance. Have you changed your mind, or am I mis-reading the planned updates?
At the moment there isn't any way to edit the Guide's messages. Also he has a really messy system for messages. (tAPI didn't have it either so I ended up making my own NPC.)

To make your NPCs persistent, you need to use Autoload so that their internal names match their display names. (I'll probably try to change this in the future.)

I think I've thought of some way so that I could add support for PlayerLayers without making overly extensive changes to the source code. Plus I don't know how else I could possibly modify player drawing. So yeah, I've changed my mind from before.
 
Can I get some help making a sword that has life stealing ability?
I tried this,
public void DamageNPC(Player myPlayer, NPC npc, ref int damage, ref float knockback)
{

myPlayer.HealEffect(damage);

myPlayer.statLife += damage;

}
but the sword does nothing. Tried a bunch of other ways that i can't even remember at this point. Been trying to get this to work for like 3 days...
 
Can I get some help making a sword that has life stealing ability?
I tried this,
public void DamageNPC(Player myPlayer, NPC npc, ref int damage, ref float knockback)
{

myPlayer.HealEffect(damage);

myPlayer.statLife += damage;

}
but the sword does nothing. Tried a bunch of other ways that i can't even remember at this point. Been trying to get this to work for like 3 days...
It does nothing, because you're not overriding a function. You'll want to override the OnHitNPC function for this to work, like follows:
Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
    player.HealEffect(damage);
    player.statLife += damage;
}
 
It does nothing, because you're not overriding a function. You'll want to override the OnHitNPC function for this to work, like follows:
Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
    player.HealEffect(damage);
    player.statLife += damage;
}
When I put in that code, I get
error CS0115: 'Ice2.Items.Weapons.ice.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
 
When I put in that code, I get
error CS0115: 'Ice2.Items.Weapons.ice.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
Could I see your whole class with the OnHitNPC function in it, because this function if working fine for me?
 
Could I see your whole class with the OnHitNPC function in it, because this function if working fine for me?
Sure
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Ice2.Items;
using Ice2.Items.Weapons;
using Ice2.Items.Armor;

namespace Ice2.Items.Weapons
{
public class GlacierBlade : ModItem
{
public override void SetDefaults()
{
item.name = "Glacier Blade";
item.damage = 165;
item.width = 40;
item.height = 40;
item.toolTip = "Chill them to the Bone.";
item.toolTip2 = "The blade will sap enemy Life.";
item.useTime = 14;
item.useAnimation = 14;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000000;
item.rare = 11;
item.useSound = 1;
item.autoReuse = true;
item.useTurn = true;
item.melee = true;
item.ranged = true;
item.shoot = mod.ProjectileType("ice");
item.shootSpeed = 1f;
}

public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
player.HealEffect(damage);
player.statLife += damage;
}


public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(3467, 20);
recipe.AddIngredient(2161, 3);
recipe.AddTile(412);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
Hmm, allright...
Copy pasting that code works fine, so my next question to you is the following:
Why is your error starting with 'Ice2.Items.Weapons.ice'? Do you have an ice class somewhere, because this class is clearly called GlacierBlade...
 
The mod itself is named Ice2 for now, there's the sword, the swords projectile (ice), and armor. I can get it to work too, but as soon as I put the projectile part back on it stops doing the health regen and I'm not sure why. The error was my fault that's gone now
 
The mod itself is named Ice2 for now, there's the sword, the swords projectile (ice), and armor. I can get it to work too, but as soon as I put the projectile part back on it stops doing the health regen and I'm not sure why. The error was my fault that's gone now
What do you mean with 'put the projectile part back on'?
If it breaks when you add your projectile, there's obviously something wrong with that. Could I see your projectiles' code?
 
The mod itself is named Ice2 for now, there's the sword, the swords projectile (ice), and armor. I can get it to work too, but as soon as I put the projectile part back on it stops doing the health regen and I'm not sure why. The error was my fault that's gone now
Sorry that wasn't good wording. I can get the swords regen to work (thanks to your code) but if I add the same code to the projectile that's when the error comes up and I can't get the projectile to also give regen.
[DOUBLEPOST=1449054352,1449054298][/DOUBLEPOST]this is the projectile
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Ice2.Items;
using Ice2.Items.Weapons;

namespace Ice2.Items.Weapons
{
public class ice : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "Ice";
projectile.width = 20;
projectile.height = 20;
projectile.scale = 1.0f;
projectile.aiStyle = 27;
projectile.damage = 120;
projectile.friendly = true;
projectile.melee = true;
projectile.penetrate = 3;
projectile.timeLeft = 500;
projectile.light = 1f;
projectile.extraUpdates = 15;
projectile.tileCollide = true;
projectile.coldDamage = true;
projectile.numHits = 12;
projectile.ignoreWater = true;
}
/*
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
player.HealEffect(damage);
player.statLife += damage;
}
*/
}
}
the regen part is in the comment code because it wont work for some reason
 
Sorry that wasn't good wording. I can get the swords regen to work (thanks to your code) but if I add the same code to the projectile that's when the error comes up and I can't get the projectile to also give regen.
Oooh, allright, that makes sense.
The OnHitNPC function for the projectile is different, take a look at this:
Code:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
}
Notice that the Player parameter is gone. Now, if you want to GET the player of this projectile, you can just do:
Code:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
    Player player = Main.player[projectile.owner];
    // Lifesteal stuff with player.
}
Hope that works!
 
Oooh, allright, that makes sense.
The OnHitNPC function for the projectile is different, take a look at this:
Code:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
}
Notice that the Player parameter is gone. Now, if you want to GET the player of this projectile, you can just do:
Code:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
    Player player = Main.player[projectile.owner];
    // Lifesteal stuff with player.
}
Hope that works!
You have saved my sanity thank you!
 
You have the Projectile.NewProjectle function to spawn your projectile.
Lemme give you an example:
Code:
Vector2 pos = projectile.Center;
Vector2 dir = Vector2.Normalize(projectile.velocity);
if (float.IsNaN(dir.X) || float.IsNaN(dir.Y))
{
    dir = -Vector2.UnitY;
}
Projectile.NewProjectile(pos.X, pos.Y, dir.X, dir.Y, mod.ProjectileType("PowerBeamShot"),
        projectile.damage, projectile.knockBack, projectile.owner);
That is how you would spawn a projectile with the code I gave you earlier.

That did it, thank you. However the projectiles are veeery slow now, what could be causing that?
 
Back
Top Bottom