Standalone [1.3] tModLoader - A Modding API

Look at your code:
Code:
public class Haunted : ModNPC
{
    public override void SetDefaults()
    {
        npc.name = "Haunted";
        npc.displayName = "The Haunted";
        npc.width = 52;
        npc.height = 60;
        npc.damage = 200;
        npc.defense = 33;
        npc.lifeMax = 6000;
        npc.soundHit = 1;
        npc.soundKilled = 1;
        npc.value = 60f;
        npc.knockBackResist = 0.5f;
        aiStyle = 40;
    }
} // <--- Right over here
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if(((myModPlayer)spawnInfo.player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true) // That last ; here is not supposed to be there!
    {
        return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 5f : 0f;
    }
    return 0f;
}
You're closing your class before your put the function in. Fix: Move that closing bracket below your CanSpawn function.
ahh thanks
[DOUBLEPOST=1457607276,1457607237][/DOUBLEPOST]the name aiStyle does not exist in the current context
 
At some point I wonder; how are segmented mobs created? I dont want a tutorial, I just wanna know how its done
First you've got the head. This is an NPC that keeps track of the actual life of the NPC and functions as the main AI source.
Then you've got two other NPCs: A body part and a tail part. In the AI of the head, both these other NPCs are created upon spawning (the body parts are obviously created multiple times).
Now each part (except the head) holds a value that represents the index of the npc before it in the Main.npc array so it can get the position and rotation of that NPC, thus making it able to follow it.

Don't know if this was the explanation you're looking for? ;)
 
First you've got the head. This is an NPC that keeps track of the actual life of the NPC and functions as the main AI source.
Then you've got two other NPCs: A body part and a tail part. In the AI of the head, both these other NPCs are created upon spawning (the body parts are obviously created multiple times).
Now each part (except the head) holds a value that represents the index of the npc before it in the Main.npc array so it can get the position and rotation of that NPC, thus making it able to follow it.

Don't know if this was the explanation you're looking for? ;)
that sounds confusing
[DOUBLEPOST=1457608804,1457608483][/DOUBLEPOST]What does the AI "do"? That sounds like the most confusing part. movement wise
 
that sounds confusing
Uhm.. Lemme try to give you an example in psuedo code:
Code:
/// HEAD 
public override void AI
{
    if(npc.ai[0] == 0)
    {            
        int npcToFollow = npc.whoAmI;
        for(int i = 0; i < 10; ++i)
        {                    
            int newNPC;   
            if(i < 9)
                newNPC = NPC.NewNPC(npc.position.X, npc.position.Y, mod.NPCType("BodyPart");
            else
                newNPC = NPC.NewNPC(npc.position.X, npc.position.Y, mod.NPCType("TailPart"); // We only want one tail.

            Main.npc[newNPC].ai[0] = npcToFollow;
            npcToFollow = newNPC;
        }
        npc.ai[0] = 1; // Can only be triggered once
    }

    // Direction and moving code.
}

// TAIL & BODY
public override void AI
{
    NPC target = Main.npc[(int)npc.ai[0]];
    // Now we have the part that was spawned (quite litterally) before this one, so we'll be able to follow it.
}
 
Uhm.. Lemme try to give you an example in psuedo code:
Code:
/// HEAD
public override void AI
{
    if(npc.ai[0] == 0)
    {           
        int npcToFollow = npc.whoAmI;
        for(int i = 0; i < 10; ++i)
        {                   
            int newNPC;  
            if(i < 9)
                newNPC = NPC.NewNPC(npc.position.X, npc.position.Y, mod.NPCType("BodyPart");
            else
                newNPC = NPC.NewNPC(npc.position.X, npc.position.Y, mod.NPCType("TailPart"); // We only want one tail.

            Main.npc[newNPC].ai[0] = npcToFollow;
            npcToFollow = newNPC;
        }
        npc.ai[0] = 1; // Can only be triggered once
    }

    // Direction and moving code.
}

// TAIL & BODY
public override void AI
{
    NPC target = Main.npc[(int)npc.ai[0]];
    // Now we have the part that was spawned (quite litterally) before this one, so we'll be able to follow it.
}
alright thanks. One last sidenotive kinda thing; How do you make a monster 'leech' life from you when it hits you? Im assuming its an onhitplayer (does that even exist)
 
alright thanks. One last sidenotive kinda thing; How do you make a monster 'leech' life from you when it hits you? Im assuming its an onhitplayer (does that even exist)
Yup, something like:
Code:
public override void OnHitPlayer(Player target, int damage, bool crit)
{
    // Here we can calculate the amount we want to leech using the damage value. I'm just 'leeching' half of the damage done.
    int leechAmount = damage / 2;
    if( (leechAmount + npc.life) > npc.lifeMax) // If the amount we leech exceeds the max life of the player, we'll want to cut it down to the max value possible.
    { 
        leechAmount = npc.lifeMax - npc.life;
    }
    npc.life += leechAmount; // HEAL!
}
 
Yup, something like:
Code:
public override void OnHitPlayer(Player target, int damage, bool crit)
{
    // Here we can calculate the amount we want to leech using the damage value. I'm just 'leeching' half of the damage done.
    int leechAmount = damage / 2;
    if( (leechAmount + npc.life) > npc.lifeMax) // If the amount we leech exceeds the max life of the player, we'll want to cut it down to the max value possible.
    {
        leechAmount = npc.lifeMax - npc.life;
    }
    npc.life += leechAmount; // HEAL!
}

yay thanks
[DOUBLEPOST=1457609648,1457609432][/DOUBLEPOST]One FINAL THING! what is the TileID for all furnaces and the tileid for all anvils?
 
tModLoaderInstaller opens with java but my java doesn't work
[DOUBLEPOST=1457614891,1457614798][/DOUBLEPOST]
You double-click it?
Is it not working for you? If so, you can always manually copy+paste the files.
 

Attachments

  • 2016-03-10.png
    2016-03-10.png
    523.9 KB · Views: 191
tModLoaderInstaller opens with java but my java doesn't work
Then you can do it like I said.
Head over to your Terraria steam folder and copy+paste all files (excluding the readme and the installer that is) into that folder (even if you're not on mac, you'll still want to copy the TerrariaMac.exe over (really, just everything excluding the two files mentioned earlier)).
 
Back
Top Bottom