tModLoader Town NPC Error

jon meme

Eye of Cthulhu
c:\Users\JA\Documents\My Games\Terraria\ModLoader\Mod Sources\InfiniumMod\NPCs\NPCTown.cs(13,30) : error CS0115: 'InfiniumMod.NPCs.NPCTown.Autoload(ref string, ref string)': no suitable method found to override

I have NO idea how to fix it.

Code for NPC:
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace InfiniumMod.NPCs
{
    public class NPCTown : ModNPC
    {
        public override bool Autoload(ref string name, ref string texture)
        {
            name = "NPCTown";
            return mod.Properties.Autoload;
        }
        public override void SetDefaults()
        {
            npc.name = "Cool NPC";
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 40;
            npc.aiStyle = 7;
            npc.damage = 10;
            npc.defense = 15;
            npc.lifeMax = 250;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.knockBackResist = 0.5f;
            Main.npcFrameCount[npc.type] = 25;           
            animationType = NPCID.Guide;
        }
        public override bool CanTownNPCSpawn(int numTownNPCs, int money)
        {
           
            return false;// this make that he will spawn when a house is available
        }



        public override string TownNPCName()
        {                                        //NPC names
            switch (WorldGen.genRand.Next(4))
            {
                case 0:
                    return "Blue";
                case 1:
                    return "Blu";
                case 2:
                    return "Azul";
                default:
                    return "Bleu";
            }
        }




        public override string GetChat()
        {                                             //npc chat
         
            switch (Main.rand.Next(3))
            {
                case 0:
                    return "Kappa";
                case 1:
                    return "I'm Blue Da Ba Dee Da Ba Die.";
                default:
                    return "Hello!";
            }
        }

        public override void SetChatButtons(ref string button, ref string button2)
        {
            button = Lang.inter[28];
        }

        public override void OnChatButtonClicked(bool firstButton, ref bool shop)
        {
            if (firstButton)
            {
                shop = true;
            }
        }

        public override void SetupShop(Chest shop, ref int nextSlot)
        {
            shop.item[nextSlot].SetDefaults(mod.ItemType("AxeName")); //items that he sells
            nextSlot++;
            shop.item[nextSlot].SetDefaults(mod.ItemType("YourSword"));
            nextSlot++;
            shop.item[nextSlot].SetDefaults (ItemID.LunarBar);
            nextSlot++;
        }

    }
}
 
c:\Users\JA\Documents\My Games\Terraria\ModLoader\Mod Sources\InfiniumMod\NPCs\NPCTown.cs(13,30) : error CS0115: 'InfiniumMod.NPCs.NPCTown.Autoload(ref string, ref string)': no suitable method found to override

I have NO idea how to fix it.

Code for NPC:
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace InfiniumMod.NPCs
{
    public class NPCTown : ModNPC
    {
        public override bool Autoload(ref string name, ref string texture)
        {
            name = "NPCTown";
            return mod.Properties.Autoload;
        }
        public override void SetDefaults()
        {
            npc.name = "Cool NPC";
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 40;
            npc.aiStyle = 7;
            npc.damage = 10;
            npc.defense = 15;
            npc.lifeMax = 250;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.knockBackResist = 0.5f;
            Main.npcFrameCount[npc.type] = 25;          
            animationType = NPCID.Guide;
        }
        public override bool CanTownNPCSpawn(int numTownNPCs, int money)
        {
          
            return false;// this make that he will spawn when a house is available
        }



        public override string TownNPCName()
        {                                        //NPC names
            switch (WorldGen.genRand.Next(4))
            {
                case 0:
                    return "Blue";
                case 1:
                    return "Blu";
                case 2:
                    return "Azul";
                default:
                    return "Bleu";
            }
        }




        public override string GetChat()
        {                                             //npc chat
        
            switch (Main.rand.Next(3))
            {
                case 0:
                    return "Kappa";
                case 1:
                    return "I'm Blue Da Ba Dee Da Ba Die.";
                default:
                    return "Hello!";
            }
        }

        public override void SetChatButtons(ref string button, ref string button2)
        {
            button = Lang.inter[28];
        }

        public override void OnChatButtonClicked(bool firstButton, ref bool shop)
        {
            if (firstButton)
            {
                shop = true;
            }
        }

        public override void SetupShop(Chest shop, ref int nextSlot)
        {
            shop.item[nextSlot].SetDefaults(mod.ItemType("AxeName")); //items that he sells
            nextSlot++;
            shop.item[nextSlot].SetDefaults(mod.ItemType("YourSword"));
            nextSlot++;
            shop.item[nextSlot].SetDefaults (ItemID.LunarBar);
            nextSlot++;
        }

    }
}
Just delete
public override bool Autoload(ref string name, ref string texture)
{
name = "NPCTown";
return mod.Properties.Autoload;
}
 
