Standalone [1.3] tModLoader - A Modding API

i watched the tutorial from al0n37, i have all the exact same code, but idk why this happens...
 
You have also the examplemod where you have two boss for example. Use that also.

Your problem is not in your code(i think), this is setdefault where you have probably put a bad value, i suppose
 
WELL I FOUND THE BUG:

it was the knockBackResist -.- i put it on 100f and thought its 100%...
 
ah, yes, i have not see, knockBackResist is a false word, more less you put, more he resist. Ah ah ^^. (and 0 is a immunity, 20 is huge knockback)
 
ooooohhhh.... so basically he disappeared becus he got 100 times the knockback... WELL
[doublepost=1468146708,1468146296][/doublepost]and i have another question:

how do i make my crossbow shoot FASTER??
if i change the usetime it will shoot 2 or more arrows after each other and also consume them, pls halp

heres the code:
Code:
using Terraria;
using System;
using Terraria.ID;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Terraria.ModLoader;

namespace SacredTools.Items.Weapons
{
    public class PandolarRepeater : ModItem
    {

        public override void SetDefaults()
        {
            item.name = "Pandolar Repeater";
            item.damage = 55;
            item.noMelee = true;
            item.ranged = true;
            item.width = 69;
            item.height = 40;
            item.toolTip = "death to the enemies!";
            item.toolTip2 = "Pandolar FTW!";
            item.useTime = 18;
            item.useAnimation = 30;
            item.useStyle = 5;
            item.shoot = 3;
            item.useAmmo = 1;
            item.knockBack = 1;
            item.value = Item.sellPrice(0, 30, 0, 0);
            item.rare = 5;
            item.useSound = 5;
            item.autoReuse = true;
            item.shootSpeed = 20f;

        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ProjectileID.FrostburnArrow, damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type FrostburnArrow using the original stats
            return false; //Makes sure to not fire the original projectile
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.SnowBlock, 100);
            recipe.AddIngredient(null, "OblivionBar", 20);
            recipe.AddIngredient(null, "PandolarBow", 1);
            recipe.AddTile(TileID.MythrilAnvil);   //at work bench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
[doublepost=1468146827][/doublepost]and how do i spawn more dust on an debuffed NPC/Player and make em not move away from the entity (for some reason my dust moves away from the debuffed enemy)
 
ooooohhhh.... so basically he disappeared becus he got 100 times the knockback... WELL
[doublepost=1468146708,1468146296][/doublepost]and i have another question:

how do i make my crossbow shoot FASTER??
if i change the usetime it will shoot 2 or more arrows after each other and also consume them, pls halp

heres the code:
Code:
using Terraria;
using System;
using Terraria.ID;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Terraria.ModLoader;

namespace SacredTools.Items.Weapons
{
    public class PandolarRepeater : ModItem
    {

        public override void SetDefaults()
        {
            item.name = "Pandolar Repeater";
            item.damage = 55;
            item.noMelee = true;
            item.ranged = true;
            item.width = 69;
            item.height = 40;
            item.toolTip = "death to the enemies!";
            item.toolTip2 = "Pandolar FTW!";
            item.useTime = 18;
            item.useAnimation = 30;
            item.useStyle = 5;
            item.shoot = 3;
            item.useAmmo = 1;
            item.knockBack = 1;
            item.value = Item.sellPrice(0, 30, 0, 0);
            item.rare = 5;
            item.useSound = 5;
            item.autoReuse = true;
            item.shootSpeed = 20f;

        }
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ProjectileID.FrostburnArrow, damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type FrostburnArrow using the original stats
            return false; //Makes sure to not fire the original projectile
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.SnowBlock, 100);
            recipe.AddIngredient(null, "OblivionBar", 20);
            recipe.AddIngredient(null, "PandolarBow", 1);
            recipe.AddTile(TileID.MythrilAnvil);   //at work bench
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
[doublepost=1468146827][/doublepost]and how do i spawn more dust on an debuffed NPC/Player and make em not move away from the entity (for some reason my dust moves away from the debuffed enemy)


UseTime: shoot projectile each time than he go this value and the max counts is useanimation, so, you need put less in useanimation also.

For your problem of dust, create a special dust and say: No, do not move! This is a stupid question, i think, you need just put velocity zero
 
where is the part i need to change??

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

namespace SacredTools.Dusts
{
    public class PandolarDust : ModDust
    {
        public override void OnSpawn(Dust dust)
        {
            dust.color = new Color(103, 208, 208); 
            dust.alpha = 1;
            dust.scale = 1.13f;
            dust.velocity *= 1.4f;
            dust.noGravity = true;
            dust.noLight = false;
        }

