Standalone [1.3] tModLoader - A Modding API

Here's the code for a heat ray projectile

Code:
        public override void AI()
        {
            projectile.localAI[0] += 1f; //Increase counter by 1
            if (projectile.localAI[0] > 3f)  //by 3rd count, activate beam
            {
                for (int num562 = 0; num562 < 3; num562++)
                {
                    projectile.alpha = 255; //makes projectile invisible
                    int num563 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y - projectile.height/4), projectile.width + 4, projectile.height + 4, 15, 0f, 0f, 0, default(Color), 0.75f); //Dust for laser beam
                    Main.dust[num563].scale = (float)Main.rand.Next(70, 110) * 0.013f; //Randomizes scale of the dust
                    Main.dust[num563].velocity *= 0.2f;  //how fast dust goes
                    Main.dust[num563].noGravity = true;  //makes dust float
                }
            }
        }
Thanks, but what about the damage?
 
Why do my players keep getting corrupted? Their .bak files keep getting moved to the Recycle Bin, and when I put them back, they get deleted again.
Capture.PNG
 
Change the AI to bullet
Thanks.
[DOUBLEPOST=1453855832,1453855771][/DOUBLEPOST]
Why do my players keep getting corrupted? Their .bak files keep getting moved to the Recycle Bin, and when I put them back, they get deleted again.
View attachment 94201
That happened to me too and I lost TONS of progress. I don't know why it does that. I guess just back up your players until a fix for it is found.
 
Thanks.
[DOUBLEPOST=1453855832,1453855771][/DOUBLEPOST]
That happened to me too and I lost TONS of progress. I don't know why it does that. I guess just back up your players until a fix for it is found.
Sometimes moving the player files somewhere else and moving back works.
 
How do I do that?

This is the rotation code for a projectile pointing up, you can stick this in the AI hook.

Code:
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;

For Terrablade like projectiles (projectiles pointing top right), stick this thing in instead.

Code:
projectile.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 0.785f;

And for spears projectiles (projectiles pointing top left), stick this thing in instead.

Code:
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2.355f;
            if (projectile.spriteDirection == -1)
            {
                projectile.rotation -= 1.57f;
            }

If curved to the right and a sword looking like a saber pointing top right, stick this in the AI instead.

Code:
projectile.rotation += (float)this.direction * 0.4f;
projectile.spriteDirection = this.direction;
 
This is the rotation code for a projectile pointing up, you can stick this in the AI hook.

Code:
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;

For Terrablade like projectiles (projectiles pointing top right), stick this thing in instead.

Code:
projectile.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 0.785f;

And for spears projectiles (projectiles pointing top left), stick this thing in instead.

Code:
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2.355f;
            if (projectile.spriteDirection == -1)
            {
                projectile.rotation -= 1.57f;
            }

If curved to the right and a sword looking like a saber pointing top right, stick this in the AI instead.

Code:
projectile.rotation += (float)this.direction * 0.4f;
projectile.spriteDirection = this.direction;
Thanks so much! :D
 
How do I make a NPC summon monsters?
[DOUBLEPOST=1453862776,1453862370][/DOUBLEPOST]and also, how do I create a pet? its for a boss drop, but im too confused with the code. The pet is called DronePet
 
How do i get a pet without the examplePlayer stuff?
[DOUBLEPOST=1453865891,1453865310][/DOUBLEPOST]nevermind about my last question, I just wont do the pet. What I really need to know is how do you only make a certain item drop at a certain rate? like duke fishron only drops one of the several items. I kinda want that kinda thing.
 
How do i get a pet without the examplePlayer stuff?
[DOUBLEPOST=1453865891,1453865310][/DOUBLEPOST]nevermind about my last question, I just wont do the pet. What I really need to know is how do you only make a certain item drop at a certain rate? like duke fishron only drops one of the several items. I kinda want that kinda thing.
Um, just delete all the stuff not related to ExamplePet. ResetEffects should be the only method left.
[DOUBLEPOST=1453866327][/DOUBLEPOST]
How do i get a pet without the examplePlayer stuff?
[DOUBLEPOST=1453865891,1453865310][/DOUBLEPOST]nevermind about my last question, I just wont do the pet. What I really need to know is how do you only make a certain item drop at a certain rate? like duke fishron only drops one of the several items. I kinda want that kinda thing.
Make a random number between 0 and X, if 0 drop A, if 1 drop B, if 2 drop C, ....etc.
 
