tModLoader Official tModLoader Help Thread

Remove the public override void UseStyle with much of probability is for this thing.
public override void UseStyle(Player player)
{
player.itemLocation.X -= 5f * player.direction;
player.itemLocation.Y += 4f * player.gravDir;
}
I tried but it didn't make a change...I believe the UseStyle function is only applied when I am using it.
 
I tried but it didn't make a change...I believe the UseStyle function is only applied when I am using it.
Yup, that's true.
Could you try the following for me:
Code:
public override Vector2? HoldoutOffset(Player player)
{
    Vector2 offset = new Vector2(8 * Main.player[item.owner].direction, 0);
    return offset;
}
 
Yup, that's true.
Could you try the following for me:
Code:
public override Vector2? HoldoutOffset(Player player)
{
    Vector2 offset = new Vector2(8 * Main.player[item.owner].direction, 0);
    return offset;
}
error CS0115: “whatever.Items.weapons.ShotGunII.HoldoutOffset(Terraria.Player)”
 
@Eldrazi : Optionnal help needed :
I still have the tiny eater of world particle effect, which part of the code does that ?
And how can i make the projectile glow ?
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace HyperTerraria.Projectiles
{
    public class Aura : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Aura";
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.penetrate = 1;
            projectile.timeLeft = 30;
            /*ProjectileID.Sets.Homing[ModProjectile] = true;
            */
            projectile.tileCollide = false;
            projectile.ignoreWater = true;
            projectile.aiStyle = 340;

        }
  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 num366 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 184, 0f, 0f, 0, default(Color), 1f);
                Main.dust[num366].position.X = projectile.Center.X - num364;
                Main.dust[num366].position.Y = projectile.Center.Y - num365;
                Main.dust[num366].velocity *= 0f;
                Main.dust[num366].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;
        }
    }
   
}
 
@Eldrazi : Optionnal help needed :
I still have the tiny eater of world particle effect, which part of the code does that ?
And how can i make the projectile glow ?
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace HyperTerraria.Projectiles
{
    public class Aura : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Aura";
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.penetrate = 1;
            projectile.timeLeft = 30;
            /*ProjectileID.Sets.Homing[ModProjectile] = true;
            */
            projectile.tileCollide = false;
            projectile.ignoreWater = true;
            projectile.aiStyle = 340;

        }
  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 num366 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 184, 0f, 0f, 0, default(Color), 1f);
                Main.dust[num366].position.X = projectile.Center.X - num364;
                Main.dust[num366].position.Y = projectile.Center.Y - num365;
                Main.dust[num366].velocity *= 0f;
                Main.dust[num366].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;
        }
    }
  
}
This piece of code spaws the Dusts (or particles, but in Terraria they're called Dusts):
Code:
for (int num363 = 0; num363 < 3; num363++)
{
float num364 = projectile.velocity.X / 3f * (float)num363;
float num365 = projectile.velocity.Y / 3f * (float)num363;
int num366 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 184, 0f, 0f, 0, default(Color), 1f);
Main.dust[num366].position.X = projectile.Center.X - num364;
Main.dust[num366].position.Y = projectile.Center.Y - num365;
Main.dust[num366].velocity *= 0f;
Main.dust[num366].scale = 0.5f;
}
 
That's is pretty weird.. maybe you can test yourself with my code and find what is wrong

using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Items.Weapons
{
public class YourWeapon : ModItem
{
public override void SetDefaults()
{
item.name = "Test Weapon";
item.damage = 100;
item.scale = 1.30f;
item.stack = 1;
item.ranged = true;
item.crit = 30;
item.width = 0;
item.height = 0;
item.toolTip = "";
item.useTime = 5;
item.useAnimation = 10;
item.useStyle = 5;
item.noMelee = true;
item.mana = 10;
item.knockBack = 10;
item.value = 100;
item.rare = 10;
item.useSound = 12;
item.autoReuse = true;
item.shoot = mod.ProjectileType("TestProj");
item.shootSpeed = 16f;
}


public override Vector2? HoldoutOffset()
{
Vector2 offset = new Vector2(-14,2);
// 8, 0 is something I just made up on the spot, just experiment with these numbers until you find something that works.
return offset;
}

public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
{
Vector2 direction = new Vector2(speedX, speedY);
direction.Normalize();
position += direction * item.width *item.height;
int ShotAmt = 10;
int spread = 30;
float spreadMult = 0.08f;
for (int i = 0; i < ShotAmt; i++)
{
float vX = speedX + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
float vY = speedY + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
Projectile.NewProjectile(position.X, position.Y, vX,vY, type, damage, knockBack, player.whoAmI);
}
return true;
}
}
}
}

As you can see is nothing special but, for me it works fine..
 
That's is pretty weird.. maybe you can test yourself with my code and find what is wrong

using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Items.Weapons
{
public class YourWeapon : ModItem
{
public override void SetDefaults()
{
item.name = "Test Weapon";
item.damage = 100;
item.scale = 1.30f;
item.stack = 1;
item.ranged = true;
item.crit = 30;
item.width = 0;
item.height = 0;
item.toolTip = "";
item.useTime = 5;
item.useAnimation = 10;
item.useStyle = 5;
item.noMelee = true;
item.mana = 10;
item.knockBack = 10;
item.value = 100;
item.rare = 10;
item.useSound = 12;
item.autoReuse = true;
item.shoot = mod.ProjectileType("TestProj");
item.shootSpeed = 16f;
}


public override Vector2? HoldoutOffset()
{
Vector2 offset = new Vector2(-14,2);
// 8, 0 is something I just made up on the spot, just experiment with these numbers until you find something that works.
return offset;
}

public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
{
Vector2 direction = new Vector2(speedX, speedY);
direction.Normalize();
position += direction * item.width *item.height;
int ShotAmt = 10;
int spread = 30;
float spreadMult = 0.08f;
for (int i = 0; i < ShotAmt; i++)
{
float vX = speedX + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
float vY = speedY + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
Projectile.NewProjectile(position.X, position.Y, vX,vY, type, damage, knockBack, player.whoAmI);
}
return true;
}
}
}
}

As you can see is nothing special but, for me it works fine..
well, we have a difference here. What I want to adjust is the position when I holding it,not the position when I'm using it. You can add item.holdStyle = 1; to your SetDefaults(),and find the same problem as mine.
 
Huh, wth o_O what does that Player player do there.
Remove that parameter from the methode signature.
Anyway I was trying to create a gun with a flashlight attach to it. Maybe there is a way to achieve that without dealing with this holding thing?
 
Sorry it was a mistake, anyway are try to use public static void HoldStyle(Item item, Player player)?

P.S there is no public override void for PreitemCheck?
 
Sorry it was a mistake, anyway are try to use public static void HoldStyle(Item item, Player player)?
That will not work. That method belongs to ItemLoader, not ModItem.
P.S there is no public override void for PreitemCheck?
No, but there is one called PreItemCheck (Pascal casing!) that returns bool. See it here.
 
Well, what is it you need it to do?
I need to update my old weapon from Tapi but for make this i need to "override" my weapon setting item animation, time and shootspeed etc for every projectile selected with a hotkey, and for make this as i know only override PreItemCheck will work really fine. Previously i use Preshoot (for Tapi) but isn't perfect like PreItemCheck that can override without you need to shoot projectile.
 
Does anyone know how to make a weapon & Projectile glowing please ?

@Eldrazi : I summon you for help XD Do you know how to do that :D ?
 
Last edited:
Back
Top Bottom