Standalone [1.3] tModLoader - A Modding API

I need to access a variable i want to set with a hotkey, which will turn off and on the modded npc spawns for testing, but i dont know how i can access the main Mod file variable from another file, since i dont know what the instance the game makes is called. Any ideas?
 
E1Z2Fnf.png


Game crashes and this message pops up randomly while playing. Any idea what it means/how to fix it?
 
I need to access a variable i want to set with a hotkey, which will turn off and on the modded npc spawns for testing, but i dont know how i can access the main Mod file variable from another file, since i dont know what the instance the game makes is called. Any ideas?
All modSomething classes have a reference to their mod class. You can cast that as the class of your mod class to get it from Mod to ExampleMod, for example.
 
How do I change this
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0.5f : 0f;
so it spawns in the day and night
[doublepost=1458037766,1458037748][/doublepost]in the sky biome*
 
Code:
return spawnInfo.sky ? 0.5F : 0F;
thanks
[doublepost=1458038313,1458038022][/doublepost]c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\SpiritMod\NPCs\BruteZombie.cs(113,17) : error CS1518: Expected class, delegate, enum, interface, or struct

public override float CanSpawn(NPCSpawnInfo spawnInfo)
 
thanks
[doublepost=1458038313,1458038022][/doublepost]c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\SpiritMod\NPCs\BruteZombie.cs(113,17) : error CS1518: Expected class, delegate, enum, interface, or struct

public override float CanSpawn(NPCSpawnInfo spawnInfo)
Could you show all your NPC code please?
 
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class ShootingStar : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Shooting Star";
            npc.displayName = "Shooting Star";
            npc.width = 30;
            npc.height = 24;
            npc.damage = 200;
            npc.defense = 30;
            npc.lifeMax = 5000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
        }
            public override bool PreAI()
{

    npc.noGravity = true;
    // The following handles the collision:
    if (!npc.noTileCollide)
    {
        if (npc.collideX)
        {
            npc.velocity.X = npc.oldVelocity.X * -0.5f;
            if (npc.direction == -1 && (double) npc.velocity.X > 0.0 && (double) npc.velocity.X < 2.0)
                npc.velocity.X = 2f;
            if (npc.direction == 1 && (double) npc.velocity.X < 0.0 && (double) npc.velocity.X > -2.0)
                npc.velocity.X = -2f;
        }
        if (npc.collideY)
        {
            npc.velocity.Y = npc.oldVelocity.Y * -0.5f;
            if ((double) npc.velocity.Y > 0.0 && (double) npc.velocity.Y < 1.0)
                npc.velocity.Y = 1f;
            if ((double) npc.velocity.Y < 0.0 && (double) npc.velocity.Y > -1.0)
                npc.velocity.Y = -1f;
        }
    } 
 
    npc.TargetClosest(true); // Gets a valid player to target.
    //The 'true' means that we want the NPC to look at the player.

    // The following is plucked right from the 'Demon Eye' AI, so you may want to take a look, but you might not understand it all:
 
    float num1 = 4f;
    float num2 = 1.5f;
    float num3 = num1 * (float) (1.0 + (1.0 - (double) npc.scale));
    float num4 = num2 * (float) (1.0 + (1.0 - (double) npc.scale));
    if (npc.direction == -1 && (double) npc.velocity.X > -(double) num3)
    {
        npc.velocity.X = npc.velocity.X - 0.1f;
        if ((double) npc.velocity.X > (double) num3)
            npc.velocity.X = npc.velocity.X - 0.1f;
        else if ((double) npc.velocity.X > 0.0)
            npc.velocity.X = npc.velocity.X + 0.05f;
        if ((double) npc.velocity.X < -(double) num3)
         npc.velocity.X = -num3;
    }
    else if (npc.direction == 1 && (double) npc.velocity.X < (double) num3)
    {
        npc.velocity.X = npc.velocity.X + 0.1f;
        if ((double) npc.velocity.X < -(double) num3)
            npc.velocity.X = npc.velocity.X + 0.1f;
        else if ((double) npc.velocity.X < 0.0)
            npc.velocity.X = npc.velocity.X - 0.05f;
        if ((double) npc.velocity.X > (double) num3)
            npc.velocity.X = num3;
    }
    if (npc.directionY == -1 && (double) npc.velocity.Y > -(double) num4)
    {
        npc.velocity.Y = npc.velocity.Y - 0.04f;
        if ((double) npc.velocity.Y > (double) num4)
            npc.velocity.Y = npc.velocity.Y - 0.05f;
        else if ((double) npc.velocity.Y > 0.0)
            npc.velocity.Y = npc.velocity.Y + 0.03f;
        if ((double) npc.velocity.Y < -(double) num4)
            npc.velocity.Y = -num4;
    }
    else if (npc.directionY == 1 && (double) npc.velocity.Y < (double) num4)
    {
        npc.velocity.Y = npc.velocity.Y + 0.04f;
        if ((double) npc.velocity.Y < -(double) num4)
            npc.velocity.Y = npc.velocity.Y + 0.05f;
        else if ((double) npc.velocity.Y < 0.0)
            npc.velocity.Y = npc.velocity.Y - 0.03f;
        if ((double) npc.velocity.Y > (double) num4)
            npc.velocity.Y = num4;
    }
 
    if(!npc.wet)
        return false;
 
    if ((double) npc.velocity.Y > 0.0)
        npc.velocity.Y = npc.velocity.Y * 0.95f;
    npc.velocity.Y = npc.velocity.Y - 0.5f;
    if ((double) npc.velocity.Y < -4.0)
        npc.velocity.Y = -4f;
    npc.TargetClosest(true);
 
    return false;
}
}           
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if (NPC.downedMechBossAny)
    {
        return spawnInfo.sky ? 0.7f : 0f;
    }
    return 0f;
}

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

