tModLoader [Tutorial] Custom Invasion

c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\TerraZ.cs(31,2) : error CS1513: } esperada

using System;
using Microsoft.Xna.Framework;

using Terraria;
using Terraria.ModLoader;

namespace TerraZ
{
public class MMod : Mod
{
public MMod()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
};
}

//Setting music to 1 which is “Night”
public override void UpdateMusic(ref int music)
{
//Checks if the invasion is in the correct spot, if it is, then change the music
(Main.invasionX == Main.spawnTileX)
{
music = 1;

}
}
}
[doublepost=1509912380,1509912152][/doublepost]c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(26,25) : error CS0246: O nome de namespace ou o tipo 'TagCompound' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(37,35) : error CS0246: O nome de namespace ou o tipo 'TagCompound' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(44,38) : error CS0246: O nome de namespace ou o tipo 'BinaryWriter' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(52,41) : error CS0246: O nome de namespace ou o tipo 'BinaryReader' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

using System;
using System.Collections.Generic;

using Terraria;
using Terraria.ID;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace TerraZ
{
public class MWorld : ModWorld
{
//Setting up variables for invasion
public static bool customInvasionUp = false;
public static bool downedCustomInvasion = false;

//Initialize all variables to their default values
public override void Initialize()
{
Main.invasionSize = 0;
customInvasionUp = false;
downedCustomInvasion = false;
}

//Save downed data
public override TagCompound Save()
{
var downed = new List<string>();
if (downedCustomInvasion) downed.Add("ZombieInvasion");

return new TagCompound {
{"downed", downed}
};
}

//Load downed data
public override void Load(TagCompound tag)
{
var downed = tag.GetList<string>("downed");
downedCustomInvasion = downed.Contains("ZombieInvasion");
}

//Sync downed data
public override void NetSend(BinaryWriter writer)
{
BitsByte flags = new BitsByte();
flags[0] = downedCustomInvasion;
writer.Write(flags);
}

//Sync downed data
public override void NetReceive(BinaryReader reader)
{
BitsByte flags = reader.ReadByte();
downedCustomInvasion = flags[0];
}

//Allow to update invasion while game is running
public override void PostUpdate()
{
if(customInvasionUp)
{
if(Main.invasionX == (double)Main.spawnTileX)
{
//Checks progress and reports progress only if invasion at spawn
CustomInvasion.CheckCustomInvasionProgress();
}
//Updates the custom invasion while it heads to spawn point and ends it
CustomInvasion.UpdateCustomInvasion();
}
}
}
}
 
c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\TerraZ.cs(31,2) : error CS1513: } esperada

using System;
using Microsoft.Xna.Framework;

using Terraria;
using Terraria.ModLoader;

namespace TerraZ
{
public class MMod : Mod
{
public MMod()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
};
}

//Setting music to 1 which is “Night”
public override void UpdateMusic(ref int music)
{
//Checks if the invasion is in the correct spot, if it is, then change the music
(Main.invasionX == Main.spawnTileX)
{
music = 1;

}
}
}
[doublepost=1509912380,1509912152][/doublepost]c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(26,25) : error CS0246: O nome de namespace ou o tipo 'TagCompound' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(37,35) : error CS0246: O nome de namespace ou o tipo 'TagCompound' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(44,38) : error CS0246: O nome de namespace ou o tipo 'BinaryWriter' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

c:\Users\Convidado\Documents\My Games\Terraria\ModLoader\Mod Sources\TerraZ\MWorld.cs(52,41) : error CS0246: O nome de namespace ou o tipo 'BinaryReader' não pôde ser encontrado. Precisa de uma diretiva using ou de uma referência de assembly?

using System;
using System.Collections.Generic;

