Creeper da Snek
Plantera
ExampleMod’s good for that. https://github.com/blushiemagic/tModLoader/tree/master/ExampleModCan I see anyone's projectile.cs script and sword.cs script to reference off?
ExampleMod’s good for that. https://github.com/blushiemagic/tModLoader/tree/master/ExampleModCan I see anyone's projectile.cs script and sword.cs script to reference off?
Take the projectile code and move everything except the DisplayName call to the SetDefaults method:Hewwo, I'm trying to "code" a melee projectile. The melee work, projectile pops up, the only problem is that, the projectile is just /there/.
The projectile phases through enemies, doesn't do much except fly away..
Can anyone show me a script I can reference to?
My current script:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
namespace YinBlade.Projectiles
{
public class Lightning : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Lightning");
projectile.width = 200;
projectile.height = 200;
projectile.friendly = true;
projectile.melee = true;
projectile.tileCollide = true;
projectile.penetrate = -1;
projectile.timeLeft = 200;
projectile.light = 20f;
projectile.extraUpdates = 1;
projectile.ignoreWater = true;
}
public override void AI()
{
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 90f;
}
}
}
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Lightning");
}
public override void SetDefaults()
{
projectile.width = 200;
projectile.height = 200;
projectile.friendly = true;
projectile.melee = true;
projectile.tileCollide = true;
projectile.penetrate = 1;
projectile.timeLeft = 200;
projectile.light = 20f;
projectile.extraUpdates = 1;
projectile.ignoreWater = true;
}
It did end up helping, it lead me to the code in the terraria game files to find the moveSpeed variable (or whatever you call it here, I'm too used to Python) So thanks!
I do have a string of questions now though.. The first one being, how would you create an item with damage reduction? The mod itself is for adding a whole load of shields into the game, and I've currently got them adding defense, but I do realise it's much better to have damage reduction instead. Plus, this would end up helping with finding a way to make knockback apply to the player for a mechanic I want, as it'd factor in the damage you take which I could find from a damage reduction calculation.
:0 At least I got something to believe/hope towards.Is there such thing as setting a different damage value for your projectile vs the sword's damage value? (Projectile refers to projectiles of melee)
Easiest way is to override the Shoot method on your ModItem:I tried "projectile.damage = 100;" didn't work,
I did find something on the internet, but it resulted in some errors that I'm clueless about.. the line of code is:
virtual void Terraria.ModLoader.ModProjectile.ModifyHitNPC ( ... ref int 100, ... )
public override void SetDefaults()
{
// Blabla
}
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
damage = 100;
return true;
}
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
namespace TrepidityMod.Items.Weapons.Prehardmode.Shortswords
{
public class VilethornStabber : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Vilethorn Stabber");
}
public override void SetDefaults()
{
item.damage = 15;
item.melee = true;
item.width = 32;
item.height = 32;
item.useTime = 15;
item.useAnimation = 15;
item.useStyle = 3;
item.knockBack = 3;
item.value = 100;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = ProjectileID.VilethornTip;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
For the item.shoot set you'll want to use ProjectileID.VilethornBase instead of VilethornTip.I am trying to make a vilethorn style weapon using the vanilla vilethorn projectile. Problem is i don't know how to combine the vilethorn with its end to create that kind of projectile that you see with it. I also want to make it so that it does the projectile every 5th swing since it is an autoreuse weapon. If someone could please help me out so far i have this as my code.
Code:using Terraria; using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; using Microsoft.Xna.Framework; namespace TrepidityMod.Items.Weapons.Prehardmode.Shortswords { public class VilethornStabber : ModItem { public override void SetStaticDefaults() { DisplayName.SetDefault("Vilethorn Stabber"); } public override void SetDefaults() { item.damage = 15; item.melee = true; item.width = 32; item.height = 32; item.useTime = 15; item.useAnimation = 15; item.useStyle = 3; item.knockBack = 3; item.value = 100; item.rare = 2; item.UseSound = SoundID.Item1; item.autoReuse = true; item.shoot = ProjectileID.VilethornTip; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ItemID.DirtBlock, 1); recipe.AddTile(TileID.WorkBenches); recipe.SetResult(this); recipe.AddRecipe(); } } }
int swingAmount = 0;
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
if(swingAmount++ < 5) return false;
swingAmount = 0;
return true;
}
Set item.nousegraphic to trueHello, I am trying to make a modded sword, and I'm running into two issues.
1. The sword's sprite doesn't show up when swinging.
2. No matter what I set the item.width and item.height values to, the sword always has a ridiculously long range (It can hit things offscreen)
Here is the code: (I've just started so there's not a lot)
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace NinjagoMod.Items
{
public class SwordOfFire : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Sword of Fire");
Tooltip.SetDefault("Forged with gold from the Golden Peaks");
}
public override void SetDefaults()
{
item.damage = 25;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 22;
item.useAnimation = 22;
item.useStyle = 1;
item.knockBack = 6;
item.value = 50000;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.noUseGraphic = false;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.GoldBar, 15);
recipe.AddIngredient(ItemID.Diamond, 1);
recipe.AddIngredient(ItemID.Ruby, 5);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.PlatinumBar, 15);
recipe.AddIngredient(ItemID.Diamond, 1);
recipe.AddIngredient(ItemID.Ruby, 5);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
target.AddBuff(BuffID.OnFire, 300);
}
}
}
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Subweapons.Items.Cross {
public class WoodenCross : ModItem
{
public override void SetDefaults()
{
item.knockBack = 4;
item.damage = 10;
item.useAnimation = 21;
item.useTime = 21;
item.useStyle = 1;
item.UseSound = SoundID.Item1;
item.width = 34;
item.height = 34;
item.maxStack = 999;
item.shoot = mod.ProjectileType("WoodenCross");
item.consumable = true;
item.noUseGraphic = true;
item.noMelee = true;
item.autoReuse = false;
item.thrown = true;
item.shootSpeed = 5.9f;
item.value = Item.sellPrice(copper: 10);
item.rare = 0;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this, 50);
recipe.AddRecipe();
}
}}
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Subweapons.Projectiles.Cross
{
public class WoodenCross : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("WoodenCross");
}
public override void SetDefaults()
{
projectile.CloneDefaults(ProjectileID.WoodenBoomerang);
projectile.friendly = true;
projectile.thrown = true;
projectile.tileCollide = false;
projectile.penetrate = -1;
projectile.width = 22;
projectile.height = 22;
projectile.MaxUpdates = 2;
aiType = ProjectileID.WoodenBoomerang;
}
public override void AI()
{
if ((double) projectile.ai[1] >= 27.5)
{
projectile.ai[0] = 1f;
projectile.ai[1] = 0.0f;
projectile.netUpdate = true;
}
}
}
}
Not sure, but a possible fix:Hey, how would I go about making a boomerang pierce when it goes forwards, instead of just piercing when it goes backwards?
The only way I've gotten it to work is by either setting the projectile to basically be the Paladin's Hammer with projectile.type or if you hit with just the tip of the throw, with some snippets of the source code.
Code:using System; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace Subweapons.Items.Cross { public class WoodenCross : ModItem { public override void SetDefaults() { item.knockBack = 4; item.damage = 10; item.useAnimation = 21; item.useTime = 21; item.useStyle = 1; item.UseSound = SoundID.Item1; item.width = 34; item.height = 34; item.maxStack = 999; item.shoot = mod.ProjectileType("WoodenCross"); item.consumable = true; item.noUseGraphic = true; item.noMelee = true; item.autoReuse = false; item.thrown = true; item.shootSpeed = 5.9f; item.value = Item.sellPrice(copper: 10); item.rare = 0; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ItemID.DirtBlock, 1); recipe.SetResult(this, 50); recipe.AddRecipe(); } }}
View attachment 210150Code:using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace Subweapons.Projectiles.Cross { public class WoodenCross : ModProjectile { public override void SetStaticDefaults() { DisplayName.SetDefault("WoodenCross"); } public override void SetDefaults() { projectile.CloneDefaults(ProjectileID.WoodenBoomerang); projectile.friendly = true; projectile.thrown = true; projectile.tileCollide = false; projectile.penetrate = -1; projectile.width = 22; projectile.height = 22; projectile.MaxUpdates = 2; aiType = ProjectileID.WoodenBoomerang; } public override void AI() { if ((double) projectile.ai[1] >= 27.5) { projectile.ai[0] = 1f; projectile.ai[1] = 0.0f; projectile.netUpdate = true; } } } }
And there's the item's image itself, if you want to test it in-game.
public override void PostAI()
{
projectile.penetrate = -1;
}
public class MyPlayer : ModPlayer
{
public bool NaughtyRomiPresentEQ;
public override void ResetEffects()
{
this.NaughtyRomiPresentEQ = false;
}
public override void OnHitNPC(Item item, NPC target, int damage, float knockback, bool crit)
{
if (this.NaughtyRomiPresentEQ == true)
player.AddBuff(mod.BuffType("BarrierBuff"), 1000);
}
}
public class NaughtyRomiPresent : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("");
}
public override void SetDefaults()
{
item.width = 10;
item.height = 14;
item.value = 10;
item.rare = 3;
item.accessory = true;
}
public override void UpdateAccessory(Player player, bool hideVisual)
{
player.GetModPlayer<MyPlayer>(mod).NaughtyRomiPresentEQ = true;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(TileID.LunarCraftingStation);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
public class BarrierBuff : ModBuff
{
public override void SetDefaults()
{
DisplayName.SetDefault("Barrier");
Description.SetDefault("");
Main.buffNoTimeDisplay[Type] = true;
}
public override void Update(Player player, ref int buffIndex)
{
player.statDefense += 500; //example
}
}
That looks right, maybe try to identify where it is messing up. You can do Main.NewText("Hi"); in Update or UpdateAccessory to make sure the code is running. You can also player.AddBuff with a vanilla Buff to see if that works. If you can identify what is messing up, that'll help.Hello guys I would like to know how to add OnHitNPC on accessory. I was already reading this forum and I was looking on google but I still can't figure out how to do that. I have ModPlayer class, Buff Class and ItemClass. When I hit NPC in game nothing happen. Am I missing something ?
Player Class
Code:public class MyPlayer : ModPlayer { public bool NaughtyRomiPresentEQ; public override void ResetEffects() { this.NaughtyRomiPresentEQ = false; } public override void OnHitNPC(Item item, NPC target, int damage, float knockback, bool crit) { if (this.NaughtyRomiPresentEQ == true) player.AddBuff(mod.BuffType("BarrierBuff"), 1000); } }
Item Class
Code:public class NaughtyRomiPresent : ModItem { public override void SetStaticDefaults() { Tooltip.SetDefault(""); } public override void SetDefaults() { item.width = 10; item.height = 14; item.value = 10; item.rare = 3; item.accessory = true; } public override void UpdateAccessory(Player player, bool hideVisual) { player.GetModPlayer<MyPlayer>(mod).NaughtyRomiPresentEQ = true; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ItemID.DirtBlock, 1); recipe.AddTile(TileID.LunarCraftingStation); recipe.SetResult(this); recipe.AddRecipe(); } }
Buff Class
Code:public class BarrierBuff : ModBuff { public override void SetDefaults() { DisplayName.SetDefault("Barrier"); Description.SetDefault(""); Main.buffNoTimeDisplay[Type] = true; } public override void Update(Player player, ref int buffIndex) { player.statDefense += 500; //example } }
Thanks for your time
That looks right, maybe try to identify where it is messing up. You can do Main.NewText("Hi"); in Update or UpdateAccessory to make sure the code is running. You can also player.AddBuff with a vanilla Buff to see if that works. If you can identify what is messing up, that'll help.
As always, the best place for help is the discord chat: discord.me/tModLoader