Standalone [1.3] tModLoader - A Modding API

Guys i'm in trouble.. i try to make my own mod and then i tryed to build it..but it say that TYPE EXPECTED..

EDIT: SORRY FOR THE BAD ENGLISH..I CAME FROM PHILIPPINES.. REALLY SORRY..
 
Can you give an Example Code?
For example if you wanted a vanilla boss to spawn your custom ore it's look like this:
Code:
public override void NPCLoot(NPC npc)
    {
        if(Main.netMode == 1 || WorldGen.noTileActions || WorldGen.gen)
        {
            return;
        }
        if(npc.type == 4) //$ is EoCs' NPC ID
        {
            for(double k = 0; k < (Main.maxTilesX - 200) * (Main.maxTilesY - 150 - (int)Main.rockLayer) / 5000.0; k += 1.0)
            {
                WorldGen.OreRunner(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), (ushort)mod.TileType("YourCustomOre"));
            }
        }
}

Of course if you have a mod boss that you want to spawn your ore on kill:

Code:
public override void NPCLoot()
    {
        if(Main.netMode == 1 || WorldGen.noTileActions || WorldGen.gen)
        {
            return;
        }
        if(mod.NPCType("YourModBoss"))
        {
            for(double k = 0; k < (Main.maxTilesX - 200) * (Main.maxTilesY - 150 - (int)Main.rockLayer) / 5000.0; k += 1.0)
            {
                WorldGen.OreRunner(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), (ushort)mod.TileType("YourCustomOre"));
            }
        }
}
 
For example if you wanted a vanilla boss to spawn your custom ore it's look like this:
Code:
public override void NPCLoot(NPC npc)
    {
        if(Main.netMode == 1 || WorldGen.noTileActions || WorldGen.gen)
        {
            return;
        }
        if(npc.type == 4) //$ is EoCs' NPC ID
        {
            for(double k = 0; k < (Main.maxTilesX - 200) * (Main.maxTilesY - 150 - (int)Main.rockLayer) / 5000.0; k += 1.0)
            {
                WorldGen.OreRunner(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), (ushort)mod.TileType("YourCustomOre"));
            }
        }
}

Of course if you have a mod boss that you want to spawn your ore on kill:

Code:
public override void NPCLoot()
    {
        if(Main.netMode == 1 || WorldGen.noTileActions || WorldGen.gen)
        {
            return;
        }
        if(mod.NPCType("YourModBoss"))
        {
            for(double k = 0; k < (Main.maxTilesX - 200) * (Main.maxTilesY - 150 - (int)Main.rockLayer) / 5000.0; k += 1.0)
            {
                WorldGen.OreRunner(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), (ushort)mod.TileType("YourCustomOre"));
            }
        }
}
Thanks!
 
opps.. my mistake it's c:\Users\Dewfoam\Documents\My Games\Terraria\Modloader\ModSources\CroisMod\NPCs\ModGlobalNPC.cs(4,16) : error CS0234: The type or namespace name 'Modloader' does not exist in the namespace 'Terraria' (are you missing an assembly reference?)
That's it..
 
For example if you wanted a vanilla boss to spawn your custom ore it's look like this:
Code:
public override void NPCLoot(NPC npc)
    {
        if(Main.netMode == 1 || WorldGen.noTileActions || WorldGen.gen)
        {
            return;
        }
        if(npc.type == 4) //$ is EoCs' NPC ID
        {
            for(double k = 0; k < (Main.maxTilesX - 200) * (Main.maxTilesY - 150 - (int)Main.rockLayer) / 5000.0; k += 1.0)
            {
                WorldGen.OreRunner(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), (ushort)mod.TileType("YourCustomOre"));
            }
        }
}

Of course if you have a mod boss that you want to spawn your ore on kill:

Code:
public override void NPCLoot()
    {
        if(Main.netMode == 1 || WorldGen.noTileActions || WorldGen.gen)
        {
            return;
        }
        if(mod.NPCType("YourModBoss"))
        {
            for(double k = 0; k < (Main.maxTilesX - 200) * (Main.maxTilesY - 150 - (int)Main.rockLayer) / 5000.0; k += 1.0)
            {
                WorldGen.OreRunner(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 150), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), (ushort)mod.TileType("YourCustomOre"));
            }
        }
}

how whould i make it for AnyMechBoss?
SO that if DEstoryer,Twins Or Skeletron is killed the Ore Spawnes
can i just Replace if(npc.type == 4) with
if if (NPC.downedMechBossAny == true)
?
 