using Terraria;
using Terraria.ID;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace TerraZ
{
public class MWorld : ModWorld
{
//Setting up variables for invasion
public static bool customInvasionUp = false;
public static bool downedCustomInvasion = false;

//Initialize all variables to their default values
public override void Initialize()
{
Main.invasionSize = 0;
customInvasionUp = false;
downedCustomInvasion = false;
}

//Save downed data
public override TagCompound Save()
{
var downed = new List<string>();
if (downedCustomInvasion) downed.Add("ZombieInvasion");

return new TagCompound {
{"downed", downed}
};
}

//Load downed data
public override void Load(TagCompound tag)
{
var downed = tag.GetList<string>("downed");
downedCustomInvasion = downed.Contains("ZombieInvasion");
}

//Sync downed data
public override void NetSend(BinaryWriter writer)
{
BitsByte flags = new BitsByte();
flags[0] = downedCustomInvasion;
writer.Write(flags);
}

//Sync downed data
public override void NetReceive(BinaryReader reader)
{
BitsByte flags = reader.ReadByte();
downedCustomInvasion = flags[0];
}

//Allow to update invasion while game is running
public override void PostUpdate()
{
if(customInvasionUp)
{
if(Main.invasionX == (double)Main.spawnTileX)
{
//Checks progress and reports progress only if invasion at spawn
CustomInvasion.CheckCustomInvasionProgress();
}
//Updates the custom invasion while it heads to spawn point and ends it
CustomInvasion.UpdateCustomInvasion();
}
}
}
}

You need to add 'using Terraria.ModLoader.IO;' for TagCompound, and 'using System.IO;' for BinaryReader and BinaryWriter.



Now on to what I want to ask:
When I run the example in singleplayer, the invasion icon is a generic looking magic sword:
24d54634ac.png

But in multiplayer, it shows up as a Pumpkin Moon:
48bdc98ab0.png

Does anybody know how to fix this? I thought maybe it had to do with the "Main.invasionProgressIcon" variable, but that value seems to have no effect regardless of what number it's set to.
 
I figured it out after a grueling day of trial and error. This line of code:
Code:
                NetMessage.SendData(78, p.whoAmI, -1, null, Main.invasionSizeStart - Main.invasionSize, (float)Main.invasionSizeStart, (float)(Main.invasionType + 3), 0f, 0, 0, 0);
has an error, instead of Main.invasionType + 3 it should just be Main.invasionType:
Code:
                NetMessage.SendData(78, p.whoAmI, -1, null, Main.invasionSizeStart - Main.invasionSize, (float)Main.invasionSizeStart, (float)(Main.invasionType), 0f, 0, 0, 0);

Main.invasionType is -1 in the example code, and invasionType 2 is a pumpkin moon.
 
How would I make a invasion spawner for a vanilla invasion?

In my case, I want to make a slime rain spawner.
 
hey sin costan, the skeleton banner is an item and it says "The dungeon beckons you..." but nothing happens. I've tried to cause an error log, but there aren't even warnings. the code is a bit advanced for me so I have no idea how to fix. can you help plz?

I have that error too
 
I need help with my invasion which involves modded NPCs.

Here's the code:
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Localization;