Just delete
public override bool Autoload(ref string name, ref string texture)
{
name = "NPCTown";
return mod.Properties.Autoload;
}
It worked. Thanks!
Also I noticed on one of your thread that you're good at making randomly generated structures. How do I do this?
 
It worked. Thanks!
Also I noticed on one of your thread that you're good at making randomly generated structures. How do I do this?
Well you need to make a file for the structure; its more complicated than you might think but heres a start
 

Attachments

  • Starter Well.txt
    5.1 KB · Views: 308
It worked. Thanks!
Also I noticed on one of your thread that you're good at making randomly generated structures. How do I do this?

I have the same error but no matter what i do, it just wont work. Ive been experimenting with the code, searching everywhere i would and trying to find the exact way to fix it but sofar no luck...
 
Um guys im not the best modder/spriter or Coder around and i cant seem to fix this each thing i do to try fix this another gets added so can you please help

the error is

c:\Users\N\Documents\My Games\Terraria\ModLoader\Mod Sources\CustomNpcs\Rey.cs(103,135) : error CS1010: Newline in constant

c:\Users\N\Documents\My Games\Terraria\ModLoader\Mod Sources\CustomNpcs\Rey.cs(108,87) : error CS1010: Newline in constant

c:\Users\N\Documents\My Games\Terraria\ModLoader\Mod Sources\CustomNpcs\Rey.cs(108,87) : error CS1012: Too many characters in character literal

and the codes

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria;
using Terraria.ModLoader;

namespace CustomNpcs //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
public class ReytheHero : ModNpc
{
public override bool Autoload(ref string name, ref string texture, ref string[] altTextures)
{
name = "ReyTheHero";
return mod.Properties.Autoload;
}
public override void SetDefaults()
{
npc.name = "Rey"; //the name displayed when hovering over the npc ingame.
npc.townNPC = true; //This defines if the npc is a town Npc or not
npc.friendly = true; //this defines if the npc can hur you or not()
npc.width = 18; //the npc sprite width
npc.height = 46; //the npc sprite height
npc.aiStyle = 7; //this is the npc ai style, 7 is Pasive Ai
npc.defense = 100; //the npc defense
npc.lifeMax = 500;// the npc life
npc.HitSound = SoundID.NPCHit1; //the npc sound when is hit
npc.DeathSound = SoundID.NPCDeath1; //the npc sound when he dies
npc.knockBackResist = 0.5f; //the npc knockback resistance
Main.npcFrameCount[npc.type] = 25; //this defines how many frames the npc sprite sheet has
NPCID.Sets.ExtraFramesCount[npc.type] = 9;
NPCID.Sets.AttackFrameCount[npc.type] = 4;
NPCID.Sets.DangerDetectRange[npc.type] = 150; //this defines the npc danger detect range
NPCID.Sets.AttackType[npc.type] = 3; //this is the attack type, 0 (throwing), 1 (shooting), or 2 (magic). 3 (melee)
NPCID.Sets.AttackTime[npc.type] = 10; //this defines the npc attack speed
NPCID.Sets.AttackAverageChance[npc.type] = 10;//this defines the npc atack chance
NPCID.Sets.HatOffsetY[npc.type] = 4; //this defines the party hat position
animationType = NPCID.Dryad; //this copy the Steampunker animation
}
public override bool CanTownNPCSpawn(int numTownNPCs, int money) //Whether or not the conditions have been met for this town NPC to be able to move into town.
{
if (NPC.downedBoss1) //so after the EoC is killed
{
return true;
}
return false;
}
public override bool CheckConditions(int left, int right, int top, int bottom) //Allows you to define special conditions required for this town NPC's house
{
return true; //so when a house is available the npc will spawn
}
public override string TownNPCName() //Allows you to give this town NPC any name when it spawns
{
switch (WorldGen.genRand.Next(6))
{
case 0:
return "Rey";

}
}

public override void SetChatButtons(ref string button, ref string button2) //Allows you to set the text for the buttons that appear on this town NPC's chat window.
{
button = "Buy Gear"; //this defines the buy button name
}
public override void OnChatButtonClicked(bool firstButton, ref bool openShop) //Allows you to make something happen whenever a button is clicked on this town NPC's chat window. The firstButton parameter tells whether the first button or second button (button and button2 from SetChatButtons) was clicked. Set the shop parameter to true to open this NPC's shop.
{

if (firstButton)
{
openShop = true; //so when you click on buy button opens the shop
}
}

public override void SetupShop(Chest shop, ref int nextSlot) //Allows you to add items to this town NPC's shop. Add an item by setting the defaults of shop.item[nextSlot] then incrementing nextSlot.
{
if (NPC.downedSlimeKing) //this make so when the king slime is killed the town npc will sell this
{
shop.item[nextSlot].SetDefaults(ItemID.RecallPotion); //an example of how to add a vanilla terraria item
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.WormholePotion);
nextSlot++;
}
if (NPC.downedBoss3) //this make so when Skeletron is killed the town npc will sell this
{
shop.item[nextSlot].SetDefaults(ItemID.BookofSkulls);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.ClothierVoodooDoll);
nextSlot++;
}
shop.item[nextSlot].SetDefaults(ItemID.IronskinPotion);
nextSlot++;


}