how whould i make it for AnyMechBoss?
SO that if DEstoryer,Twins Or Skeletron is killed the Ore Spawnes
can i just Replace if(npc.type == 4) with
if if (NPC.downedMechBossAny == true)
?
I believe you'd put the NPC IDs of all the mech bosses in. I haven't tested out multiple NPCs though so you may have to go through trial and error if my suggestion doesn't work
 
opps.. my mistake it's c:\Users\Dewfoam\Documents\My Games\Terraria\Modloader\ModSources\CroisMod\NPCs\ModGlobalNPC.cs(4,16) : error CS0234: The type or namespace name 'Modloader' does not exist in the namespace 'Terraria' (are you missing an assembly reference?)
That's it..

It's Terraria.ModLoader. Capital L.
 
Are custom backgrounds still impossible?
I was fishing through the games code and found this: public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
Can this method be used or, as I stated, are custom backgrounds imposssible?
 
Could someone please help me. I changed the boss in the code to one of my other ones that works and it summoned, but the one I want to summon won't work could someone please find the reason in this code:

SUMMON ITEM

using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TerraMagna.Items
{
public class LightAbsorber : ModItem
{
public override void SetDefaults()
{
item.name = "Light Absorber";
item.width = 20;
item.height = 20;
item.maxStack = 50;
AddTooltip("May offend something");
item.value = 0;
item.rare = 9;
item.useAnimation = 30;
item.useTime = 30;
item.useStyle = 4;
item.consumable = false;
}
public override bool UseItem(Player player)
{
NPC.SpawnOnPlayer(player.whoAmI, mod.NPCType("ES"));
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, "MagnaIngot", 15);
recipe.AddIngredient(null, "ShipCore", 2);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

BOSS

using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TerraMagna.NPCs.Boss
{
public class ES : ModNPC
{
public override void SetDefaults()
{
npc.name = "ES";
npc.displayName = "Elumite Sphere";
npc.aiStyle = 14;
npc.lifeMax = 60000;
npc.damage = 400;
npc.defense = 350;
npc.knockBackResist = 0f;
npc.width = 100;
npc.height = 100;
animationType = NPCID.DemonEye;
Main.npcFrameCount[npc.type] = 2;
npc.value = Item.buyPrice(1, 0, 75, 40);
npc.npcSlots = 1f;
npc.boss = true;
npc.lavaImmune = true;
npc.noGravity = true;
npc.noTileCollide = true;
npc.soundHit = 8;
npc.soundKilled = 14;
npc.buffImmune[24] = true;
music = MusicID.Plantera;
npc.netAlways = true;
}
public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
{
bossHeadTexture = "TerraMagna/NPCs/Boss/ES_Head_Boss";
}
public override void BossLoot(ref string name, ref int potionType)
{
potionType = ItemID.GreaterHealingPotion;
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ElumiteIngot"), 60);
if (Main.rand.Next(10) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.AnkhCharm, 1);
}
if (Main.rand.Next(3) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.LavaCharm, 1);
}
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.579f * bossLifeScale);
npc.damage = (int)(npc.damage * 0.6f);
}
public override void AI()
{
npc.ai[0]++;
npc.ai[5]++;
Player player = Main.player[npc.target];
if (!player.active || player.dead)
{
npc.velocity = new Vector2(0f, 10f);
if (npc.timeLeft > 10)
{
npc.timeLeft = 10;
}
return;
}

npc.ai[6]++;
if (npc.ai[6] >= 200)
{
float Speed = 25f;
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 100;
int type = mod.ProjectileType("ESShot");
Main.PlaySound(23, (int)npc.position.Y, 17);
float rotation = (float)Math.Atan2(vector8.Y - (player.position.Y + (player.height * 0.5f)), vector8.X - (player.position.X + (player.width * 0.5f)));
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
npc.ai[6] = 0;
}

npc.ai[7]++;
if (npc.ai[7] >= 40)
{
float Speed = 25f;
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 60;
int type = mod.ProjectileType("ESShot");
Main.PlaySound(23, (int)npc.position.Y, 17);
float rotation = (float)Math.Atan2(vector8.Y - (player.position.Y + (player.height * 0.5f)), vector8.X - (player.position.X + (player.width * 0.5f)));
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
npc.ai[7] = 0;
}
}
}
}
 
