Standalone [1.3] tModLoader - A Modding API

I need help, i am trying to make it so that if you are within a certain radius (about 10 to 20 blocks) of this projectile then you will get the regen buff. However it gives you regen if you are anywhere while the projectile is out. Anyone know how to do that or know what i'm doing wrong? Help would be much appreciated
Thank you in advance
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace RCT.Projectiles
{
    public class MedicSphereBallProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Guardian Sphere Projectile";
            projectile.width = 20;
            projectile.height = 20;
            projectile.aiStyle = 47;
            projectile.ranged = true;
            projectile.penetrate = 2;
            projectile.timeLeft = 1800;
            projectile.ignoreWater = true;
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.tileCollide = false;
           
        }
        public override void AI()
        {
            projectile.rotation += (float)projectile.direction * 0.8f;
           
                
            projectile.light = 1;
            Player owner = Main.player[projectile.owner];
            if (owner.position.X - projectile.position.X <= 10f && owner.position.Y - projectile.position.Y <= 10f || owner.position.X - projectile.position.X >= 10f && owner.position.Y - projectile.position.Y >= 10f || owner.position.X - projectile.position.X <= 10f && owner.position.Y - projectile.position.Y >= 10f || owner.position.X - projectile.position.X >= 10f && owner.position.Y - projectile.position.Y <= 10f)
            {
           
                    owner.AddBuff(2, 1800);

            }
        }
    }
}
 
I need help, i am trying to make it so that if you are within a certain radius (about 10 to 20 blocks) of this projectile then you will get the regen buff. However it gives you regen if you are anywhere while the projectile is out. Anyone know how to do that or know what i'm doing wrong? Help would be much appreciated
Thank you in advance
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace RCT.Projectiles
{
    public class MedicSphereBallProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Guardian Sphere Projectile";
            projectile.width = 20;
            projectile.height = 20;
            projectile.aiStyle = 47;
            projectile.ranged = true;
            projectile.penetrate = 2;
            projectile.timeLeft = 1800;
            projectile.ignoreWater = true;
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.tileCollide = false;
         
        }
        public override void AI()
        {
            projectile.rotation += (float)projectile.direction * 0.8f;
         
              
            projectile.light = 1;
            Player owner = Main.player[projectile.owner];
            if (owner.position.X - projectile.position.X <= 10f && owner.position.Y - projectile.position.Y <= 10f || owner.position.X - projectile.position.X >= 10f && owner.position.Y - projectile.position.Y >= 10f || owner.position.X - projectile.position.X <= 10f && owner.position.Y - projectile.position.Y >= 10f || owner.position.X - projectile.position.X >= 10f && owner.position.Y - projectile.position.Y <= 10f)
            {
         
                    owner.AddBuff(2, 1800);

            }
        }
    }
}
Well, your logic is off. Just do this: (10 is pretty small though)

Code:
            Player owner = Main.player[projectile.owner];
            float distance = Vector2.Distance(owner.Center, projectile.Center);

            if (distance < 10f)
            {
                owner.AddBuff(2, 1800);
            }
 
Yeah... As its been asked a million times on the thread, would the issue with multiplayer boss spawning be the problem of the item used to summon it, or the ai of the boss itself wigging out with multiple players on screen? and to add onto that question, do the tModLoader guys know exactly what were doing wrong that makes our modded enemies disappear when hit? Is it our fault?
The multiplayer bosses could be a problem with the item and/or the boss's AI; that would depend on the boss.

We still can't really decide what's causing modded enemies to disappear on hit. I think we're going to see if making servers sync mods with the clients helps anything first.
 
How come when i mine with my modded pickaxe that it mines so slowly compared to the Pickaxe Axe of vanilla terraria? Is there extra code to make it so that the actual mining if faster than the swing or am i just doing something wrong? If there is extra code to make it mine faster then some incite on how to do so would be very helpful.
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace RCT.Items.Tools
{
    public class DivineConversionPickaxeAxe : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Divine Conversion - Pickaxe-Axe";
            item.damage = 30;
            item.melee = true;
            item.width = 60;
            item.height = 60;
            item.useTime = 25;
            item.useAnimation = 25;
            item.axe = 23;
            item.pick = 205;
            item.useStyle = 1;
            item.knockBack = 6;
            item.value = 600000;
            item.rare = 5;
            item.useSound = 1;
            item.autoReuse = true;
          
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "DivineConversionBlade", 1);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
     
    }
}
 