namespace TurquoiseStuff
{
public class PumpkinLegion
{

public static int[] invaders = {
mod.NPCType("PumpFloater"),
mod.NPCType("PumpkinMagus"),
mod.NPCType("HeadlessWarrior"),
mod.NPCType("WalkingPumpkin")

};

public static void StartPumpkinLegion()
{
if (Main.invasionType != 0 && Main.invasionSize == 0)
{
Main.invasionType = 0;
}

if (Main.invasionType == 0)
{
int numPlayers = 0;
for (int i = 0; i < 255; i++)
{
if (Main.player.active && Main.player.statLifeMax >= 200)
{
numPlayers++;
}
}

if (numPlayers > 0)
{
Main.invasionType = -1;
TurquoiseWorld.pumpkinLegionUp = true;
Main.invasionSize = 100 * numPlayers;
Main.invasionSizeStart = Main.invasionSize;
Main.invasionProgress = 0;
Main.invasionProgressIcon = 0 + 3;
Main.invasionProgressWave = 0;
Main.invasionProgressMax = Main.invasionSizeStart;
Main.invasionWarn = 3600;
if (Main.rand.Next(2) == 0)
{
Main.invasionX = 0.0;
return;
}
Main.invasionX = (double)Main.maxTilesX;
}
}
}

public static void PumpkinLegionWarning()
{
String text = "";
if (Main.invasionX == (double)Main.spawnTileX)
{
text = "The Pumpkin Legion has arrived!";
}
if (Main.invasionSize <= 0)
{
text = "The Pumpkin Legion has retreated.";
}
if (Main.netMode == 0)
{
Main.NewText(text, 175, 75, 255, false);
return;
}
if (Main.netMode == 2)
{
NetMessage.SendData(25, -1, -1, NetworkText.FromLiteral(text), 255, 175f, 75f, 255f, 0, 0, 0);
}
}

public static void UpdatePumpkinLegion()
{
if (TurquoiseWorld.pumpkinLegionUp)
{

if(Main.invasionSize <= 0)
{
TurquoiseWorld.pumpkinLegionUp = false;
PumpkinLegionWarning();
Main.invasionType = 0;
Main.invasionDelay = 0;
}

if (Main.invasionX == (double)Main.spawnTileX)
{
return;
}

float moveRate = (float)Main.dayRate;

if (Main.invasionX > (double)Main.spawnTileX)
{
Main.invasionX -= (double)moveRate;

if (Main.invasionX <= (double)Main.spawnTileX)
{
Main.invasionX = (double)Main.spawnTileX;
PumpkinLegionWarning();
}
else
{
Main.invasionWarn--;
}
}
else
{

if (Main.invasionX < (double)Main.spawnTileX)
{
Main.invasionX += (double)moveRate;

if (Main.invasionX >= (double)Main.spawnTileX)
{
Main.invasionX = (double)Main.spawnTileX;
PumpkinLegionWarning();
}
else
{
Main.invasionWarn--;
}
}
}
}
}
public static void CheckPumpkinLegionProgress()
{
if (Main.invasionProgressMode != 2)
{
Main.invasionProgressNearInvasion = false;
return;
}

bool flag = false;
Player player = Main.player[Main.myPlayer];
Rectangle rectangle = new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight);
int num = 5000;
int icon = 3;
for (int i = 0; i < 200; i++)
{
if (Main.npc.active)
{
icon = 3;
int type = Main.npc.type;
for(int n = 0; n < invaders.Length; n++)
{
if(type == invaders[n])
{
Rectangle value = new Rectangle((int)(Main.npc.position.X + (float)(Main.npc.width / 2)) - num, (int)(Main.npc.position.Y + (float)(Main.npc.height / 2)) - num, num * 2, num * 2);
if (rectangle.Intersects(value))
{
flag = true;
break;
}
}
}
}
}
Main.invasionProgressNearInvasion = flag;
int progressMax3 = 1;

if(TurquoiseWorld.pumpkinLegionUp)
{
progressMax3 = Main.invasionSizeStart;
}

if(TurquoiseWorld.pumpkinLegionUp && (Main.invasionX == (double)Main.spawnTileX))
{
Main.ReportInvasionProgress(Main.invasionSizeStart - Main.invasionSize, progressMax3, icon, 0);
}

foreach(Player p in Main.player)
{
NetMessage.SendData(78, p.whoAmI, -1, null, Main.invasionSizeStart - Main.invasionSize, (float)Main.invasionSizeStart, (float)(Main.invasionType + 3), 0f, 0, 0, 0);
}
}
}
}


And here's the error:

Mod Sources\TurquoiseStuff\PumpkinLegion.cs(17,4) : error CS0103: The name 'mod' does not exist in the current context
 
Incredibly helpful mod, thank you, as of the time of posting this the mod works just fine with tModLoader. Just place the unzipped folder (with the files inside of it) into your "Terraria > ModLoader > ModSources" folder and then while in-game at the main menu goto: "ModSources" and select build + load on the invasion mod.
 
I am having problem with the invasion it says: "make sure you have exactly one class extending mod" what does that mean
 
I need help with my invasion which involves modded NPCs.

Here's the code:
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Localization;