Are custom backgrounds still impossible?
I was fishing through the games code and found this: public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
Can this method be used or, as I stated, are custom backgrounds imposssible?
Still not implemented.

npc.ai[6]++;
There are only 4 ai values for NPC. You'll need to find a different way to do whatever this code is doing.
 
Is there prefixes in this mod? I would really like to get the legendary prefix on my terrablade without going to the goblin tinkerer and hoping for the best .
 
PLEASE HELP ME.. i have error when i compile my mod..

HERE IS THE ERROR

c:\Users\Dewfoam\Documents\My Games\Terraria\ModLoader\Mod Sources\MOD\Items\Weapons\SepultchuresSword.cs(9,15) : error CS1514: { expected
 
I can't see any mods in the mod browser, i know it's beta but everyone else seems to be able to. I'm using the latest version of terraria and the latest version of tModLoader (V0.8.0.0). Any idea how i can do something about it to fix it?
 
open the cs thats named there, look at line 9 (as it states right there)
you are missing a { at line 9, it tells you right there
Thanks for the reply!!
[doublepost=1463577996,1463577892][/doublepost]
open the cs thats named there, look at line 9 (as it states right there)
you are missing a { at line 9, it tells you right there
like this??


using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

{ namespace The Well Mod.Items.Weapons //where is located
{
public class SepultchuresSword : ModItem
{
public override void SetDefaults()
{
item.name = "SepultchuresSword"; //Sword name
item.damage = 30; //Sword damage
item.melee = true; //if it's melee
item.width = 90; //Sword width
item.height = 90; //Sword height
item.toolTip = "SepultchuresSwor"; //Item Description
item.useTime = 25; //how fast
item.useAnimation = 25;
item.useStyle = 1; //Style is how this item is used, 1 is the style of the sword
item.knockBack = 5; //Sword knockback
item.value = 100;
item.rare = 10;
item.useSound = 1; //1 is the sound of the sword
item.autoReuse = true; //if it's capable of autoswing.
item.useTurn = true;
item.shoot = mod.ProjectileType("YourProjectileName");
item.shootSpeed = 8f; //projectile speed
}
public override void AddRecipes() //How to craft this sword
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1); //you need 1 DirtBlock
recipe.AddTile(TileID.WorkBenches); //at work bench
recipe.SetResult(this);
recipe.AddRecipe();

}
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
player.AddBuff(mod.BuffType("BuffName"), 400); //400 is the buff time
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(1) == 0)
{
int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("DustName"));
}
}
}
}
[doublepost=1463578108][/doublepost]not working..
 
Thanks for the reply!!
[doublepost=1463577996,1463577892][/doublepost]
like this??


using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

{ namespace The Well Mod.Items.Weapons //where is located
{
public class SepultchuresSword : ModItem
{
public override void SetDefaults()
{
item.name = "SepultchuresSword"; //Sword name
item.damage = 30; //Sword damage
item.melee = true; //if it's melee
item.width = 90; //Sword width
item.height = 90; //Sword height
item.toolTip = "SepultchuresSwor"; //Item Description
item.useTime = 25; //how fast
item.useAnimation = 25;
item.useStyle = 1; //Style is how this item is used, 1 is the style of the sword
item.knockBack = 5; //Sword knockback
item.value = 100;
item.rare = 10;
item.useSound = 1; //1 is the sound of the sword
item.autoReuse = true; //if it's capable of autoswing.
item.useTurn = true;
item.shoot = mod.ProjectileType("YourProjectileName");
item.shootSpeed = 8f; //projectile speed
}
public override void AddRecipes() //How to craft this sword
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1); //you need 1 DirtBlock
recipe.AddTile(TileID.WorkBenches); //at work bench
recipe.SetResult(this);
recipe.AddRecipe();

}
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
player.AddBuff(mod.BuffType("BuffName"), 400); //400 is the buff time
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(1) == 0)
{
int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("DustName"));
}
}
}
}

actually no, the { wasn't actually the problem it seems. this is why you post your code with your question lol, i gave the wrong answer

what is happening is actually that you have spaces in your namespace

{ namespace The Well Mod.Items.Weapons
is wrong

namespace TheWellMod.Items.Weapons
is right

you can't have spaces in the namespace like that. you will need to go through each of your CS files and correct this, im sure more errors will pop up the same

also go to INSERT and then select CODE when your posting, it looks much better than just straight posting it like that
 
Back
Top Bottom