public override string GetChat() //Allows you to give this town NPC a chat message when a player talks to it.
{
int wizardNPC = NPC.FindFirstNPC(NPCID.Wizard); //this make so when this npc is close to Wizard
if (wizardNPC >= 0 && Main.rand.Next(4) == 0) //has 1 in 3 chance to show this message
{
return " Main.npc[MerchantNPC].displayName + "keeps trying to sell me angel statues who in there right mind buys them?";
}
int guideNPC = NPC.FindFirstNPC(NPCID.Guide); //this make so when this npc is close to the Guide
if (guideNPC >= 0 && Main.rand.Next(4) == 0) //has 1 in 3 chance to show this message
{
return " Main.npc[guideNPC].displayName + " seems incredibly fidgety i'll keep an eye on him for you.";
}
switch (Main.rand.Next(4)) //this are the messages when you talk to the npc
{
case 0:
return "Did you need something?";
case 1:
return "You better not be causing trouble";
case 2:
return "You look worn out";
case 3:
return "You need to take a break every once in awhile";
case 4:
return "I worry about you sometimes you know";
case 5:
return "Take care out there";
case 6:
return "EEEK WHO IS Tha.. A.. ahem... you didn't hear anything";
case 7:
return "I hope you aren't pushing yourself";
case 7:
return "I'll hold the fort go get some rest";
default:
return "Ah do you require my assistance?";

}
}
public override void TownNPCAttackStrength(ref int damage, ref float knockback)// Allows you to determine the damage and knockback of this town NPC attack
{
damage = 100; //npc damage
knockback = 3f; //npc knockback
}

public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown) //Allows you to determine the cooldown between each of this town NPC's attack. The cooldown will be a number greater than or equal to the first parameter, and less then the sum of the two parameters.
{
cooldown = 5;
randExtraCooldown = 10;
}
//------------------------------------This is an example of how to make the npc use a sward attack-------------------------------
public override void DrawTownAttackSwing(ref Texture2D item, ref int itemSize, ref float scale, ref Vector2 offset)//Allows you to customize how this town NPC's weapon is drawn when this NPC is swinging it (this NPC must have an attack type of 3). Item is the Texture2D instance of the item to be drawn (use Main.itemTexture[id of item]), itemSize is the width and height of the item's hitbox
{
scale = 1f;
item = Terrablade("CustomSword")]; //this defines the item that this npc will use
itemSize = 56;
}

public override void TownNPCAttackSwing(ref int itemWidth, ref int itemHeight) // Allows you to determine the width and height of the item this town NPC swings when it attacks, which controls the range of this NPC's swung weapon.
{
itemWidth = 56;
itemHeight = 56;
}