namespace Enderuim.NPCs
{
    public class ShootingStar : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Shooting Star";
            npc.displayName = "Shooting Star";
            npc.width = 30;
            npc.height = 24;
            npc.damage = 200;
            npc.defense = 30;
            npc.lifeMax = 5000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
        }
            public override bool PreAI()
{

    npc.noGravity = true;
    // The following handles the collision:
    if (!npc.noTileCollide)
    {
        if (npc.collideX)
        {
            npc.velocity.X = npc.oldVelocity.X * -0.5f;
            if (npc.direction == -1 && (double) npc.velocity.X > 0.0 && (double) npc.velocity.X < 2.0)
                npc.velocity.X = 2f;
            if (npc.direction == 1 && (double) npc.velocity.X < 0.0 && (double) npc.velocity.X > -2.0)
                npc.velocity.X = -2f;
        }
        if (npc.collideY)
        {
            npc.velocity.Y = npc.oldVelocity.Y * -0.5f;
            if ((double) npc.velocity.Y > 0.0 && (double) npc.velocity.Y < 1.0)
                npc.velocity.Y = 1f;
            if ((double) npc.velocity.Y < 0.0 && (double) npc.velocity.Y > -1.0)
                npc.velocity.Y = -1f;
        }
    }

    npc.TargetClosest(true); // Gets a valid player to target.
    //The 'true' means that we want the NPC to look at the player.

    // The following is plucked right from the 'Demon Eye' AI, so you may want to take a look, but you might not understand it all:

    float num1 = 4f;
    float num2 = 1.5f;
    float num3 = num1 * (float) (1.0 + (1.0 - (double) npc.scale));
    float num4 = num2 * (float) (1.0 + (1.0 - (double) npc.scale));
    if (npc.direction == -1 && (double) npc.velocity.X > -(double) num3)
    {
        npc.velocity.X = npc.velocity.X - 0.1f;
        if ((double) npc.velocity.X > (double) num3)
            npc.velocity.X = npc.velocity.X - 0.1f;
        else if ((double) npc.velocity.X > 0.0)
            npc.velocity.X = npc.velocity.X + 0.05f;
        if ((double) npc.velocity.X < -(double) num3)
         npc.velocity.X = -num3;
    }
    else if (npc.direction == 1 && (double) npc.velocity.X < (double) num3)
    {
        npc.velocity.X = npc.velocity.X + 0.1f;
        if ((double) npc.velocity.X < -(double) num3)
            npc.velocity.X = npc.velocity.X + 0.1f;
        else if ((double) npc.velocity.X < 0.0)
            npc.velocity.X = npc.velocity.X - 0.05f;
        if ((double) npc.velocity.X > (double) num3)
            npc.velocity.X = num3;
    }
    if (npc.directionY == -1 && (double) npc.velocity.Y > -(double) num4)
    {
        npc.velocity.Y = npc.velocity.Y - 0.04f;
        if ((double) npc.velocity.Y > (double) num4)
            npc.velocity.Y = npc.velocity.Y - 0.05f;
        else if ((double) npc.velocity.Y > 0.0)
            npc.velocity.Y = npc.velocity.Y + 0.03f;
        if ((double) npc.velocity.Y < -(double) num4)
            npc.velocity.Y = -num4;
    }
    else if (npc.directionY == 1 && (double) npc.velocity.Y < (double) num4)
    {
        npc.velocity.Y = npc.velocity.Y + 0.04f;
        if ((double) npc.velocity.Y < -(double) num4)
            npc.velocity.Y = npc.velocity.Y + 0.05f;
        else if ((double) npc.velocity.Y < 0.0)
            npc.velocity.Y = npc.velocity.Y - 0.03f;
        if ((double) npc.velocity.Y > (double) num4)
            npc.velocity.Y = num4;
    }

    if(!npc.wet)
        return false;

    if ((double) npc.velocity.Y > 0.0)
        npc.velocity.Y = npc.velocity.Y * 0.95f;
    npc.velocity.Y = npc.velocity.Y - 0.5f;
    if ((double) npc.velocity.Y < -4.0)
        npc.velocity.Y = -4f;
    npc.TargetClosest(true);

    return false;
}
}          
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if (NPC.downedMechBossAny)
    {
        return spawnInfo.sky ? 0.7f : 0f;
    }
    return 0f;
}

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

