Standalone [1.3] tModLoader - A Modding API

Well:
Code:
            projectile.rotation += 0.1f;
            Vector2 drawPos = projectile.Center - Main.screenPosition;
            Color alpha = GetColor();
            spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, alpha, projectile.rotation, new Vector2(2, 2), 1f, SpriteEffects.None, 0f);
            return false;
But it only rotates 0.1f. What if I want it to rotate 0.1f on every fame, i.e. keep spinning?
Well, isn't this method called every frame? It should work, if it doesn't, if you could post all the code I could help better.
 
Well, isn't this method called every frame? It should work, if it doesn't, if you could post all the code I could help better.
of course, here you are:
Code:
public class SuperStarCannonProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Super Star Cannon Projectile";
            projectile.width = 16;
            projectile.height = 16;
            projectile.alpha = 0;
            projectile.aiStyle = 1;
            projectile.friendly = true;
            projectile.ranged = true;
            projectile.penetrate = -1;
            projectile.timeLeft = 600;
            projectile.light = 0.9f;
            projectile.scale = 1.2f;
            projectile.extraUpdates = 1;
            aiType = 5;
        }

        public Color GetColor()
        {
            return new Color(255, 255, 255);
        }

        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            projectile.rotation += 0.1f;
            Vector2 drawPos = projectile.Center - Main.screenPosition;
            Color alpha = GetColor();
            spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, alpha, projectile.rotation, new Vector2(2, 2), 1f, SpriteEffects.None, 0f);
            return false;
}
        }
 
of course, here you are:
Code:
public class SuperStarCannonProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Super Star Cannon Projectile";
            projectile.width = 16;
            projectile.height = 16;
            projectile.alpha = 0;
            projectile.aiStyle = 1;
            projectile.friendly = true;
            projectile.ranged = true;
            projectile.penetrate = -1;
            projectile.timeLeft = 600;
            projectile.light = 0.9f;
            projectile.scale = 1.2f;
            projectile.extraUpdates = 1;
            aiType = 5;
        }

        public Color GetColor()
        {
            return new Color(255, 255, 255);
        }

        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            projectile.rotation += 0.1f;
            Vector2 drawPos = projectile.Center - Main.screenPosition;
            Color alpha = GetColor();
            spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, alpha, projectile.rotation, new Vector2(2, 2), 1f, SpriteEffects.None, 0f);
            return false;
}
        }
Oh, so aiStyle 1, I believe, will automatically rotate the projectile to face the direction of velocity. This way, things like arrows and such look right.

Also, your aiType is for the Jesters Arrow, any reason?

Anyway, you can force it by storing your rotation separately or by using an aiStyle that doesn't cause rotation to be fixed like that or just don't have a aiStyle.

If I were you, I'd look for a projectile that does pretty much what you want and clone it.

Why not take a look at ExampleCloneProjectile in ExampleMod? It seems very similar to what you want anyway, it is a star that rotates and it looks like a falling star.
 
Oh, so aiStyle 1, I believe, will automatically rotate the projectile to face the direction of velocity. This way, things like arrows and such look right.

Also, your aiType is for the Jesters Arrow, any reason?

Anyway, you can force it by storing your rotation separately or by using an aiStyle that doesn't cause rotation to be fixed like that or just don't have a aiStyle.

If I were you, I'd look for a projectile that does pretty much what you want and clone it.

Why not take a look at ExampleCloneProjectile in ExampleMod? It seems very similar to what you want anyway, it is a star that rotates and it looks like a falling star.
Well, that aiType was put at random.
I actually set aiType to 12 initially, but it ain't working.
So I'm trying to make it by my own... ofc. with your help, but without engaging with the vanilla. Now I changed the aiType to -1, it doesn't work either. Maybe you could tell me how to realize this without cloning a vanilla projectile?
 
Well, that aiType was put at random.
I actually set aiType to 12 initially, but it ain't working.
So I'm trying to make it by my own... ofc. with your help, but without engaging with the vanilla. Now I changed the aiType to -1, it doesn't work either. Maybe you could tell me how to realize this without cloning a vanilla projectile?
Any reason you are opposed to cloning a vanilla projectile? It gets you 80% of the way there really easily.

Anyway, I've forgotten exactly what you want. I guess you want to write your own AI. I think you can just have position be incremented by velocity and rotation incremented by .1 and your AI should be fine.
 
Any reason you are opposed to cloning a vanilla projectile? It gets you 80% of the way there really easily.