namespace TurquoiseStuff
{
public class PumpkinLegion
{

public static int[] invaders = {
mod.NPCType("PumpFloater"),
mod.NPCType("PumpkinMagus"),
mod.NPCType("HeadlessWarrior"),
mod.NPCType("WalkingPumpkin")

};

public static void StartPumpkinLegion()
{
if (Main.invasionType != 0 && Main.invasionSize == 0)
{
Main.invasionType = 0;
}

if (Main.invasionType == 0)
{
int numPlayers = 0;
for (int i = 0; i < 255; i++)
{
if (Main.player.active && Main.player.statLifeMax >= 200)
{
numPlayers++;
}
}

if (numPlayers > 0)
{
Main.invasionType = -1;
TurquoiseWorld.pumpkinLegionUp = true;
Main.invasionSize = 100 * numPlayers;
Main.invasionSizeStart = Main.invasionSize;
Main.invasionProgress = 0;
Main.invasionProgressIcon = 0 + 3;
Main.invasionProgressWave = 0;
Main.invasionProgressMax = Main.invasionSizeStart;
Main.invasionWarn = 3600;
if (Main.rand.Next(2) == 0)
{
Main.invasionX = 0.0;
return;
}
Main.invasionX = (double)Main.maxTilesX;
}
}
}

public static void PumpkinLegionWarning()
{
String text = "";
if (Main.invasionX == (double)Main.spawnTileX)
{
text = "The Pumpkin Legion has arrived!";
}
if (Main.invasionSize <= 0)
{
text = "The Pumpkin Legion has retreated.";
}
if (Main.netMode == 0)
{
Main.NewText(text, 175, 75, 255, false);
return;
}
if (Main.netMode == 2)
{
NetMessage.SendData(25, -1, -1, NetworkText.FromLiteral(text), 255, 175f, 75f, 255f, 0, 0, 0);
}
}

public static void UpdatePumpkinLegion()
{
if (TurquoiseWorld.pumpkinLegionUp)
{

if(Main.invasionSize <= 0)
{
TurquoiseWorld.pumpkinLegionUp = false;
PumpkinLegionWarning();
Main.invasionType = 0;
Main.invasionDelay = 0;
}

if (Main.invasionX == (double)Main.spawnTileX)
{
return;
}

float moveRate = (float)Main.dayRate;

if (Main.invasionX > (double)Main.spawnTileX)
{
Main.invasionX -= (double)moveRate;

if (Main.invasionX <= (double)Main.spawnTileX)
{
Main.invasionX = (double)Main.spawnTileX;
PumpkinLegionWarning();
}
else
{
Main.invasionWarn--;
}
}
else
{

if (Main.invasionX < (double)Main.spawnTileX)
{
Main.invasionX += (double)moveRate;

if (Main.invasionX >= (double)Main.spawnTileX)
{
Main.invasionX = (double)Main.spawnTileX;
PumpkinLegionWarning();
}
else
{
Main.invasionWarn--;
}
}
}
}
}
public static void CheckPumpkinLegionProgress()
{
if (Main.invasionProgressMode != 2)
{
Main.invasionProgressNearInvasion = false;
return;
}

bool flag = false;
Player player = Main.player[Main.myPlayer];
Rectangle rectangle = new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight);
int num = 5000;
int icon = 3;
for (int i = 0; i < 200; i++)
{
if (Main.npc.active)
{
icon = 3;
int type = Main.npc.type;
for(int n = 0; n < invaders.Length; n++)
{
if(type == invaders[n])
{
Rectangle value = new Rectangle((int)(Main.npc.position.X + (float)(Main.npc.width / 2)) - num, (int)(Main.npc.position.Y + (float)(Main.npc.height / 2)) - num, num * 2, num * 2);
if (rectangle.Intersects(value))
{
flag = true;
break;
}
}
}
}
}
Main.invasionProgressNearInvasion = flag;
int progressMax3 = 1;

if(TurquoiseWorld.pumpkinLegionUp)
{
progressMax3 = Main.invasionSizeStart;
}

if(TurquoiseWorld.pumpkinLegionUp && (Main.invasionX == (double)Main.spawnTileX))
{
Main.ReportInvasionProgress(Main.invasionSizeStart - Main.invasionSize, progressMax3, icon, 0);
}

foreach(Player p in Main.player)
{
NetMessage.SendData(78, p.whoAmI, -1, null, Main.invasionSizeStart - Main.invasionSize, (float)Main.invasionSizeStart, (float)(Main.invasionType + 3), 0f, 0, 0, 0);
}
}
}
}