//----------------------------------This is an example of how to make the npc use a gun and a projectile ----------------------------------
/*public override void DrawTownAttackGun(ref float scale, ref int item, ref int closeness) //Allows you to customize how this town NPC's weapon is drawn when this NPC is shooting (this NPC must have an attack type of 1). Scale is a multiplier for the item's drawing size, item is the ID of the item to be drawn, and closeness is how close the item should be drawn to the NPC.
{
scale = 1f;
item = Undertaker("Undertaker");
closeness = 20;
}
public override void TownNPCAttackProj(ref int projType, ref int attackDelay)//Allows you to determine the projectile type of this town NPC's attack, and how long it takes for the projectile to actually appear
{
projType = ProjectileID.CrystalBullet;
attackDelay = 1;
}

public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)//Allows you to determine the speed at which this town NPC throws a projectile when it attacks. Multiplier is the speed of the projectile, gravityCorrection is how much extra the projectile gets thrown upwards, and randomOffset allows you to randomize the projectile's velocity in a square centered around the original velocity
{
multiplier = 7f;
// randomOffset = 4f;

} */

}
}
 
Just delete
public override bool Autoload(ref string name, ref string texture)
{
name = "NPCTown";
return mod.Properties.Autoload;
}
I did what you said, but i'm getting
error CS1071 'terraria.npc' does not contain a definition for 'name' and no extension method 'name' accepting a first argument of type 'terraria.npc' could be found (are you missing a using directive or an assembly reference?)


using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria;
using Terraria.ModLoader;

namespace LegendOfMaxx.NPCs //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
public class CustomTownNPC : ModNPC
{
public override void SetDefaults()
{
npc.name = "Aley"; //the name displayed when hovering over the npc ingame.
npc.townNPC = true; //This defines if the npc is a town Npc or not
npc.friendly = true; //this defines if the npc can hur you or not()
npc.width = 20; //the npc sprite width
npc.height = 20; //the npc sprite height
npc.aiStyle = 7; //this is the npc ai style, 7 is Pasive Ai
npc.defense = 25; //the npc defense
npc.lifeMax = 250;// the npc life
npc.HitSound = SoundID.NPCHit1; //the npc sound when is hit
npc.DeathSound = SoundID.NPCDeath1; //the npc sound when he dies
npc.knockBackResist = 0.5f; //the npc knockback resistance
Main.npcFrameCount[npc.type] = 25; //this defines how many frames the npc sprite sheet has
NPCID.Sets.ExtraFramesCount[npc.type] = 9;
NPCID.Sets.AttackFrameCount[npc.type] = 4;
NPCID.Sets.DangerDetectRange[npc.type] = 150; //this defines the npc danger detect range
NPCID.Sets.AttackType[npc.type] = 3; //this is the attack type, 0 (throwing), 1 (shooting), or 2 (magic). 3 (melee)
NPCID.Sets.AttackTime[npc.type] = 30; //this defines the npc attack speed
NPCID.Sets.AttackAverageChance[npc.type] = 10;//this defines the npc atack chance
NPCID.Sets.HatOffsetY[npc.type] = 4; //this defines the party hat position
animationType = NPCID.Guide; //this copy the guide animation
}
public override bool CanTownNPCSpawn(int numTownNPCs, int money) //Whether or not the conditions have been met for this town NPC to be able to move into town.
{
if (NPC.downedBoss1) //so after the EoC is killed
{
return true;
}
return false;
}
public override bool CheckConditions(int left, int right, int top, int bottom) //Allows you to define special conditions required for this town NPC's house
{
return true; //so when a house is available the npc will spawn
}
public override string TownNPCName() //Allows you to give this town NPC any name when it spawns
{
switch (WorldGen.genRand.Next(6))
{
case 0:
return "Aley";
case 1:
return "Aley";
case 2:
return "Aley";
case 3:
return "Aley";
case 4:
return "Aley";
case 5:
return "Aley";
default:
return "Aley";
}
}

public override void SetChatButtons(ref string button, ref string button2) //Allows you to set the text for the buttons that appear on this town NPC's chat window.
{
button = "Ale"; //this defines the buy button name
}
public override void OnChatButtonClicked(bool firstButton, ref bool openShop) //Allows you to make something happen whenever a button is clicked on this town NPC's chat window. The firstButton parameter tells whether the first button or second button (button and button2 from SetChatButtons) was clicked. Set the shop parameter to true to open this NPC's shop.
{

if (firstButton)
{
openShop = true; //so when you click on buy button opens the shop
}
}

public override void SetupShop(Chest shop, ref int nextSlot) //Allows you to add items to this town NPC's shop. Add an item by setting the defaults of shop.item[nextSlot] then incrementing nextSlot.
{
{
shop.item[nextSlot].SetDefaults(ItemID.Ale); //an example of how to add a vanilla terraria item
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.Mug);
nextSlot++;
}
if (NPC.downedBoss3) //this make so when Skeletron is killed the town npc will sell this
{
shop.item[nextSlot].SetDefaults(ItemID.BookofSkulls);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.ClothierVoodooDoll);
nextSlot++;
}
shop.item[nextSlot].SetDefaults(ItemID.IronskinPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(mod.ItemType("CustomSword")); //this is an example of how to add a modded item
nextSlot++;

}

