Standalone [1.3] tModLoader - A Modding API

oh, ok, srry that im a big noob at C# ^-^
[doublepost=1468179309,1468179049][/doublepost]the only thing now i need help at is this:

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 SacredTools.NPCs
{
    public class PandolarTrader : ModNPC
    {
        public override bool Autoload(ref string name, ref string texture)
        {
            name = "PandolarTrader";
            return mod.Properties.Autoload;
        }
        public override void SetDefaults()
        {
            npc.name = "PandolarTrader";
            npc.displayName = "Pandolar Trader";
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 40;
            npc.aiStyle = 7;
            npc.damage = 30;
            npc.defense = 50;
            npc.lifeMax = 500;
            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 "Mural";
                case 1:
                    return "Reggie";
                case 2:
                    return "Waglington";
                default:
                    return "Tucker";
            }
        }
        public override string GetChat()
        {                                           //npc chat
        
            switch (Main.rand.Next(10))
            {
                case 0:
                    return "its a beautiful day outside...";
                case 1:
                    return "all hail Pandolar.";
                case 2:
                    return "you got some spare ice blocks maybe?? its really hot right now.";
                case 3:
                    return "my old home looked way better than this";
                case 4:
                    return "sometimes i think about licking ice cubes...";
                case 5:
                    return "you wanna buy something??";
                case 6:
                    return "you want something??";
                case 7:
                    return "my race was very powerful a long time ago, but now we are almost extinct";
                case 8:
                    return "Eseduh ohuht edahyay emecuh elyay eruhahl ah es et";
                default:
                    return "sup scrub";
            }
        }
        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("PandolarBow")); //items that he sells
            nextSlot++;
            shop.item[nextSlot].SetDefaults(mod.ItemType("Pandolance"));
            nextSlot++;
            shop.item[nextSlot].SetDefaults (ItemID.Snowball);
            nextSlot++;
        }
       
        public override void TownNPCAttackStrength(ref int damage, ref float knockback)
        {
            damage = 20;
            knockback = 4f;
        }

        public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown)
        {
            cooldown = 30;
            randExtraCooldown = 30;
        }

        public override void TownNPCAttackProj(ref int projType, ref int attackDelay)
        {
            projType = mod.ProjectileType("FrostBeamProjectile");
            attackDelay = 1;
        }

        public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)
        {
            multiplier = 12f;
            randomOffset = 2f;
        }
    }
}


i coded him to use the FrostBeamProjectile when an enemy is near, but the only thing he does is run away, pls help me find the issue
[doublepost=1468179716][/doublepost]and 3 extra things i forgot:

-How to play a dust on an NPC (no buff)
-How to display a Sprite above a buffed NPC/Player
-How to make a Beam Projectile (like the Shadowbeamstaff but without the ricochet)
 
argh, forgot another two:
-How do i make my debuff drain more HP (only does 1, no matter how much negative life regen i put)
-How do i make an Accessory give more maxhealth
 
oh, ok, srry that im a big noob at C# ^-^
[doublepost=1468179309,1468179049][/doublepost]the only thing now i need help at is this:

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 SacredTools.NPCs
{
    public class PandolarTrader : ModNPC
    {
        public override bool Autoload(ref string name, ref string texture)
        {
            name = "PandolarTrader";
            return mod.Properties.Autoload;
        }
        public override void SetDefaults()
        {
            npc.name = "PandolarTrader";
            npc.displayName = "Pandolar Trader";
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 40;
            npc.aiStyle = 7;
            npc.damage = 30;
            npc.defense = 50;
            npc.lifeMax = 500;
            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 "Mural";
                case 1:
                    return "Reggie";
                case 2:
                    return "Waglington";
                default:
                    return "Tucker";
            }
        }
        public override string GetChat()
        {                                           //npc chat
       
            switch (Main.rand.Next(10))
            {
                case 0:
                    return "its a beautiful day outside...";
                case 1:
                    return "all hail Pandolar.";
                case 2:
                    return "you got some spare ice blocks maybe?? its really hot right now.";
                case 3:
                    return "my old home looked way better than this";
                case 4:
                    return "sometimes i think about licking ice cubes...";
                case 5:
                    return "you wanna buy something??";
                case 6:
                    return "you want something??";
                case 7:
                    return "my race was very powerful a long time ago, but now we are almost extinct";
                case 8:
                    return "Eseduh ohuht edahyay emecuh elyay eruhahl ah es et";
                default:
                    return "sup scrub";
            }
        }
        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("PandolarBow")); //items that he sells
            nextSlot++;
            shop.item[nextSlot].SetDefaults(mod.ItemType("Pandolance"));
            nextSlot++;
            shop.item[nextSlot].SetDefaults (ItemID.Snowball);
            nextSlot++;
        }
      
        public override void TownNPCAttackStrength(ref int damage, ref float knockback)
        {
            damage = 20;
            knockback = 4f;
        }

        public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown)
        {
            cooldown = 30;
            randExtraCooldown = 30;
        }

        public override void TownNPCAttackProj(ref int projType, ref int attackDelay)
        {
            projType = mod.ProjectileType("FrostBeamProjectile");
            attackDelay = 1;
        }

        public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)
        {
            multiplier = 12f;
            randomOffset = 2f;
        }
    }
}


