tModLoader Official tModLoader Help Thread

NicksMod\Npcs\FlyingDesertBug.cs(32,85) : error CS0117: 'Terraria.Main' does not contain a definition for 'ZoneDesert'
can someone help me because im really confused about this terraria main zone desert thing
help would be appreciated code is below
Code:
using Terraria.ID;
using Terraria.ModLoader;

                                                            //By Al0n37
namespace NicksMod.Npcs
{
    public class FlyingDesertBug : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Flying Desert Bug";
            npc.displayName = "Flying Desert Bug";
            npc.width = 50;
            npc.height = 50;
            npc.damage = 40;
            npc.defense = 4;
            npc.lifeMax = 80;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
            npc.aiStyle = 44;
            Main.npcFrameCount[npc.type] = 1;
            aiType = NPCID.FlyingFish;  //npc behavior
            animationType = NPCID.FlyingFish;
        }

        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            return spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && Main.ZoneDesert ? 0.5f : 0.5f; //spawn at day
        }
        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

            npc.spriteDirection = npc.direction;
           
               

           
       


        }
        public override void NPCLoot()  //Npc drop
        {
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DesertChitin"), 4); //Item spawn
            }
        }
    }
}
 
NicksMod\Npcs\FlyingDesertBug.cs(32,85) : error CS0117: 'Terraria.Main' does not contain a definition for 'ZoneDesert'
can someone help me because im really confused about this terraria main zone desert thing
help would be appreciated code is below
Code:
using Terraria.ID;
using Terraria.ModLoader;

                                                            //By Al0n37
namespace NicksMod.Npcs
{
    public class FlyingDesertBug : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Flying Desert Bug";
            npc.displayName = "Flying Desert Bug";
            npc.width = 50;
            npc.height = 50;
            npc.damage = 40;
            npc.defense = 4;
            npc.lifeMax = 80;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
            npc.aiStyle = 44;
            Main.npcFrameCount[npc.type] = 1;
            aiType = NPCID.FlyingFish;  //npc behavior
            animationType = NPCID.FlyingFish;
        }

        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            return spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && Main.ZoneDesert ? 0.5f : 0.5f; //spawn at day
        }
        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

            npc.spriteDirection = npc.direction;
          
              

          
      


        }
        public override void NPCLoot()  //Npc drop
        {
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DesertChitin"), 4); //Item spawn
            }
        }
    }
}
The error is right (as errors are always right): Main does not contain a definition for ZoneDesert. I don't know where you found this, but only the Player class has a boolean called ZoneDesert. So change Main.ZoneDesert to spawnInfo.player.ZoneDesert
 
does anyone know how to make an npc move faster?
Yes; write your own AI.
If you've using aiStyle/aiType to copy vanilla AI, you can't increase the movement speed of the NPC, since the values are hardcoded.
You could try multiplying the velocity vector of the NPC, but that might result in some... Funky effects.
 
Hi all! I am bad with coding, bad with spriting, bad with english, but it don't stop me in learning modding Terraria.

I have question - how i can create glowing projectile? Not light - it's easy. I need glowing texture and all examples what i can find - wall of code. Simple way create this effect are exist?
 
Hi all! I am bad with coding, bad with spriting, bad with english, but it don't stop me in learning modding Terraria.

I have question - how i can create glowing projectile? Not light - it's easy. I need glowing texture and all examples what i can find - wall of code. Simple way create this effect are exist?
Hey, i used some code that did it but i don't know how it did because i copied it and didn't care that it glowed, i could send you my code if you feel like looking through it to find what does it?

Edit: actually under Void AI() try adding a light code such as:

public override void AI()
{

projectile.light = 0.9f;
 
Last edited:
alright so i believe i am just stupid but my NPC that I just made doesn't spawn like it is supposed to. No errors in the code but it just doesn't spawn.
Here is my code(I currently have the spawn rate cranked up)

using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MTGMod.NPCs
{
public class Nightmare : ModNPC
{
public override void SetDefaults()
{
npc.name = "Nightmare";
npc.displayName = "Nightmare";
npc.width = 18;
npc.height = 40;
npc.damage = 14;
npc.defense = 6;
npc.lifeMax = 200;
npc.HitSound = SoundID.NPCHit10;
npc.DeathSound = SoundID.NPCDeath18;
npc.value = 97f;
npc.knockBackResist = 0.5f;
npc.aiStyle = 26;
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Unicorn];
aiType = NPCID.Unicorn;
animationType = NPCID.Unicorn;
}

public static bool SpawnNPC(int x, int y, int playerID)
{
bool surface = (y <= Main.worldSurface);

if (surface == true && !Main.dayTime && Main.rand.Next(1)==1)
{
return true;
}
else
{
return false;
}
}
public override void HitEffect(int hitDirection, double damage)
{
for (int i = 0; i < 10; i++)
{
int dustType = Main.rand.Next(139, 143);
int dustIndex = Dust.NewDust(npc.position, npc.width, npc.height, dustType);
Dust dust = Main.dust[dustIndex];
dust.velocity.X = dust.velocity.X + Main.rand.Next(-50, 51) * 0.01f;
dust.velocity.Y = dust.velocity.Y + Main.rand.Next(-50, 51) * 0.01f;
dust.scale *= 1f + Main.rand.Next(-30, 31) * 0.01f;
}
}
}
}