namespace Enderuim.NPCs
{
    public class ShootingStar : ModNPC
    {
        // All your NPC code.
    } // < Uhm, you're closing the class before the CanSpawn function. Syntax bruh ;)          
    public override float CanSpawn(NPCSpawnInfo spawnInfo)
    {
        if (NPC.downedMechBossAny)
        {
            return spawnInfo.sky ? 0.7f : 0f;
        }
        return 0f;
    }
}
 
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class ShootingStar : ModNPC
    {
        // All your NPC code.
    } // < Uhm, you're closing the class before the CanSpawn function. Syntax bruh ;)         
    public override float CanSpawn(NPCSpawnInfo spawnInfo)
    {
        if (NPC.downedMechBossAny)
        {
            return spawnInfo.sky ? 0.7f : 0f;
        }
        return 0f;
    }
}
Sorry I copy pasted from another NPC
 
Hang on, whaaat?
I can't really seem to make something out of your post. What do you mean by 'enter the same code' and 'denies also denies example mod'??
Well uhmm its like i copy the cody cause mine didnt seem to work i changed everthing to customise name etc and it said "=" shouldnt be there i tried removing it than it also bugged thats my main problem
 
Well uhmm its like i copy the cody cause mine didnt seem to work i changed everthing to customise name etc and it said "=" shouldnt be there i tried removing it than it also bugged thats my main problem
Allright, could you show me your code then?
I might be able to help then.
 
If you would like to do a total conversion mod, would it be hard to have a mod that removes everything in the game except dirt/grass?
(Like flatworld setting in Minecraft).
 
If you would like to do a total conversion mod, would it be hard to have a mod that removes everything in the game except dirt/grass?
(Like flatworld setting in Minecraft).
Well not really you just have to make a worldgen that removes all the tiles and replaces them with a flat dirt/grass platform
 
Well not really you just have to make a worldgen that removes all the tiles and replaces them with a flat dirt/grass platform
Well not just the tiles, but remove every item/weapon/enemy/npc and so on.

Should be included as a mod in tModLoader.
 
Well not just the tiles, but remove every item/weapon/enemy/npc and so on.

Should be included as a mod in tModLoader.

Out of curiosity, why would you want to remove items? Wouldn't removing the means to acquire them be sufficient?
 
Code:
public override bool PreNPCLoot(NPC npc)
        {
                    if (npc.type == NPCID.EyeofCthulhu)
                    {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("EyeOfCthulhuNMBossBag"));
                    return false;
                    }
                    return true;
                    if (npc.type == NPCID.KingSlime)
                    {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KingSlimeNMBossBag"));
                    return false;
                    }
                    return true;
}
Why is this working for the EoC, but not the King Slime?
 
Code:
public override bool PreNPCLoot(NPC npc)
        {
                    if (npc.type == NPCID.EyeofCthulhu)
                    {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("EyeOfCthulhuNMBossBag"));
                    return false;
                    }
                    return true;
                    if (npc.type == NPCID.KingSlime)
                    {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KingSlimeNMBossBag"));
                    return false;
                    }
                    return true;
}
Why is this working for the EoC, but not the King Slime?
Code:
public override bool PreNPCLoot(NPC npc)
{
    if (npc.type == NPCID.EyeofCthulhu)
    {
        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("EyeOfCthulhuNMBossBag"));
        return false;
    }
    return true; // You'll want to remove this return statement. Return makes sure nothing passes through here, so it doesn't even reach the code below.
    if (npc.type == NPCID.KingSlime)
    {
        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KingSlimeNMBossBag"));
        return false;
    }
    return true;
}
 
So with public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit), is it possible to check the type of damage the projectile does? I thought maybe something like this would work, but it gave me errors of course.

Code:
public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit)
        {
         if (lifeBloom)
            {
                if (proj.minion)
                {
                    if (Main.rand.Next(4) == 0)
                    {
                        player.statLife += 3;
                        player.HealEffect(3);
                    }
                }
            }
        }
 
So with public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit), is it possible to check the type of damage the projectile does? I thought maybe something like this would work, but it gave me errors of course.

Code:
public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit)
        {
         if (lifeBloom)
            {
                if (proj.minion)
                {
                    if (Main.rand.Next(4) == 0)
                    {
                        player.statLife += 3;
                        player.HealEffect(3);
                    }
                }
            }
        }
Could you show the error it's throwing?
 
Back
Top Bottom