i coded him to use the FrostBeamProjectile when an enemy is near, but the only thing he does is run away, pls help me find the issue
[doublepost=1468179716][/doublepost]and 3 extra things i forgot:

-How to play a dust on an NPC (no buff)
-How to display a Sprite above a buffed NPC/Player
-How to make a Beam Projectile (like the Shadowbeamstaff but without the ricochet)

1) For the NPC who do not shoot: Recheck all thing of the ExampleNpc. After, you have probably fail the projectile, if this is not that ^^.
2) All NPC have a AI, you need just add dust in the AI code.
3) PostDraw.
4) This is a complex code, i think. I cannot explain :x

argh, forgot another two:
-How do i make my debuff drain more HP (only does 1, no matter how much negative life regen i put)
-How do i make an Accessory give more maxhealth
1)
player.HealEffect(-2, false);
player.statLife -= 2;
if (player.statLife < 0)
{
player.statLife = 0;
}
NetMessage.SendData(66, -1, -1, "", player.whoAmI, (float)-2, 0f, 0f, 0, 0, 0);
Try that, do not forgot add a cooldown, else each frame, ah ah
else player.lifeRegen -= X is functionnal for me, but you need maybe add player.HealEffect(-2, false);
2) just player.statLifeMax2 += 10;
 
thanl you for the great help! your in my credits now ^-^

also how do i make an enemy only spawn in Hardmode Underworld??
 
Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            Player player = spawnInfo.player;
            int x = spawnInfo.spawnTileX;
            int y = spawnInfo.spawnTileY;
         
            int tile = (int)Main.tile[x, y].type;
            return (Main.hardMode && !spawnInfo.playerSafe &&  (y > Main.maxTilesY - 190) ) ? 1f : 0f;
}
I think, you need many test after. ?1f : 0f; if a bool is false, so 0% than your npc spawn, else, 100%, so change 1f after test (for be sure than do not spawn a other place) where you put less, i suppose. With 1f, you can have very many npc :p
You can also add a Main.rand.Next(XX) ==0 in the list of bool for reassure you ^^.
 
H'ok... The Solarius item wasn't working because item.useAnimation was 1. I don't know how small it can be, but vanilla uses 25 there. Also, in the projectile, you've got 'projectile.type = ProjectileID.Arkhalis;' which will make the item a cosmetic clone of Arkhalis. If you want to use your own sprite, you'll need 'aiType = ProjectileID.Arkhalis;' instead.

Now, if you want to delay the projectile from homing in on enemies, then create an int to use as a timer, then place your homing code inside an if statement that checks if your int is above a specific value, and if it isn't, increase the timer. To adjust how quickly your projectile accelerates, change the 1.5f in the line 'projectile.velocity += acceleration * 1.5f;'

To make the projectile return to the player when it hits something, set 'projectile.ai[0]' to 1. The hooks onHitNPC, onHitPVP and onTileCollide are where you'll want to do this.

