Standalone [1.3] tModLoader - A Modding API

I'm kinda new at this so I do believe that there is no statements.
Allright, if that's all the code, you're missing a few things. You'll want to put the following lines at the top of your code:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
 
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items
{
public class SpecterRifle : ModItem
{
public override void SetDefaults()
{
item.name = "Specter Rifle";
item.damage = 20;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "This is a modded gun.";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 2;
item.useSound = 11;
item.autoReuse = true;
item.shoot = 10;
item.shootSpeed = 16f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}
}
}


Yeah Sorry it didnt copy correctly.
 
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items
{
public class SpecterRifle : ModItem
{
public override void SetDefaults()
{
item.name = "Specter Rifle";
item.damage = 20;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "This is a modded gun.";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 2;
item.useSound = 11;
item.autoReuse = true;
item.shoot = 10;
item.shootSpeed = 16f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}
}
}


Yeah Sorry it didnt copy correctly.
Could you copy+paste the exact errors, please?
 
Hi guys,
I'm getting these errors:
c:\Users\Warsmith\Documents\My Games\Terraria\ModLoader\Mod Sources\Terravalice\Items\KnightSwords\Save the Queen.cs(9,20) : error CS1514: { expected

c:\Users\Warsmith\Documents\My Games\Terraria\ModLoader\Mod Sources\Terravalice\Items\KnightSwords\Save the Queen.cs(9,30) : error CS1002: ; expected

c:\Users\Warsmith\Documents\My Games\Terraria\ModLoader\Mod Sources\Terravalice\Items\KnightSwords\Save the Queen.cs(10,2) : error CS1519: Invalid token '{' in class, struct, or interface member declaration

With this code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Terravalice.Items.KnightSwords
{
public class Save the Queen : ModItem
{
public override void SetDefaults()
{
item.name = "Save the Queen";
item.melee = true;
item.damage = 36;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 20;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
// Ironskin effect (protect)
public void DamageNPC (Player myPlayer, NPC npc, ref int damage, ref float knockback)
{
// Add the buff
myPlayer.AddBuff (5, 600);
}
}
}

I feel like I'm missing something obvious, but it looks ok to me...
 
Can anyone explain to me how
public virtual bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
in modProjectile works?
I'm trying to make a projectile have a damaging trail

[DOUBLEPOST=1457660346,1457660300][/DOUBLEPOST]
Hi guys,
I'm getting these errors:
c:\Users\Warsmith\Documents\My Games\Terraria\ModLoader\Mod Sources\Terravalice\Items\KnightSwords\Save the Queen.cs(9,20) : error CS1514: { expected

c:\Users\Warsmith\Documents\My Games\Terraria\ModLoader\Mod Sources\Terravalice\Items\KnightSwords\Save the Queen.cs(9,30) : error CS1002: ; expected

c:\Users\Warsmith\Documents\My Games\Terraria\ModLoader\Mod Sources\Terravalice\Items\KnightSwords\Save the Queen.cs(10,2) : error CS1519: Invalid token '{' in class, struct, or interface member declaration

With this code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Terravalice.Items.KnightSwords
{
public class Save the Queen : ModItem
{
public override void SetDefaults()
{
item.name = "Save the Queen";
item.melee = true;
item.damage = 36;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 20;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
// Ironskin effect (protect)
public void DamageNPC (Player myPlayer, NPC npc, ref int damage, ref float knockback)
{
// Add the buff
myPlayer.AddBuff (5, 600);
}
}
}

I feel like I'm missing something obvious, but it looks ok to me...
The name of your class can't have a space in it
 
Can anyone explain to me how
public virtual bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
in modProjectile works?
I'm trying to make a projectile have a damaging trail
Two rectangles are passed in, you decide if they "intersect".

Vanilla code just checks Rectangle.Intersects(Ractangle).

The projHitbox is based on projectile.width, projectile.height, projectile.position. Similar for the targetHitbox (but for an npc maybe).

Sometimes rectangles aren't perfect for what you want, such as MoonLords beam or Last Prism laser. If you made a bounding box around a laser, it would intersect with a lot of things the visuals don't show it actually hitting.

Use Collision.CheckAABBvLineCollision if you want :
public static bool CheckAABBvLineCollision(Vector2 objectPosition, Vector2 objectDimensions, Vector2 lineStart, Vector2 lineEnd, float lineWidth, ref float collisionPoint)
 
Two rectangles are passed in, you decide if they "intersect".

Vanilla code just checks Rectangle.Intersects(Ractangle).

The projHitbox is based on projectile.width, projectile.height, projectile.position. Similar for the targetHitbox (but for an npc maybe).

Sometimes rectangles aren't perfect for what you want, such as MoonLords beam or Last Prism laser. If you made a bounding box around a laser, it would intersect with a lot of things the visuals don't show it actually hitting.

Use Collision.CheckAABBvLineCollision if you want :
public static bool CheckAABBvLineCollision(Vector2 objectPosition, Vector2 objectDimensions, Vector2 lineStart, Vector2 lineEnd, float lineWidth, ref float collisionPoint)
For my projectile, having a little inaccurate rectangle collision doesn't matter.
Do you think this would work for a damaging trail?
Code:
public virtual bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
        {
            for (int i = 0; i < projectile.oldPos.Length; k++)
            {
                for (int pointX = projectile.oldPos[i].X; pointX < projectile.oldPos[i].X + projectile.width; pointX++)
                {
                    for (int pointY = projectile.oldPos[i].Y; pointY < projectile.oldPos[i].Y + projectile.height; pointY++)
                    {
                        if (targetHitbox.Contains(pointX, pointY))
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }
 
For my projectile, having a little inaccurate rectangle collision doesn't matter.
Do you think this would work for a damaging trail?
Code:
public virtual bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
        {
            for (int i = 0; i < projectile.oldPos.Length; k++)
            {
                for (int pointX = projectile.oldPos[i].X; pointX < projectile.oldPos[i].X + projectile.width; pointX++)
                {
                    for (int pointY = projectile.oldPos[i].Y; pointY < projectile.oldPos[i].Y + projectile.height; pointY++)
                    {
                        if (targetHitbox.Contains(pointX, pointY))
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }
Move the return false to the end of the method. Should work. Make sure the original non-tail hitbox is still being checked.
 
Ok, same weapon, new question.

I'm trying to get it to activate the Ironskin buff when I hit an enemy. No luck so far.

Here is the code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Terravalice.Items.KnightSwords
{
public class SavetheQueen : ModItem
{
public override void SetDefaults()
{
item.name = "Save the Queen";
item.melee = true;
item.damage = 36;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 20;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
// Ironskin effect (protect)
public override void DamageNPC (Player myPlayer, Item item, NPC npc, ref int damage, ref float knockBack)
{
// Add the buff
myPlayer.AddBuff (BuffID.Ironskin, 600);
}
}
}

I'm working on porting over old tConfig code, so that my be messing me up. =/
 
Hello, i was wondering how you would go about updating the tModLoader, if you dont need to or if there is an explanation in the description please do tell me, Thanks!

UPDATED: Nevermind i fond out hoe to update it
 
Last edited:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items.Weapons
{
public class IronWill : ModItem
{
public override void SetDefaults()
{
item.name = "Iron Will";
item.melee = true;
item.damage = 45;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 1;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Can someone actually explain what I'm doing wrong because its building the mod but i cannot get the item.
 
Ok, same weapon, new question.

I'm trying to get it to activate the Ironskin buff when I hit an enemy. No luck so far.

Here is the code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Terravalice.Items.KnightSwords
{
public class SavetheQueen : ModItem
{
public override void SetDefaults()
{
item.name = "Save the Queen";
item.melee = true;
item.damage = 36;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 20;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
// Ironskin effect (protect)
public override void DamageNPC (Player myPlayer, Item item, NPC npc, ref int damage, ref float knockBack)
{
// Add the buff
myPlayer.AddBuff (BuffID.Ironskin, 600);
}
}
}

I'm working on porting over old tConfig code, so that my be messing me up. =/

You want to override OnHitNPC instead of DamageNPC.
Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
player.AddBuff(BuffID.Ironskin, 600);
}
 
Last edited:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items.Weapons
{
public class IronWill : ModItem
{
public override void SetDefaults()
{
item.name = "Iron Will";
item.melee = true;
item.damage = 45;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 1;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Can someone actually explain what I'm doing wrong because its building the mod but i cannot get the item.
Have you enabled it's? and then reloaded mods as well?
 
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items.Weapons
{
public class IronWill : ModItem
{
public override void SetDefaults()
{
item.name = "Iron Will";
item.melee = true;
item.damage = 45;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 1;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Can someone actually explain what I'm doing wrong because its building the mod but i cannot get the item.
Are you setting autoload to true in the Mod.cs, do you have a class that extends mod?
 
Is there a way to change how the player animates when an item is used, kind of like HoldItemFrame, only called at the same time as UseStyle? I tried changing the player's frame in UseStyle, but it had no effect. Thanks.
 
Back
Top Bottom