Standalone [1.3] tModLoader - A Modding API

Thanks, that was exactely what I was looking for, so type is referred to the projectile shooted?
[doublepost=1466682849,1466682710][/doublepost]

Is there a way to change the projectile before being shoot?
It sure is. This means you can also check it against more than one type of projectile for additional effects.

And yes, to change the type of projectile being shot, you want to just set the type to the type of the projectile you want.
For example, if I always want to shoot flaming arrows, I'll just put 'type = ProjectileID.FlamingArrow;'
 
I've found a bug. Sorry for it being so long.
I was using 0.8.1.2, then upgraded to 0.8.2, but it was still the same bug.
20160623155310_1.jpg
20160623155315_1.jpg
20160623155319_1.jpg
20160623155330_1.jpg
20160623155330_1.jpg
20160623155337_1.jpg
20160623155339_1.jpg
20160623155340_1.jpg
20160623155343_1.jpg

[doublepost=1466690572,1466690449][/doublepost]
Are trees possible yet?
I think trees are possible already, but definetively very hard to code.
 
20160623161634_1.jpg

What happens on Builders Workshop...
does this happen all of the time? have you disabled mods? does this happen when you get a buff or debuff? have you tried genrating new worlds? and what OS are you running on?
it happens always. I will try without buffs in a minute.
EDIT: It still happens even without buffs. And I play on windows.
It seems to be because of my modded forge.
EDIT: this happens with EVERY Hardmode-forge in Terraria.
EDIT: even without mods on this still happens to the Adamantite and Titanium Forge.
 
Last edited:
Generated a new World.
Doesn't happen with my modded forge anymore.
Still happens with the Adamantite/Titanium Forge.
EDIT: Still happens on a new generated world and ALL mods disabled.
20160623162100_1.jpg
20160623162102_1.jpg
20160623162109_1.jpg
20160623162110_1.jpg
20160623162113_1.jpg
20160623162116_1.jpg
20160623162127_1.jpg
 
Hey! So is it possible to use OnCraft with different cases? (When you craft the pick with 1 Dirt it will set the pick power to 10%, with 2 to 20%). And also if you have already crafted it with 1 Dirt the recipe will be unavailable?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MEquipment.Pickaxe
{
    class MPickaxe : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Modular Pickaxe";
            item.damage = 0;
            item.melee = true;
            item.width = 38;
            item.height = 38;
            item.toolTip = "Serves no purpose without modules...";
            item.useTime = 10;
            item.useAnimation = 10;
            item.pick = 0;
            item.useStyle = 1;
            item.knockBack = 6;
            item.value = Item.sellPrice(0, 5, 0, 0);
            item.rare = 9;
            item.useSound = 1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            if (item.pick == 0)
            {
                ModRecipe recipe = new ModRecipe(mod);
                recipe.AddIngredient(this);
                recipe.AddIngredient(ItemID.DirtBlock);
                recipe.SetResult(this);
                recipe.AddRecipe();
                item.pick = 10;
            }

            if (item.pick == 10)
            {
                ModRecipe recipe1 = new ModRecipe(mod);
                recipe1.AddIngredient(this);
                recipe1.AddIngredient(ItemID.DirtBlock, 2);
                recipe1.SetResult(this);
                recipe1.AddRecipe();
            }
        }

        public override void OnCraft(Recipe recipe)
        {
            if (item.pick == 0) item.pick = 10;
            if (item.pick == 10) item.pick = 20;
        }
    }
}
Ok, so I managed to somehow do it, and I will share a few lines of code with you guys, so you can use it if you want :)

Code:
public override void OnCraft(Recipe recipe)
        {
            foreach (var requiredItem in recipe.requiredItem)
            {
                if (requiredItem.type == ItemID.StoneBlock)
                {
                    item.pick += 20;
                }
                else if (requiredItem.type == ItemID.Wire)
                {
                    item.pick += 50;
                }
            }
        }
 
public override void AI()
{
projectile.frameCounter++;
if (projectile.frameCounter >= 28)
{
projectile.frameCounter = 0;
float rotation = (float)(Main.rand.Next(0, 361) * (Math.PI / 180));
Vector2 velocity = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation));
int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, velocity.X, velocity.Y, ProjectileID.Bee, projectile.damage, projectile.owner, 0, 0f);
Main.projectile[proj].friendly = true;
Main.projectile[proj].hostile = false;
Main.projectile[proj].velocity *= 7f;
}


So, How do I change this (yoyo projectile code) so it shoots a custom projectile? Looking at this line here:

int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, velocity.X, velocity.Y, ProjectileID.Bee, projectile.damage, projectile.owner, 0, 0f)
 
public override void AI()
{
projectile.frameCounter++;
if (projectile.frameCounter >= 28)
{
projectile.frameCounter = 0;
float rotation = (float)(Main.rand.Next(0, 361) * (Math.PI / 180));
Vector2 velocity = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation));
int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, velocity.X, velocity.Y, ProjectileID.Bee, projectile.damage, projectile.owner, 0, 0f);
Main.projectile[proj].friendly = true;
Main.projectile[proj].hostile = false;
Main.projectile[proj].velocity *= 7f;
}


