Hello! I wanted to know if anyone could help me out in making bullet damage inflict the On Fire debuff. I have been trying to figure this out for a few days now and now I want to see if someone could help me out.
Hello! I wanted to know if anyone could help me out in making bullet damage inflict the On Fire debuff. I have been trying to figure this out for a few days now and now I want to see if someone could help me out.
You want to make a GlobalProjectile and if you don't a player file.
To do it, simply use
Create buff variable in ModPlayer
OnHitNPC() hook (OnHitPvP hook if you want it to afflict players as well) to apply a debuff if the owner has above buff variable as true
Would you be so kind as to show me an example? I learn better that way. I tried looking at those ones you linked, but I don't understand how they work.
Would you be so kind as to show me an example? I learn better that way. I tried looking at those ones you linked, but I don't understand how they work.
You would want a ModPlayer.cs file, preferably in the root of your mod directory, all it would need to do is to:
1. Have a boolean (true or false) variable for your custom accessory buff.
2. Initialize that variable as false inside the hook "public override void Initialize() {}"
You want a GlobalProjectile.cs file, preferably in the same location as your ModPlayer
1. You need to use the hook "public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit) {}"
2. You need to check if the player has this variable:
- Get the player from the Main.player[] array by getting the owner ID from the projectile
- Get the player's ModPlayer properties to check if the player has the accessory
- Add buff to the target NPC if the player has the ModPlayer variable set as true
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ModName
{
public class ModPlayer : ModPlayer
{
public static bool fireInfusion; //Name of buff
public override void Initialize()
{
fireInfusion = false;
}
public override void PostUpdate()
{
/*Check for accessory, probably don't need this if you have it in your acessory*/
//Initialize bool for checking if accessory exists
bool hasFireInfusionStone = false;
//Loops through accessories to check for accessory
for(int i = 0; i < 8 + player.extraAccessorySlots; i++)
{
//If it exists then set hasFireInfusion stone to true and then break
if(player.armor[i].type == mod.ItemType("FireInfusionStone"))
{
hasFireInfusionStone = true;
break;
}
}
//If player has it, set fireInfusion to true otherwise, set it to false
if(hasFireInfusionStone)
{
fireInfusion = true;
}
else
{
fireInfusion = false;
}
}
}
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ModName
{
public class ModProjectile : GlobalProjectile
{
//Hook post damaging NPC
public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
{
//Get the player by using the ID given by projectile.owner
Player player = Main.player[projectile.owner];
//If player has the ModPlayer property of fireInfusion then add buff to NPC
if(player.GetModPlayer<ModPlayer>(mod).fireInfusion)
{
//Add "On Fire!" debuff for 5 ticks on NPC
target.AddBuff(BuffID.OnFire, 5, false);
}
}
}
}
Just to let you know, I have no idea if this will work, and I hope you learn to do this on your own.
This is an error that is similar to the one I keep running into:
Code:
c:\Users\Gabriel\Documents\My Games\Terraria\ModLoader\Mod Sources\ExtraGunGear\ModProjectile.cs(20,53) : error CS1061: 'Terraria.ModLoader.ModPlayer' does not contain a definition for 'fireInfusion' and no extension method 'fireInfusion' accepting a first argument of type 'Terraria.ModLoader.ModPlayer' could be found (are you missing a using directive or an assembly reference?)
I even ran into this error when I tried your code. :\
This is an error that is similar to the one I keep running into:
Code:
c:\Users\Gabriel\Documents\My Games\Terraria\ModLoader\Mod Sources\ExtraGunGear\ModProjectile.cs(20,53) : error CS1061: 'Terraria.ModLoader.ModPlayer' does not contain a definition for 'fireInfusion' and no extension method 'fireInfusion' accepting a first argument of type 'Terraria.ModLoader.ModPlayer' could be found (are you missing a using directive or an assembly reference?)
I even ran into this error when I tried your code. :\
try using these:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.