EM... ambiguous again, sorry.
OnPickup is not suitable for my aim. Making OnPickup return false only stop the item appearing in the inventory, but I need to entirely ban a player from picking the item under certain circumstance. Something like... say, when a player's inventory was full, he can't even pick any items he doesn't have, right?
Since I resupply the durability of my throwing knife upon picking up the dropping items, I need to make sure that a player without relative throwing knife won't grab the dropping throwing knife accidentally. This will disappoint the player who is ready to grab his knives!
Still having a hard time denying a certain item from being picked.... Seems I cannot find how vanilla codes deny player from picking items when his inventory is full. So gotta have to ask again. Little help?
 
Still having a hard time denying a certain item from being picked.... Seems I cannot find how vanilla codes deny player from picking items when his inventory is full. So gotta have to ask again. Little help?
You can use this function to determine wether or not the item can be picked up. This does not apply to items being picked up from chests, so keep that in mind.
 
how do I use this?
public virtual bool CanExplode(int i, int j)
The int i and int j are the tile location. U can do things like
if(tile.type == ItemID.Anvils) return false;
if(Main.player[Main.myPlayer].position.X < i) return false;
and all kinds of trickery like that.
Personally I use it to prevent my house tiles from getting accidentally blown up when someone forgets they got stickybombs equipped

Edit: not to rush or anything, but i've kinda hit a roadblock in my modding.

i need some item related stuff, namely saving and loading (for GlobalItem). i would also like to make prefixes/suffixes, but the main thing i need is save/load.
also this is additional but i want to be able to
Code:
                if (tile.inActive())
                {
                    Wiring.ReActive(i, j);
                }
                else
                {
                    Wiring.DeActive(i, j);
                }
but i can't since its private
 
Last edited:
It is, with a bit of (I guess you could say) 'hacky' code.
You can override the Pre/PostDraw function on a class that derives from GlobalItem, which will make it so your UI is persistent.
Do note, however, that this is (like mentioned before) a 'hacky' approach, since offocial UI draw hooks have not been implemented in tModLoader as of yet.
 
You can use this function to determine wether or not the item can be picked up. This does not apply to items being picked up from chests, so keep that in mind.
Yeah, I know this. But... I'm desperate in expressing my idea, but I'm always ambiguous about it... Although this hook returns false, Isn't an item still can be "picked" by a player? Only this item won't appear in their inventory, but they will pick it. The item will just go missing. What I'm tryna do is to deny the player from picking the item, which means the item will not even respond to the player when he gets close to the item, precisely like when a player has a full inventory...
 
It is, with a bit of (I guess you could say) 'hacky' code.
You can override the Pre/PostDraw function on a class that derives from GlobalItem, which will make it so your UI is persistent.
Do note, however, that this is (like mentioned before) a 'hacky' approach, since offocial UI draw hooks have not been implemented in tModLoader as of yet.
thanks for the info, i guess i'll wait for "oficial" support, hacky code can be a hell to maintain, and even worse to later port to non-hacky xD
 
how do i get the vanilla boss codes for use in the if()

ExampleWorld.downedAbomination
this one works but thats a modded boss

i like to get all the vanilla bosses for this
 