Um, just delete all the stuff not related to ExamplePet. ResetEffects should be the only method left.
[DOUBLEPOST=1453866327][/DOUBLEPOST]
Make a random number between 0 and X, if 0 drop A, if 1 drop B, if 2 drop C, ....etc.
I only know how to make a RNG with AI..
Code:
            npc.ai[0]++;   
            if (npc.ai[0] > 5)
                if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
                    {
                        Vector2 direction = Main.player[npc.target].Center - npc.Center;
                        direction.Normalize();
                        int rand = Main.rand.Next(0, 4);
                        if(rand == 0)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 10f, mod.ProjectileType("CodexVolt"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else if(rand == 1)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 30f, mod.ProjectileType("Laser"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else if(rand == 2)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 35f, mod.ProjectileType("Laser2"), 10, 1, Main.myPlayer, 0, 0);
                    }
                        npc.ai[0] = 0;
                    }
 
How can I make it to where an NPC will only spawn if I have a certain type of item? For example, I want my Mask Salesman to only spawn if you have any mask in your inventory.
 
If you have a target for the NPC, you can do something like the following in one of your AI methods:
Code:
if(Main.player[npc.target].dead)
    npc.Kill();

There was someone talking about a video tutorial a while ago (a pretty long while ago).
Right now there's not really a video tutorial. There are, however, threads and info that should get you started (the links for those are in the OP).
Other than that: tModLoader programming is done in C#. Hope this helps ;)

But i have not got custom ai :(
[DOUBLEPOST=1453889616,1453889265][/DOUBLEPOST]Can someone give me code to summoning item pls because my summoning item spawns 8 bosses D:
[DOUBLEPOST=1453889641][/DOUBLEPOST]And don't uses itself.
[DOUBLEPOST=1453889711][/DOUBLEPOST]This is my code

using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace GetsuuPower.Items
{
public class IceShard : ModItem
{
public override void SetDefaults()
{
item.name = "IceShard";
item.width = 20;
item.height = 20;
item.maxStack = 20;
item.toolTip = "Summons The ???.";
item.rare = 9;
item.useAnimation = 45;
item.useTime = 45;
item.useStyle = 4;
item.useSound = 44;
item.consumable = true;
}


public override bool UseItem(Player player)
{
NPC.SpawnOnPlayer(player.whoAmI, mod.NPCType("BlackHand"));
Main.PlaySound(15, (int)player.position.X, (int)player.position.Y, 0);
return true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "CthulhuEssence", 20);
recipe.AddTile(18);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
But i have not got custom ai :(
[DOUBLEPOST=1453889616,1453889265][/DOUBLEPOST]Can someone give me code to summoning item pls because my summoning item spawns 8 bosses D:
[DOUBLEPOST=1453889641][/DOUBLEPOST]And don't uses itself.
[DOUBLEPOST=1453889711][/DOUBLEPOST]This is my code

using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace GetsuuPower.Items
{
public class IceShard : ModItem
{
public override void SetDefaults()
{
item.name = "IceShard";
item.width = 20;
item.height = 20;
item.maxStack = 20;
item.toolTip = "Summons The ???.";
item.rare = 9;
item.useAnimation = 45;
item.useTime = 45;
item.useStyle = 4;
item.useSound = 44;
item.consumable = true;
}


public override bool UseItem(Player player)
{
NPC.SpawnOnPlayer(player.whoAmI, mod.NPCType("BlackHand"));
Main.PlaySound(15, (int)player.position.X, (int)player.position.Y, 0);
return true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "CthulhuEssence", 20);
recipe.AddTile(18);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Then make an ai. I don't see the problem.
Also, when you have more to add to your post, try using the edit button instead of double posting.
 
Back
Top Bottom