And here's the error:

Mod Sources\TurquoiseStuff\PumpkinLegion.cs(17,4) : error CS0103: The name 'mod' does not exist in the current context
easy just make the M's capital or you need to put: Using [name of mod].[name of npcs folder].[anymore folders your enemys are in]
 
easy just make the M's capital or you need to put: Using [name of mod].[name of npcs folder].[anymore folders your enemys are in]

ModLoader.GetMod("YourModeName").NPCType.("NPCName")
[doublepost=1564677201,1564677147][/doublepost]Does anyone know why my invasion music is playing infinitely? Even when the invasion has already ended. It's just a normal Terraria theme not a custom one.
 
For some reason, everything in the invasion works except for the most important part, spawning mobs. I even used cheat sheet and set the spawn rate to 30 but to no avail. Am I missing something?
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

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

namespace NewJourney
{
    public class NewJourneyNPC : GlobalNPC
    {
        //Change the spawn pool
        public override void EditSpawnPool(IDictionary< int, float > pool, NPCSpawnInfo spawnInfo)
        {
            if(Modworld.jungleInvasionUp)
            {
                //Clear pool so that only the stuff you want spawns
                pool.Clear();
        if(NPC.downedQueenBee) {
  
                //key = NPC ID | value = spawn weight
                //pool.add(key, value)

                    foreach(int i in JungleInvasion.PreHardmodeInvaders)
                    {
                        pool.Add(i, 1f); //Add it to the pool with the same weight of 1
                    }
        }
        if(NPC.downedPlantBoss) {

                    foreach(int i in JungleInvasion.HardmodeInvaders)
                    {
                        pool.Add(i, 1f); //Add it to the pool with the same weight of 1
                    }

                    foreach(int i in JungleInvasion.PreHardmodeInvaders)
                    {
                        pool.Add(i, 1f); //Add it to the pool with the same weight of 1
                    }
        }
        if(NPC.downedMoonlord) {

                    foreach(int i in JungleInvasion.MoonlordInvaders)
                    {
                        pool.Add(i, 1f); //Add it to the pool with the same weight of 1
                    }

                    foreach(int i in JungleInvasion.HardmodeInvaders)
                    {
                        pool.Add(i, 1f); //Add it to the pool with the same weight of 1
                    }

                    foreach(int i in JungleInvasion.PreHardmodeInvaders)
                    {
                        pool.Add(i, 1f); //Add it to the pool with the same weight of 1
                    }
        }
            }
        }

        public override void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
        {
            //Change spawn stuff if invasion up and invasion at spawn
            if(Modworld.jungleInvasionUp)
            {
                spawnRate = 50; //Higher the number, the more spawns
                maxSpawns = 100; //Max spawns of NPCs depending on NPC value
            }
        }

        public override void PostAI(NPC npc)
        {
            //Changes NPCs so they do not despawn when invasion up and invasion at spawn
            if(Modworld.jungleInvasionUp)
            {
                npc.timeLeft = 1000;
            }
        }

        public override void NPCLoot(NPC npc)
        {
            if(Modworld.jungleInvasionUp && NPC.downedQueenBee)
            {
                foreach(int invader in JungleInvasion.PreHardmodeInvaders)
                {
                    if(npc.type == invader)
                    {
                        Main.invasionSize -= 1;
                    }
                }
            }
            if(Modworld.jungleInvasionUp && Main.hardMode && NPC.downedPlantBoss)
            {
                foreach(int invader in JungleInvasion.HardmodeInvaders)
                {
                    //If npc type equal to invader's ID decrement size to progress invasion
                    if(npc.type == invader)
                    {
                        Main.invasionSize -= 1;
                    }
                }
            }
            if(Modworld.jungleInvasionUp && Main.hardMode && NPC.downedMoonlord)
            {
                foreach(int invader in JungleInvasion.HardmodeInvaders)
                {
                    //If npc type equal to invader's ID decrement size to progress invasion
                    if(npc.type == invader)
                    {
                        Main.invasionSize -= 1;
                    }
                }
            }
        }
    }
}
 
Back
Top Bottom