@Eldrazi :
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace HyperTerraria.Projectiles
{
    public class EnchantedChlorophyteRound : ModProjectile
    {

        public override void SetDefaults()
        {
            projectile.name = "Enchanted Chlorophyte Bullet";
            projectile.alpha = 255;
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.ranged = true;
           
            projectile.penetrate = 1;
            projectile.timeLeft = 2000;
            /*ProjectileID.Sets.Homing[ModProjectile] = true;
            */
            projectile.tileCollide = true;
            projectile.ignoreWater = true;
            projectile.aiStyle = 340;
            projectile.light = 1;
           
          
        }
    

  public override bool PreAI()
       
        //    return base.PreAI();
        //}

        //public override void AI()
        //{
            {
            if (projectile.alpha > 0)
            {
                projectile.alpha -= 50;
            }
            else
            {
                projectile.extraUpdates = 0;
            }
            if (projectile.alpha < 0)
            {
                projectile.alpha = 0;
            }
            projectile.rotation = (float)System.Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) - 1.57f;
            projectile.frameCounter++;
            if (projectile.frameCounter >= 6)
            {
                projectile.frame++;
                projectile.frameCounter = 0;
            }
            if (projectile.frame >= 2)
            {
                projectile.frame = 0;
            }
            for (int num363 = 0; num363 < 3; num363++)
            {
                float num364 = projectile.velocity.X / 3f * (float)num363;
                float num365 = projectile.velocity.Y / 3f * (float)num363;
                int num161 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 74, 0f, 0f, 0, default(Color), 1f);
                Main.dust[num161].position.X = projectile.Center.X - num364;
                Main.dust[num161].position.Y = projectile.Center.Y - num365;
                Main.dust[num161].velocity *= 0f;
                Main.dust[num161].scale = 0.5f;
            }

            float num367 = projectile.position.X;
            float num368 = projectile.position.Y;
            float num369 = 100000f;
            bool flag10 = false;
            projectile.ai[0] += 1f;
         
                for (int num370 = 0; num370 < 200; num370++)
                {
                    if (Main.npc[num370].CanBeChasedBy(projectile, false) && (!Main.npc[num370].wet /*|| projectile.type == 307*/))
                    {
                        float num371 = Main.npc[num370].position.X + (float)(Main.npc[num370].width / 2);
                        float num372 = Main.npc[num370].position.Y + (float)(Main.npc[num370].height / 2);
                        float num373 = System.Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num371) + System.Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num372);
                        if (num373 < 800f && num373 < num369 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num370].position, Main.npc[num370].width, Main.npc[num370].height))
                        {
                            num369 = num373;
                            num367 = num371;
                            num368 = num372;
                            flag10 = true;
                        }
                    }
               
            }
            if (!flag10)
            {
                num367 = projectile.position.X + (float)(projectile.width / 2) + projectile.velocity.X * 100f;
                num368 = projectile.position.Y + (float)(projectile.height / 2) + projectile.velocity.Y * 100f;
            }
            else /*if (projectile.type == 307)*/
            {
                projectile.friendly = true;
            }
            float num374 = 6f;
            float num375 = 0.1f;

            num374 = 9f;
            num375 = 0.2f;

            Vector2 vector27 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
            float num376 = num367 - vector27.X;
            float num377 = num368 - vector27.Y;
            float num378 = (float)System.Math.Sqrt((double)(num376 * num376 + num377 * num377));
            num378 = num374 / num378;
            num376 *= num378;
            num377 *= num378;
            if (projectile.velocity.X < num376)
            {
                projectile.velocity.X = projectile.velocity.X + num375;
                if (projectile.velocity.X < 0f && num376 > 0f)
                {
                    projectile.velocity.X = projectile.velocity.X + num375 * 2f;
                }
            }
            else if (projectile.velocity.X > num376)
            {
                projectile.velocity.X = projectile.velocity.X - num375;
                if (projectile.velocity.X > 0f && num376 < 0f)
                {
                    projectile.velocity.X = projectile.velocity.X - num375 * 2f;
                }
            }
            if (projectile.velocity.Y < num377)
            {
                projectile.velocity.Y = projectile.velocity.Y + num375;
                if (projectile.velocity.Y < 0f && num377 > 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y + num375 * 2f;
                    return false;
                }
            }
            else if (projectile.velocity.Y > num377)
            {
                projectile.velocity.Y = projectile.velocity.Y - num375;
                if (projectile.velocity.Y > 0f && num377 < 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y - num375 * 2f;
                    return false;
                }
            }

            return false;
        }
    }

   
}
Please note, I don't want it to be reflecteable ^^
 