I tried to use onTileCollide, but it failed :(
code
Code:
public override bool OnTileCollide(Vector2 oldVelocty)
        {
            projectile.ai[0] = 1;
        }

error
not all code paths return a value.
and the line numbers are pointing to OnTileCollide
 
I tried to use onTileCollide, but it failed :(
code
Code:
public override bool OnTileCollide(Vector2 oldVelocty)
        {
            projectile.ai[0] = 1;
        }

error
not all code paths return a value.
and the line numbers are pointing to OnTileCollide
In public override bool ontilecollide, you have "bool" or void, or other. this is the value than you need return.

Void: you do not need return a value.
Bool: You need return true or false.
Etc
 
In public override bool ontilecollide, you have "bool" or void, or other. this is the value than you need return.

Void: you do not need return a value.
Bool: You need return true or false.
Etc

I changed it to void
error
return type must be 'bool' to match overridden member
 
You cannot change a override method. (Because this is a method already write in the modloader/ vanilla code than you "override" for replace code )
When i have say, you need return a value, YOU RETURN A VALUE, not you change the method.

Put return false or true, just that. (True if you want a tilecollide or false you wannot. (your projectile.ontilecollide or npc.ontilecollide have not effect when you apply this method ^^)
 
Code:
projectile.aiType = ProjectileID.Arkhalis;

this used to work in setdefaults and now it doesn't, but I didn't change it
error
Terraria.Projectile does not contain a definition for aiType and no extention method aiType accepting a first argument of type Terraria.Projectile could be found
 
Um, I can't find the publish button for my mod anywhere on tmod. It's nowhere to be found. Just vanished. I asked for help once and nobody replied.
 
im back with another question:

how i display multiple different dusts with different colors on one single projectile??
(i want all the 4 different moon colors: orange, purple, blue and green)

Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace SacredTools.Projectiles
{

    public class MoonBeam : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Moon Beam";  //projectile name
            projectile.width = 20;       //projectile width
            projectile.height = 28;  //projectile height
            projectile.friendly = true;      //make that the projectile will not damage you
            projectile.melee = true;         //
            projectile.tileCollide = true;   //make that the projectile will be destroed if it hits the terrain
            projectile.penetrate = 5;      //how many npc will penetrate
            projectile.timeLeft = 200;   //how many time this projectile has before disepire
            projectile.light = 0.75f;    // projectile light
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true;  
        }
        public override void AI()           //this make that the projectile will face the corect way
        {                                                           // |
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; 
            projectile.velocity.Y += projectile.ai[0];
           
           
            if (projectile.localAI[0] == 0f)
            {
                Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 20);
                projectile.localAI[0] = 1f;
            }
            int num666 = 8;
            int num667 = Dust.NewDust(new Vector2(projectile.position.X + (float)num666 + 6, projectile.position.Y + (float)num666), projectile.width - num666 * 2, projectile.height - num666 * 2, 66, 0f, 0f, 0, new Color(36, 158, 184), 1.5f);  //projectile dust color
            Main.dust[num667].velocity *= 0.5f;
            Main.dust[num667].velocity += projectile.velocity * 0.5f;
            Main.dust[num667].noGravity = true;
            Main.dust[num667].noLight = false;
            Main.dust[num667].scale = 2.4f;
        }
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(mod.BuffType("MoonCurse"), 500);
        }
       
       
       
       
       
    }
}
[doublepost=1468240491,1468240474][/doublepost]how do i*
 
im back with another question:

how i display multiple different dusts with different colors on one single projectile??
(i want all the 4 different moon colors: orange, purple, blue and green)

Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace SacredTools.Projectiles
{

    public class MoonBeam : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Moon Beam";  //projectile name
            projectile.width = 20;       //projectile width
            projectile.height = 28;  //projectile height
            projectile.friendly = true;      //make that the projectile will not damage you
            projectile.melee = true;         //
            projectile.tileCollide = true;   //make that the projectile will be destroed if it hits the terrain
            projectile.penetrate = 5;      //how many npc will penetrate
            projectile.timeLeft = 200;   //how many time this projectile has before disepire
            projectile.light = 0.75f;    // projectile light
            projectile.extraUpdates = 1;
            projectile.ignoreWater = true; 
        }
        public override void AI()           //this make that the projectile will face the corect way
        {                                                           // |
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
            projectile.velocity.Y += projectile.ai[0];
          
          
            if (projectile.localAI[0] == 0f)
            {
                Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 20);
                projectile.localAI[0] = 1f;
            }
            int num666 = 8;
            int num667 = Dust.NewDust(new Vector2(projectile.position.X + (float)num666 + 6, projectile.position.Y + (float)num666), projectile.width - num666 * 2, projectile.height - num666 * 2, 66, 0f, 0f, 0, new Color(36, 158, 184), 1.5f);  //projectile dust color
            Main.dust[num667].velocity *= 0.5f;
            Main.dust[num667].velocity += projectile.velocity * 0.5f;
            Main.dust[num667].noGravity = true;
            Main.dust[num667].noLight = false;
            Main.dust[num667].scale = 2.4f;
        }
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(mod.BuffType("MoonCurse"), 500);
        }
      
      
      
      
      
    }
}
[doublepost=1468240491,1468240474][/doublepost]how do i*

int num667 = Dust.NewDust(..., 66, ..., new Color(36, 158, 184),...); //projectile dust color

If you talk only with New Color(), you need just that:
Code:
Color color = new Color(0,0,0)
Int rand = Main.rand.Next(4);
switch (rand)
                {
                    case 0:
                    color = new Color(..,..,..)
                    break;
                    case 1:
                    color = new Color(..,..,..)
                    break;
                    case 2:
                    color = new Color(..,..,..)
                    break;
                    case 3:
                    color = new Color(..,..,..)
                    break;
int num667 = Dust.NewDust(..., 66, ..., color,...); 
}
 
Back
Top Bottom