Any way to get my NPC naturally spawning? It will spawn in by means of a mod which allows me to spawn mobs in but it doesn't spawn naturally.
 
for some reason my npc that i made that is supposed to only spawn in desert spawns everywhere else as well
heres code
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

                                                            //By Al0n37
namespace NicksMod.Npcs
{
    public class FlyingDesertBug : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Flying Desert Bug";
            npc.displayName = "Flying Desert Bug";
            npc.width = 50;
            npc.height = 50;
            npc.damage = 50;
            npc.defense = 8;
            npc.lifeMax = 100;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 60f;
            npc.knockBackResist = 0.0f;
            npc.aiStyle = 44;
            Main.npcFrameCount[npc.type] = 1;
            aiType = NPCID.FlyingFish;  //npc behavior
            animationType = NPCID.FlyingFish;
        }

        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            return spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && spawnInfo.player.ZoneDesert
? 0.09f : 0.5f; //spawn at day
        }
        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

            npc.spriteDirection = npc.direction;
           
               

           
       


        }
        public override void NPCLoot()  //Npc drop
        {
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DesertChitin"), 3); //Item spawn
            }
        }
    }
}
 
Hey i'm getting an error and idk how to fix it
c:\Users\user\Documents\My Games\Terraria\ModLoader\Mod Sources\MTGMod\Items\Placeable\DarksteelForge.cs(32,25) : error CS0119: 'MTGMod.Items.DarksteelBar' is a 'type', which is not valid in the given context

the line of code is
recipe.AddIngredient(Items.DarksteelBar, 10);

any way to fix this.
p.s: yes this ingredient is part of my mod
 
for some reason my npc that i made that is supposed to only spawn in desert spawns everywhere else as well
heres code
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

                                                            //By Al0n37
namespace NicksMod.Npcs
{
    public class FlyingDesertBug : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Flying Desert Bug";
            npc.displayName = "Flying Desert Bug";
            npc.width = 50;
            npc.height = 50;
            npc.damage = 50;
            npc.defense = 8;
            npc.lifeMax = 100;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 60f;
            npc.knockBackResist = 0.0f;
            npc.aiStyle = 44;
            Main.npcFrameCount[npc.type] = 1;
            aiType = NPCID.FlyingFish;  //npc behavior
            animationType = NPCID.FlyingFish;
        }

        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            return spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && spawnInfo.player.ZoneDesert