@Eldrazi :
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace HyperTerraria.Projectiles
{
    public class EnchantedChlorophyteRound : ModProjectile
    {

        public override void SetDefaults()
        {
            projectile.name = "Enchanted Chlorophyte Bullet";
            projectile.alpha = 255;
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.ranged = true;
          
            projectile.penetrate = 1;
            projectile.timeLeft = 2000;
            /*ProjectileID.Sets.Homing[ModProjectile] = true;
            */
            projectile.tileCollide = true;
            projectile.ignoreWater = true;
            projectile.aiStyle = 340;
            projectile.light = 1;
          
         
        }
   

  public override bool PreAI()
      
        //    return base.PreAI();
        //}

        //public override void AI()
        //{
            {
            if (projectile.alpha > 0)
            {
                projectile.alpha -= 50;
            }
            else
            {
                projectile.extraUpdates = 0;
            }
            if (projectile.alpha < 0)
            {
                projectile.alpha = 0;
            }
            projectile.rotation = (float)System.Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) - 1.57f;
            projectile.frameCounter++;
            if (projectile.frameCounter >= 6)
            {
                projectile.frame++;
                projectile.frameCounter = 0;
            }
            if (projectile.frame >= 2)
            {
                projectile.frame = 0;
            }
            for (int num363 = 0; num363 < 3; num363++)
            {
                float num364 = projectile.velocity.X / 3f * (float)num363;
                float num365 = projectile.velocity.Y / 3f * (float)num363;
                int num161 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 74, 0f, 0f, 0, default(Color), 1f);
                Main.dust[num161].position.X = projectile.Center.X - num364;
                Main.dust[num161].position.Y = projectile.Center.Y - num365;
                Main.dust[num161].velocity *= 0f;
                Main.dust[num161].scale = 0.5f;
            }

            float num367 = projectile.position.X;
            float num368 = projectile.position.Y;
            float num369 = 100000f;
            bool flag10 = false;
            projectile.ai[0] += 1f;
        
                for (int num370 = 0; num370 < 200; num370++)
                {
                    if (Main.npc[num370].CanBeChasedBy(projectile, false) && (!Main.npc[num370].wet /*|| projectile.type == 307*/))
                    {
                        float num371 = Main.npc[num370].position.X + (float)(Main.npc[num370].width / 2);
                        float num372 = Main.npc[num370].position.Y + (float)(Main.npc[num370].height / 2);
                        float num373 = System.Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num371) + System.Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num372);
                        if (num373 < 800f && num373 < num369 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num370].position, Main.npc[num370].width, Main.npc[num370].height))
                        {
                            num369 = num373;
                            num367 = num371;
                            num368 = num372;
                            flag10 = true;
                        }
                    }
              
            }
            if (!flag10)
            {
                num367 = projectile.position.X + (float)(projectile.width / 2) + projectile.velocity.X * 100f;
                num368 = projectile.position.Y + (float)(projectile.height / 2) + projectile.velocity.Y * 100f;
            }
            else /*if (projectile.type == 307)*/
            {
                projectile.friendly = true;
            }
            float num374 = 6f;
            float num375 = 0.1f;

            num374 = 9f;
            num375 = 0.2f;

            Vector2 vector27 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
            float num376 = num367 - vector27.X;
            float num377 = num368 - vector27.Y;
            float num378 = (float)System.Math.Sqrt((double)(num376 * num376 + num377 * num377));
            num378 = num374 / num378;
            num376 *= num378;
            num377 *= num378;
            if (projectile.velocity.X < num376)
            {
                projectile.velocity.X = projectile.velocity.X + num375;
                if (projectile.velocity.X < 0f && num376 > 0f)
                {
                    projectile.velocity.X = projectile.velocity.X + num375 * 2f;
                }
            }
            else if (projectile.velocity.X > num376)
            {
                projectile.velocity.X = projectile.velocity.X - num375;
                if (projectile.velocity.X > 0f && num376 < 0f)
                {
                    projectile.velocity.X = projectile.velocity.X - num375 * 2f;
                }
            }
            if (projectile.velocity.Y < num377)
            {
                projectile.velocity.Y = projectile.velocity.Y + num375;
                if (projectile.velocity.Y < 0f && num377 > 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y + num375 * 2f;
                    return false;
                }
            }
            else if (projectile.velocity.Y > num377)
            {
                projectile.velocity.Y = projectile.velocity.Y - num375;
                if (projectile.velocity.Y > 0f && num377 < 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y - num375 * 2f;
                    return false;
                }
            }

            return false;
        }
    }

  
}
Please note, I don't want it to be reflecteable ^^
Hmm, have you tried changing these values:
Code:
num374 = 9f;
num375 = 0.2f;
in the AI to something bigger? Like 14 instead of 9?
 
Back
Top Bottom