Standalone [1.3] tModLoader - A Modding API

if you're using this code:
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;

please do yourself a favor, and replace it with this:
return 100f;

there's no point in doing multiple checks, if you're always returning the same thing...
Im not doing that anymore :/
 
is heaven real? other than that nothing else, you helped me enough today! OH WAIT I REMEMBERED HOW DO YOU MAKE ITEMS FLOAT LIKE SOULS
You'll want to put the following inside your SetDefaults function (of your soul item I mean):
Code:
ItemID.Sets.ItemNoGravity[item.type] = true;
 
You'll want to put the following inside your SetDefaults function (of your soul item I mean):
Code:
ItemID.Sets.ItemNoGravity[item.type] = true;
Alright thanks and bye
 
with the method I was using how do I lower the spawn rate?
[DOUBLEPOST=1457583514,1457582939][/DOUBLEPOST]because they WONT STOP COMING
 
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items
{
public class ExampleGun : ModItem
{
public override void SetDefaults()
{
item.name = "Specter Rifle";
item.damage = 20;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "This is a modded gun.";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 2;
item.useSound = 11;
item.autoReuse = true;
item.shoot = 10;
item.shootSpeed = 16f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(ItemId.DirtBlock);
recipe.SetResult(ItemID.Specter Rifle);
recipe.AddRecipe();
}
}
}





It keeps telling me line 37-38 are messed up but how and if you see anything else wrong could you guys help I'm new at CS
 
It keeps telling me line 37-38 are messed up but how and if you see anything else wrong could you guys help I'm new at CS

AddIngredient takes at least two arguments, you need to specify how much Dirt Blocks are required. If you need only one, type:
Code:
recipe.AddIngredient(ItemID.DirtBlock, 1);
Also note how ItemID spells ID with two uppercase letters.

As for SetResult, there are three problems here. First of all, ItemID is only used for items in the vanilla game. Secondly, you can't use spaces in arguments that aren't strings, C# doesn't understand that. Thirdly, SetResult also needs an argument for the amount of items created.

This is what you want:
Code:
recipe.SetResult(this, 1);

You can use 'this' instead of the name of your class, and 1 means that you will only craft one.
 
AddIngredient takes at least two arguments, you need to specify how much Dirt Blocks are required. If you need only one, type:
Code:
recipe.AddIngredient(ItemID.DirtBlock, 1);
Thirdly, SetResult also needs an argument for the amount of items created.
This isn't true, the stack argument is an optional argument with a default value of 1. There is no need to specify it and it will never be wrong to the compiler.
 
with the method I was using how do I lower the spawn rate?
[DOUBLEPOST=1457583514,1457582939][/DOUBLEPOST]because they WONT STOP COMING
You should have the following line:
Code:
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 0;
Right? In that case, you'll want to turn the 100f WAY down. As comparison: vanilla NPCs spawn rate lies around 1 (I think).
If you want your NPC to be rarer than your average NPC, just change that value to 0.5f or something.
 
This isn't true, the stack argument is an optional argument with a default value of 1. There is no need to specify it and it will never be wrong to the compiler.

So they are. My bad. Somehow missed the optional argument declarations.
 
So they are. My bad. Somehow missed the optional argument declarations.
no problem, it's just a while ago everyone was pointing that out as why the code wouldn't build and it confused people since it wasn't actually a problem.
 
error CS1518: Expected class, delegate, enum, interface, or struct

I just copy pasted everything over to this other thing and theres an error...

}
public override float CanSpawn(NPCSpawnInfo spawnInfo) ///It says the error is here
{
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;
}
 
error CS1518: Expected class, delegate, enum, interface, or struct

I just copy pasted everything over to this other thing and theres an error...

}
public override float CanSpawn(NPCSpawnInfo spawnInfo) ///It says the error is here
{
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;
}
Could you show your whole code? It's probably a typo.
 
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
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;
}

}
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;
}

}
 
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
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;
}

}
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;
}

}
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.
 
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
 
ahh thanks
[DOUBLEPOST=1457607276,1457607237][/DOUBLEPOST]the name aiStyle does not exist in the current context
It's npc.aiStyle not just plain aiStyle.
 
oh stupid mistake
 
At some point I wonder; how are segmented mobs created? I dont want a tutorial, I just wanna know how its done
 
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
 
Back
Top Bottom