Standalone [1.3] tModLoader - A Modding API

Am I right that NPC.downedBoss1 is Eye of Cthulhu, NPC.downedBoss2 is the Destroyer, and NPC.downedBoss3 is Skeletron?
yes
 
im just full of questions, how can i shoot 3 projectiles, in the same direction, all projectile ID 145, but with different speeds?
 
im just full of questions, how can i shoot 3 projectiles, in the same direction, all projectile ID 145, but with different speeds?
I'm too lazy to write some code, but it involves a for loop multiplying the speeds by 1f, .8f, and .6f for each projectile, respectively.
 
I'm too lazy to write some code, but it involves a for loop multiplying the speeds by 1f, .8f, and .6f for each projectile, respectively.
that is like, no help whatso ever XD but thanks for trying
 
im just full of questions, how can i shoot 3 projectiles, in the same direction, all projectile ID 145, but with different speeds?
so no one has an answer yet?
 
ask on the discord chat. You might get better assistance there
 
Its on the front page of this thread.
 
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;

namespace Pack.Projectiles
{
    public class PossessedTempliteHammerP : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Possessed Templite Hammer";
            projectile.width = 52;
            projectile.height = 52;
            projectile.friendly = true;
            projectile.penetrate = -1;
            projectile.aiStyle = 3;
            projectile.melee = true;
            projectile.tileCollide = false;
            projectile.timeLeft = 60000;
            projectile.light = 1f;
        }
        public override void OnHitNPC(NPC n, int damage, float knockback, bool crit)
        {
            Player player = Main.player[projectile.owner];
            player.statLife += 10; //Heals by 10; Can be changed of course
            player.HealEffect(10); //Shows a green 10 above your head to show you've been healed; Can be changed of course
            if (projectile.ai[1] > 0)
                projectile.ai[0] = 0;
            if (projectile.ai[0] == 0f)
            {
                projectile.velocity *= -1;
            }
            projectile.netUpdate = true;
        }
        public override void PostAI()
        {
            Main.NewText("ai[0]: " + projectile.ai[0] + ", ai[1]: " + projectile.ai[1]);
            if (projectile.ai[0] == 1)
            {
                projectile.velocity *= 2;
            }

        }
    }
}
OK, so it seems that simply multiplying the projectile's velocity was a bad idea. Replace this:
Code:
if (projectile.ai[0] == 1)
            {
                projectile.velocity *= 2;
            }
with this:
Code:
if (projectile.ai[0] == 1)
            {
                Player myOwner = Main.player[projectile.owner]; //find the owner of this projectile
                Vector2 toMe = Vector2.Normalize(myOwner.Center - projectile.Center); //find the distance from this projectile to it's owner and convert to a unit vector.
                projectile.velocity += toMe * 1f; //add the above vector to this projectile's velocity -- change 1f to change the return speed
            }
That worked for me, and I've added comments that hopefully describe what's going on.
 
Shouldn't that be Eater of Worlds instead of the Destroyer?

Doh, you're right, I got the names confused. Thanks for the correction.
 
Is there boss summoning item in Example mod?
 
Its an accessory, but I need that code for my next thing so thanks!
So does any one know how to make less amo consumption with accessory?
 
So does any one know how to make less amo consumption with accessory?
One of the harder, but more global ways is to create a variable in a ModPlayer class like so:
Code:
public class MPlayer : ModPlayer
{
    // Not too good of a naming.
    // This variable should have a value from 0 to 100. 100 being a 100% not to use ammo.
    public int ammoUsage;    

    public override void ResetEffects()
    {
        this.ammoUsage = 0;
    }
}
An then on your accessory do something like:
Code:
public override void UpdateAccessory(Player player)
{
    MPlayer mp = player.GetModPlayer<MPlayer>(mod);
    // Here we give the player a 10% chance not to consume ammo.
    mp.ammoUsage = 10;
}

Then create a class that derives from GlobalItem, override ConsumeAmmo and use the newly made variable in there:
Code:
public class GItem : GlobalItem
{
    public override bool ConsumeAmmo(Item item, Player player)
    {
        MPlayer mp = player.GetModPlayer<MPlayer>(mod);
        if(Main.rand.Next(0, 101) <= mp.ammoUsage)
            return false;
        return true;
    }
}

Something like that. This was programmed from the top of my head, so there might be a few flaws here and there, but I hope you get the general idea.
 
Hello,
I've been playing with my friend on an dedicated server with mods like thorium, tremor and stuff like that, but today the server started kicking me and my friend everytime we try to summon the destroyer and stuff like that. It's really annoying if you have a solution, please type it here :) .
 
How do I check if:
1. There is a guide alive
2. There is a spare house for the guide
3. There is a truffle alive
4. There is a spare house in the Mushroom Biome for the Truffle
 
Is there a way to change vanilla items sprites?
 
any idea how i can add dirt block to the Dryads shop? Dryad is entity ID 20, and there are currently 24 items in the dryads shop, so how can i add dirt as the 25th, i know i have to add something to GlobalNPC, but i dont know what
 
Back
Top Bottom