Standalone [1.3] tModLoader - A Modding API

YAY IT :red:ING WORKED! mind my french im happy rn
[DOUBLEPOST=1457580336,1457579806][/DOUBLEPOST]Alright I is calm now

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...
 
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;
 
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.
 
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.
 
Back
Top Bottom