public override string GetChat() //Allows you to give this town NPC a chat message when a player talks to it.
{
int wizardNPC = NPC.FindFirstNPC(NPCID.Wizard); //this make so when this npc is close to Wizard
if (wizardNPC >= 0 && Main.rand.Next(4) == 0) //has 1 in 3 chance to show this message
{
return "Yes " + Main.npc[wizardNPC].displayName + " is a wizard.";
}
int guideNPC = NPC.FindFirstNPC(NPCID.Guide); //this make so when this npc is close to the Guide
if (guideNPC >= 0 && Main.rand.Next(4) == 0) //has 1 in 3 chance to show this message
{
return "Sure you can ask " + Main.npc[guideNPC].displayName + " how to make Ironskin potion or you can buy it from me..hehehe.";
}
switch (Main.rand.Next(4)) //this are the messages when you talk to the npc
{
case 0:
return "You wanna buy something?";
case 1:
return "What you want?";
case 2:
return "Aley";
case 3:
return "Aley";
default:
return "Go kill Skeletron.";

}
}
public override void TownNPCAttackStrength(ref int damage, ref float knockback)// Allows you to determine the damage and knockback of this town NPC attack
{
damage = 40; //npc damage
knockback = 2f; //npc knockback
}

public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown) //Allows you to determine the cooldown between each of this town NPC's attack. The cooldown will be a number greater than or equal to the first parameter, and less then the sum of the two parameters.
{
cooldown = 5;
randExtraCooldown = 10;
}
//------------------------------------This is an example of how to make the npc use a sward attack-------------------------------

public override void DrawTownAttackSwing(ref Texture2D item, ref int itemSize, ref float scale, ref Vector2 offset)//Allows you to customize how this town NPC's weapon is drawn when this NPC is swinging it (this NPC must have an attack type of 3). Item is the Texture2D instance of the item to be drawn (use Main.itemTexture[id of item]), itemSize is the width and height of the item's hitbox
{
scale = 1f;
item = Main.itemTexture[mod.ItemType("CustomSword")]; //this defines the item that this npc will use
itemSize = 56;
}

public override void TownNPCAttackSwing(ref int itemWidth, ref int itemHeight) // Allows you to determine the width and height of the item this town NPC swings when it attacks, which controls the range of this NPC's swung weapon.
{
itemWidth = 56;
itemHeight = 56;
}

//----------------------------------This is an example of how to make the npc use a gun and a projectile ----------------------------------
/*
public override void DrawTownAttackGun(ref float scale, ref int item, ref int closeness) //Allows you to customize how this town NPC's weapon is drawn when this NPC is shooting (this NPC must have an attack type of 1). Scale is a multiplier for the item's drawing size, item is the ID of the item to be drawn, and closeness is how close the item should be drawn to the NPC.
{
scale = 1f;
item = ItemID.LastPrism;
closeness = 20;
}
public override void TownNPCAttackProj(ref int projType, ref int attackDelay)//Allows you to determine the projectile type of this town NPC's attack, and how long it takes for the projectile to actually appear
{
projType = ProjectileID.LastPrismLaser;
attackDelay = 1;
}

public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)//Allows you to determine the speed at which this town NPC throws a projectile when it attacks. Multiplier is the speed of the projectile, gravityCorrection is how much extra the projectile gets thrown upwards, and randomOffset allows you to randomize the projectile's velocity in a square centered around the original velocity
{
multiplier = 7f;
// randomOffset = 4f;

} */

}
}

Top of spoiler
 
Back
Top Bottom