Anyway, I've forgotten exactly what you want. I guess you want to write your own AI. I think you can just have position be incremented by velocity and rotation incremented by .1 and your AI should be fine.
OK... I'm making a star projectile, since I want to make a super star cannon, sort of stuff like that. So I need a more awesome star projectile. So I think I should first figure out how star cannon's star works.
12 is the aitype of star cannon's star(falling star). I set my projectile's aiType to 12 and it ain't working like the star cannon. I would like to clone vanilla projectile if I can, but now it ain't working so I don't know what to do. This actually happens a lot.
[DOUBLEPOST=1453547960,1453547601][/DOUBLEPOST]
Any reason you are opposed to cloning a vanilla projectile? It gets you 80% of the way there really easily.

Anyway, I've forgotten exactly what you want. I guess you want to write your own AI. I think you can just have position be incremented by velocity and rotation incremented by .1 and your AI should be fine.
The vanilla star has several characters:
1. it will keep rotating while it flies.
2. it will blink, at the same time make the sound of the star and create dusts.
3. flies in a line, ofc.
But when I adapt aiType = 12, none of these 3 characters was adpated...

EDIT: after this I somehow changed the aiType to 5 and always tested with this, 12 does nothing anyways.
 
OK... I'm making a star projectile, since I want to make a super star cannon, sort of stuff like that. So I need a more awesome star projectile. So I think I should first figure out how star cannon's star works.
12 is the aitype of star cannon's star(falling star). I set my projectile's aiType to 12 and it ain't working like the star cannon. I would like to clone vanilla projectile if I can, but now it ain't working so I don't know what to do. This actually happens a lot.
[DOUBLEPOST=1453547960,1453547601][/DOUBLEPOST]
The vanilla star has several characters:
1. it will keep rotating while it flies.
2. it will blink, at the same time make the sound of the star and create dusts.
3. flies in a line, ofc.
But when I adapt aiType = 12, none of these 3 characters was adpated...

EDIT: after this I somehow changed the aiType to 5 and always tested with this, 12 does nothing anyways.
Are you not using projectile.aiStyle = 5? aiType doesn't matter if you get the aiStyle wrong. Check the spreadsheet for values. aiType should be equal to ProjectileID and aiStyle you look up on the spreadsheet.

And.....that is exactly what ExampleCloneProjectile does (I assume you didn't actually use it in game). Here is ExampleCloneItem with line 13 changed to this: item.CloneDefaults(ItemID.StarCannon);
 
1. First result on google for
Have you tried just calling Projectile.NewProjectile in ModItem.Shoot? (You can call it as many times as you want, but I imagine if you go over the limit they should just die.)

How do you do that?
 
Last edited:
You could try to make a Slime projectile like this (summons are projectiles):
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MyMod.Projectiles
{
    public class MySlime : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.BabySlime); //Copy stats from Baby Slime
            projectile.name = "My Slime";
            aiType = ProjectileID.BabySlime;
        }
     
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if (Main.rand.Next(2) == 0) //increase the 2 for a lower chance
                target.AddBuff(mod.BuffType("MyBuff"), 300);
        }
    }
}
And for the actual summon item/buff, you could look at ExampleMod's Purity Totem.
 
Are you not using projectile.aiStyle = 5? aiType doesn't matter if you get the aiStyle wrong. Check the spreadsheet for values. aiType should be equal to ProjectileID and aiStyle you look up on the spreadsheet.

And.....that is exactly what ExampleCloneProjectile does (I assume you didn't actually use it in game). Here is ExampleCloneItem with line 13 changed to this: item.CloneDefaults(ItemID.StarCannon);
Wow!! This is what clone means! Never carefully thought of that. My bad.
But what precisely does clone duplicate to a new projectile?
After I add "projectile.CloneDefaults(ProjectileID.FallingStar);", I noticed that the projectile starts to spin and blink, also create dusts while flying, but it does nothing when it hits a tile. Does clone mean cloning default settings and AI, not including OnTileCollide?
By the way, I also got a question regarding frames. Look, the AI and the preDraw are all called out on every frame. So what if I want it to call every 2 frame? Maybe not to constrain the hook, but make some of the functions inside it work out on every 2 frame.
 
You could try to make a Slime projectile like this (summons are projectiles):
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MyMod.Projectiles
{
    public class MySlime : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.BabySlime); //Copy stats from Baby Slime
            projectile.name = "My Slime";
            aiType = ProjectileID.BabySlime;
        }
   
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if (Main.rand.Next(2) == 0) //increase the 2 for a lower chance
                target.AddBuff(mod.BuffType("MyBuff"), 300);
        }
    }
}
And for the actual summon item/buff, you could look at ExampleMod's Purity Totem.