        public override bool Update(Dust dust)
        {
            dust.position += dust.velocity;
            dust.rotation += dust.velocity.X * 0.15f;
            dust.scale *= 0.99f;                   
            float light = 0.35f * dust.scale;
            Lighting.AddLight(dust.position, light, light, light);
            if (dust.scale < 0.5f)
            {
                dust.active = false;
            }
            return false;
        }
    }
}
 
public override bool Update(Dust dust)
{
dust.velocity *= 0f;
.... code ....
}
 
halp something went wrong, i tried to add minions to my boss, it didnt work so i removed them again, then i wanted to make the dust have no velocity, AND NOW I CANT PLAY! IT ALWAYS SAYS FAILED TO LOAD NO BACKUP FOUND ;-;

i hope i didnt loose my world....
 
halp something went wrong, i tried to add minions to my boss, it didnt work so i removed them again, then i wanted to make the dust have no velocity, AND NOW I CANT PLAY! IT ALWAYS SAYS FAILED TO LOAD NO BACKUP FOUND ;-;

i hope i didnt loose my world....
If lag, you have maybe add too many dust. After, maybe than put a dust to zero (Maybe put just dust.velocity = Vector2.Zero) can have problem. (but this is not that, because, no reason ^^)
For add minion, the minion, a npc have be coded per you or this is a vanilla npc?
 
Last edited:
I think I ´ve found a MP bug:

In singleplayer I can place/remove modded tiles but in multiplayer I can´t.

I have noticed that if try to place a modded tile in multiplayer, it seems to be placed but if I exit the game, it is not saved.


This is the code:

Code:
   public override void SetDefaults()
        {
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = true;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style3x3);
            TileObjectData.newTile.StyleHorizontal = true;
            TileObjectData.newTile.StyleWrapLimit = 36;
            TileObjectData.newTile.Direction = Terraria.Enums.TileObjectDirection.PlaceRight;
            TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight;
            animationFrameHeight = 54;
            TileObjectData.newAlternate.CopyFrom(TileObjectData.Style3x3);
            TileObjectData.newAlternate.StyleHorizontal = true;
            TileObjectData.addAlternate(1);
            Main.tileContainer[Type] = true;

            TileObjectData.addTile(Type);
         
     

            dustType = 7;
            disableSmartCursor = true;
            AddMapEntry(new Color(120, 85, 60), "Turret");
        }

        public override void KillMultiTile(int i, int j, int frameX, int frameY)
        {
              
        
                Item.NewItem(i * 16, j * 16, 48, 48, mod.ItemType("MyItem"));
          
        }
 
nvm i fixed it, but pls tell me where do i put the thing to make the dust not move

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

namespace SacredTools.Dusts
{
    public class ShadowDust : ModDust
    {
        public override void OnSpawn(Dust dust)
        {
            dust.color = new Color(103, 24, 122); 
            dust.alpha = 1;
            dust.scale = 1.13f;
            dust.velocity *= 1.4f;
            dust.noGravity = true;
            dust.noLight = false;
        }

        public override bool Update(Dust dust)
        {
            dust.position += dust.velocity;
            dust.rotation += dust.velocity.X * 0.15f;
            dust.scale *= 0.99f;                   
            float light = 0.35f * dust.scale;
            Lighting.AddLight(dust.position, light, light, light);
            if (dust.scale < 0.5f)
            {
                dust.active = false;
            }
            return false;
        }
    }
}
[doublepost=1468178197,1468178143][/doublepost]when i changed the velocity to 0.1, 0 the thing with the Backup happened
 
dust.position += dust.velocity; Maybe, you delete that
 
ok it works now, but, the size of the dust is too small, how do i make em bigger? do i have to make the sprite bigger?
 
setdefault :
dust.scale = 1.13f;

You know read? x)
 
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 ^^.
 
Back
Top Bottom