• Journey's End on PC - Find info here and here. Please report bugs and issues for PC 1.4 and 1.4.1 to Re-Logic here.
  • Journey's End on Mobile - Find info here. Report bugs for Mobile 1.4 to DR Studios at this link and give as much detail as possible.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Console and Switch - The latest news can be found here. To report a bug, please use this link.

tModLoader How do I make a Magma Stone equivalent for guns?

GTLugo

Plantera
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.
 

Sin Costan

Eye of Cthulhu
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

Resources
http://blushiemagic.github.io/tModL...ria_1_1_mod_loader_1_1_global_projectile.html
https://github.com/Harrison-Jue/COFP/blob/master/MProjectile.cs
 

GTLugo

Plantera
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.
 
Last edited:

Sin Costan

Eye of Cthulhu
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.
Here are the goals for this project:

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.
 

GTLugo

Plantera
Thank you for your help. :) I am learning things on my own as well, but like I said, I learn better through examples I can see.
 

GTLugo

Plantera
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;
 
Top Bottom