? 0.09f : 0.5f; //spawn at day
        }
        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

            npc.spriteDirection = npc.direction;
         
             

         
     


        }
        public override void NPCLoot()  //Npc drop
        {
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DesertChitin"), 3); //Item spawn
            }
        }
    }
}
If you read the tModLoader wiki (which I'd highly recommend doing) you can see that any value you return in CanSpawn determines how quick your NPC is to spawn.
Now lets take a look at your spawn code:
Code:
return spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && spawnInfo.player.ZoneDesert ? 0.09f : 0.5f; //spawn at day
If this code doesn't make any sense to you, let me break it down to a simpler state. The above is the equivalent of:
Code:
if(spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && spawnInfo.player.ZoneDesert)
{
    return 0.09f;
}
else
{
    return 0.5f;
}
If you've take a look at the tModLoader wiki on GitHub, you can see that if you return 0 in this method, you stop the NPC from spawning. Thing is, what you're currently doing is quite the opposite: when the NPC spawn does not validate the first condition, you make its spawn rate higher than if it were to validate those conditions.
I think with this info you should be able to figure out what to do on your own.
I have a question, how to change the place where the projectile is created when shoting a gun?
You will want to override the Shoot method on your ModItem (your gun) and modify the position parameter.
Hey, i used some code that did it but i don't know how it did because i copied it and didn't care that it glowed, i could send you my code if you feel like looking through it to find what does it?

Edit: actually under Void AI() try adding a light code such as:

public override void AI()
{

projectile.light = 0.9f;
He did specify he did not want light, since that's easy :p
Hi all! I am bad with coding, bad with spriting, bad with english, but it don't stop me in learning modding Terraria.

I have question - how i can create glowing projectile? Not light - it's easy. I need glowing texture and all examples what i can find - wall of code. Simple way create this effect are exist?
Theory is: You have your projectile. You draw the projectile. Over the drawn projectile, you draw another texture which is your glowmap.
Problem: you will need a little wall of code.
Hey i'm getting an error and idk how to fix it
c:\Users\user\Documents\My Games\Terraria\ModLoader\Mod Sources\MTGMod\Items\Placeable\DarksteelForge.cs(32,25) : error CS0119: 'MTGMod.Items.DarksteelBar' is a 'type', which is not valid in the given context

the line of code is
recipe.AddIngredient(Items.DarksteelBar, 10);

any way to fix this.
p.s: yes this ingredient is part of my mod
There are two ways to add an Ingredient to a recipe: one for vanilla items and one for ModItems.
You're using the 'vanilla' way to add a ModItem, that's where you're going wrong.
Code:
recipe.AddIngredient(null, "DarksteelBar", 10);
Above is the correct AddIngredient call for your ModItem.
 
If you read the tModLoader wiki (which I'd highly recommend doing) you can see that any value you return in CanSpawn determines how quick your NPC is to spawn.
Now lets take a look at your spawn code:
Code:
return spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && spawnInfo.player.ZoneDesert ? 0.09f : 0.5f; //spawn at day
If this code doesn't make any sense to you, let me break it down to a simpler state. The above is the equivalent of:
Code:
if(spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime && spawnInfo.player.ZoneDesert)
{
    return 0.09f;
}
else
{
    return 0.5f;
}
If you've take a look at the tModLoader wiki on GitHub, you can see that if you return 0 in this method, you stop the NPC from spawning. Thing is, what you're currently doing is quite the opposite: when the NPC spawn does not validate the first condition, you make its spawn rate higher than if it were to validate those conditions.
I think with this info you should be able to figure out what to do on your own.

You will want to override the Shoot method on your ModItem (your gun) and modify the position parameter.

He did specify he did not want light, since that's easy :p

Theory is: You have your projectile. You draw the projectile. Over the drawn projectile, you draw another texture which is your glowmap.
Problem: you will need a little wall of code.

There are two ways to add an Ingredient to a recipe: one for vanilla items and one for ModItems.
You're using the 'vanilla' way to add a ModItem, that's where you're going wrong.
Code:
recipe.AddIngredient(null, "DarksteelBar", 10);
Above is the correct AddIngredient call for your ModItem.

thanks. also is there a special way to make a recipe require a modded tile or is it just using null again?
 
Hi, I've got a problem with my pickaxe code.


CODE:

using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace OmegaMod.Items.Tools
{
public class IcePickaxe : ModItem
{
public override void SetDefaults()
{
item.name = "Ice Pickaxe";
item.damage = 5;
item.melee = true;
item.width = 32;
item.height = 32;
item.useTime = 14;
item.useAnimation = 14;
item.pick = 45;
item.useStyle = 1;
item.knockBack = 3;
item.value = 10;
item.rare = 3;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "Icy_Bar", 8);
recipe.AddTile(18);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}





Everytime I try to build the mod, I get an error message which is like this :
c:\Users\~~~~~~\Documents\My Games\Terraria\ModLoader\Mod Sources\OmegaMod\Items\Tools\IcePickaxe.cs(23,29) : error CS0103:
The name 'SoundID' does not exist in the current context

Somone Help?
 
Hi, I've got a problem with my pickaxe code.


CODE:

using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace OmegaMod.Items.Tools
{
public class IcePickaxe : ModItem
{
public override void SetDefaults()
{
item.name = "Ice Pickaxe";
item.damage = 5;
item.melee = true;
item.width = 32;
item.height = 32;
item.useTime = 14;
item.useAnimation = 14;
item.pick = 45;
item.useStyle = 1;
item.knockBack = 3;
item.value = 10;
item.rare = 3;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "Icy_Bar", 8);
recipe.AddTile(18);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}





Everytime I try to build the mod, I get an error message which is like this :
c:\Users\~~~~~~\Documents\My Games\Terraria\ModLoader\Mod Sources\OmegaMod\Items\Tools\IcePickaxe.cs(23,29) : error CS0103:
The name 'SoundID' does not exist in the current context

Somone Help?
Add using Terraria.ID; to the top of your code.
 
I'm trying to play Terraria with my friend but it's not working.
We have different versions if tModLoader (I have v0.9.0.3, he has the most recent one)
Is this why we can't play together and how can I update mine?
 
\NicksMod\Items\DesertChitinHelmet.cs(35,37) : error CS1011: Empty character literal
NicksMod\Items\DesertChitinHelmet.cs(35,37) : error CS1010: Newline in constant
plz help me i have no idea whats going on
Heres code below
Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace NicksMod.Items
{
    public class DesertChitinHelmet : ModItem
    {
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Head);
            return true;
        }

        public override void SetDefaults()
        {
            item.name = "Desert Chitin Helmet";
            item.width = 18;
            item.height = 18;
            item.toolTip = "The tank helmet!";
            item.toolTip2 = "Prepare to not die!";
            item.value = 10000;
            item.rare = 2;
            item.defense = 7;
        }

        public override bool IsArmorSet(Item head, Item body, Item legs)
        {
            return body.type == mod.ItemType("DesertChitinChestplate") && legs.type == mod.ItemType("DesertChitinLeggings");  //put your Breastplate name and Leggings name
        }
        public override void UpdateArmorSet(Player player)
        {
            player.setBonus = "4 defence and endurance buff"; // the armor set bonus
            player.statDefense += 4;'
            player.AddBuff(BuffID.Endurance, 2);  //endurance potion buff
            player.meleeDamage += 0.04f;
            player.meleeCrit += 2;
        }
        public override void AddRecipes()  //How to craft this item
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "DesertChitin", 12);   //you need 10 Wood
            recipe.AddTile(TileID.WorkBenches);   //at work bench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
 
Back
Top Bottom