So, How do I change this (yoyo projectile code) so it shoots a custom projectile? Looking at this line here:

int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, velocity.X, velocity.Y, ProjectileID.Bee, projectile.damage, projectile.owner, 0, 0f)
You'll want to change the 'ProjectileID.Bee' part to your own projectile type (probably something with mod.ProjectileType("MyProjectile")).
 
How can I make an Item to be either crafted with an iron bar or a lead bar, like the craftinggroup method?
I don't want to add two recipes, and since crafting group method was removed, I am confused what to do.
 
How do I animate a four frame projectile
Depends on how you want to animate it.

First you'll want to set the amount of frames in the SetDefaults method of your projectile like so:
Code:
Main.projFrames[projectile.type] = 4;
And then in the AI function of your choosing animate it:
Code:
projectile.frameCounter++;
if(projectile.frameCounter >= 10)
{
    projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type];
    projectile.frameCounter = 0;
}
This will just loop the animation of the projectile. If you want to change the speed of the animation, change the '10' in the if statement.
 
Hello!
I have another question.
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace SpiritMod.Items.Other
{
    public class Mystic : ModItem
    {

        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.WoodYoyo);
            item.name = "Mystic";                     
            item.damage = 25;                           
            item.value = 100;
            item.rare = 3;
            item.knockBack = 2;
            item.channel = true;
            item.useStyle = 5;
            item.useAnimation = 25;
            item.useTime = 27;
            item.shoot = mod.ProjectileType("MysticProjectile");
            item.magic = true;
            item.mana = 30;  
            item.toolTip = "A one-of-a-kind yo-yo that uses magic!";
            item.melee = false;    
        }
    }
}
I have some code 'ere.

It is a yo yo that used mana. The issue is, It only used the mana once, when I click it. How do I make it use mana constantly, just like the last prism?
 
Hello!
I have another question.
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace SpiritMod.Items.Other
{
    public class Mystic : ModItem
    {

        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.WoodYoyo);
            item.name = "Mystic";                    
            item.damage = 25;                          
            item.value = 100;
            item.rare = 3;
            item.knockBack = 2;
            item.channel = true;
            item.useStyle = 5;
            item.useAnimation = 25;
            item.useTime = 27;
            item.shoot = mod.ProjectileType("MysticProjectile");
            item.magic = true;
            item.mana = 30; 
            item.toolTip = "A one-of-a-kind yo-yo that uses magic!";
            item.melee = false;   
        }
    }
}
I have some code 'ere.

It is a yo yo that used mana. The issue is, It only used the mana once, when I click it. How do I make it use mana constantly, just like the last prism?
For that you'll want to put some code on your ModProjectile.
In your yoyo, you'll want to do something like:
Code:
public override bool PreAI()
{
    Player player = Main.player[projectile.owner];
    if(!player.CheckMana(player.inventory[player.selectedItem].mana, true, false))
    {
        projectile.Kill(); // Or whatever you do to 'end' your projectile.
    }
    return true;
}
 
Um... How do i make it use it at a little... slower pace?
[doublepost=1466702888,1466702503][/doublepost]
For that you'll want to put some code on your ModProjectile.
In your yoyo, you'll want to do something like:
Code:
public override bool PreAI()
{
    Player player = Main.player[projectile.owner];
    if(!player.CheckMana(player.inventory[player.selectedItem].mana, true, false))
    {
        projectile.Kill(); // Or whatever you do to 'end' your projectile.
    }
    return true;
}
like uh make it wait a second between each usage?
 
Um... How do i make it use it at a little... slower pace?
[doublepost=1466702888,1466702503][/doublepost]
like uh make it wait a second between each usage?
You'll want to create a timer.
Although my advice is: lower the mana cost of the yoyo item, since it uses that mana cost. Right now it's set at 30, so...
 
You'll want to create a timer.
Although my advice is: lower the mana cost of the yoyo item, since it uses that mana cost. Right now it's set at 30, so...
You'll want to create a timer.
Although my advice is: lower the mana cost of the yoyo item, since it uses that mana cost. Right now it's set at 30, so...
I lowered it to two and it still uses it insanly fast. How exactly do i create a timer?
 
I lowered it to two and it still uses it insanly fast. How exactly do i create a timer?
The best way to do it, since you're probably using vanilla AI, is to create a variable on your projectile and make it tick:
Code:
int manaUsageTimer;
public override bool PreAI()
{
    if(manaUsageTimer++ % 10 == 0) // Uses mana every 10 frames, so 6 times a second.
    {
        Player player = Main.player[projectile.owner];
        if(!player.CheckMana(player.inventory[player.selectedItem].mana, true, false))
        {
            projectile.Kill(); // Or whatever you do to 'end' your projectile.
        }
    }
    return true;
}
 
Back
Top Bottom