Excuse me, do you happen to know how create a weapon that summons multiple minions? Someone here mentioned calling Projectile.NewProjectile in ModItem.Shoot. But i'm not sure how to go about doing that.
 
Excuse me, do you happen to know how create a weapon that summons multiple minions? Someone here mentioned calling Projectile.NewProjectile in ModItem.Shoot. But i'm not sure how to go about doing that.
You'll want to override the Shoot function like mentioned and indeed call Projectile.NewProjectile multiple times:
Code:
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, mod.ProjectileType("MyProjectile1"), damage, knockBack); 
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, mod.ProjectileType("MyProjectile2"), damage, knockBack);
    return false;
}
 
I still can't download the zip file from mediafire. Same thing as before. When I click the download button it simply reloads the page instead of downloading it. Can someone just pm it to me? Same thing goes for the example mod, I can't download it so I would appreciate someone sending me it.
 
Okay a little sneeky peeky for ya galls :D
oNS2T2T.gif

http://i.imgur.com/oNS2T2T.gifv

Yup this is an interactive search table for tModLoader hooks, fields, properties etc. etc.. Might release soon, whatya think of it ? (it is just an .html page)

edit: try it out yourself: http://gorateron.github.io/tModLoaderData/index.html
 
Last edited:
Can anyone help me when I try to get my npc to spawn on a blood moon I got this error
c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\NPCs\BloodySlime.cs(38,24) : error CS0161: 'EpicnessMod.NPCs.BloodySlime.CanSpawn(Terraria.ModLoader.NPCSpawnInfo)': not all code paths return a value

Here is the npc's code
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.NPCs
{
    public class BloodySlime : ModNPC
    {
public override void SetDefaults()
        {
            npc.name = "Bloody Slime";
            npc.lifeMax = 55;
            npc.damage = 40;
            npc.defense = 45;
            npc.knockBackResist = 0.1f;
            npc.width = 36;
            npc.height = 24;
            animationType = NPCID.MotherSlime;
            npc.aiStyle = 1;
            npc.npcSlots = 1f;
            npc.noGravity = false;
            npc.soundHit = 1;
            npc.soundKilled = 6;
            Main.npcFrameCount[npc.type] = 2;
            npc.value = Item.buyPrice(0, 0, 30, 5);
            npc.buffImmune[BuffID.Poisoned] = true;
            npc.buffImmune[BuffID.Venom] = true;
            banner = npc.type;
            bannerItem = mod.ItemType("BloodySlimeBanner");
        }
        public override void NPCLoot()
        {
         Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType ("BloodGel"));
        }
    public override float CanSpawn(NPCSpawnInfo spawnInfo)
    {
  if (Main.bloodMoon)
{
return 1f;
}
    }

   
}
}
 
Can anyone help me when I try to get my npc to spawn on a blood moon I got this error
c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\NPCs\BloodySlime.cs(38,24) : error CS0161: 'EpicnessMod.NPCs.BloodySlime.CanSpawn(Terraria.ModLoader.NPCSpawnInfo)': not all code paths return a value

Here is the npc's code
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.NPCs
{
    public class BloodySlime : ModNPC
    {
public override void SetDefaults()
        {
            npc.name = "Bloody Slime";
            npc.lifeMax = 55;
            npc.damage = 40;
            npc.defense = 45;
            npc.knockBackResist = 0.1f;
            npc.width = 36;
            npc.height = 24;
            animationType = NPCID.MotherSlime;
            npc.aiStyle = 1;
            npc.npcSlots = 1f;
            npc.noGravity = false;
            npc.soundHit = 1;
            npc.soundKilled = 6;
            Main.npcFrameCount[npc.type] = 2;
            npc.value = Item.buyPrice(0, 0, 30, 5);
            npc.buffImmune[BuffID.Poisoned] = true;
            npc.buffImmune[BuffID.Venom] = true;
            banner = npc.type;
            bannerItem = mod.ItemType("BloodySlimeBanner");
        }
        public override void NPCLoot()
        {
         Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType ("BloodGel"));
        }
    public override float CanSpawn(NPCSpawnInfo spawnInfo)
    {
  if (Main.bloodMoon)
{
return 1f;
}
    }

  
}
}
I dont think it works that way...
 
What do I add to a monster so when its spawned it plays the Plantera song? and also what do I add to make it despawn when the player dies?
 
Back
Top Bottom