Standalone [1.3] tModLoader - A Modding API

Sin Costan

Eye of Cthulhu
What is a static object reference thingy an error message talks about?
Usually it means that a certain thing isn't "static". What the term "static" means usually refers to things like a static variable where you can use it anywhere, sometimes it gets really confusing on what the problem is, maybe show us the error message?
 

imkSushi

Eater of Worlds
Usually it means that a certain thing isn't "static". What the term "static" means usually refers to things like a static variable where you can use it anywhere, sometimes it gets really confusing on what the problem is, maybe show us the error message?
upload_2016-3-3_22-0-44.png
 

imkSushi

Eater of Worlds
public override void Load()
{
RegisterHotKey("________", "R");
}
public override void HotKeyPressed(string name)
{
if (name == "________")
{
Player.statLife = Player.statLifeMax;
}
}
 

jopojelly

Retinazer
tModLoader
This means you are trying to change Player.statLife, which is an instance variable and not a static variable, so you'd need to reference the variable from an instance of the class, not the class name itself. Usually in the hooks an instance of the Player class is passed in and named player.

Edit: in your case, replace Player with Main.player[Main.myPlayer]
 

imkSushi

Eater of Worlds
This means you are trying to change Player.statLife, which is an instance variable and not a static variable, so you'd need to reference the variable from an instance of the class, not the class name itself. Usually in the hooks an instance of the Player class is passed in and named player.
How do I do that?
 

Iroh The Dragon

Terrarian
Im getting this error. Please help: Error Cs0103: The Name 'AddMapEntry' does not exist in the current context. Although Addmapentry does exist.

Here -

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

namespace DarkArmorReforged.Tiles
{
public class CobaltAnvil : ModTile
{
public override void SetDefaults()
{
Main.tileSolidTop[Type] = false;
Main.tileFrameImportant[Type] = true;
Main.tileNoAttach[Type] = true;
Main.tileLavaDeath[Type] = true;
TileObjectData.newTile.CopyFrom(TileObjectData.Style2x1);
TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 };
TileObjectData.newTile.CoordinateWidth = 16;
TileObjectData.newTile.CoordinatePadding = 2;
TileObjectData.addTile(Type);
adjTiles = new int[] { TileID.Anvils };
AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch);
AddMapEntry(new Color(255, 255, 255), "CobaltAnvil");
}

public override void KillMultiTile(int i, int j, int frameX, int frameY)
{
Item.NewItem(i * 16, j * 16, 48, 48, mod.ItemType("CobaltAnvil"));
}
}
}
 

Eldrazi

Eater of Worlds
Im getting this error. Please help: Error Cs0103: The Name 'AddMapEntry' does not exist in the current context. Although Addmapentry does exist.

Here -

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

namespace DarkArmorReforged.Tiles
{
public class CobaltAnvil : ModTile
{
public override void SetDefaults()
{
Main.tileSolidTop[Type] = false;
Main.tileFrameImportant[Type] = true;
Main.tileNoAttach[Type] = true;
Main.tileLavaDeath[Type] = true;
TileObjectData.newTile.CopyFrom(TileObjectData.Style2x1);
TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 };
TileObjectData.newTile.CoordinateWidth = 16;
TileObjectData.newTile.CoordinatePadding = 2;
TileObjectData.addTile(Type);
adjTiles = new int[] { TileID.Anvils };
AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch);
AddMapEntry(new Color(255, 255, 255), "CobaltAnvil");
}

public override void KillMultiTile(int i, int j, int frameX, int frameY)
{
Item.NewItem(i * 16, j * 16, 48, 48, mod.ItemType("CobaltAnvil"));
}
}
}
Have you installed tModLoader correctly? I've just copy+pasted that code and it worked fine. Try reinstalling tModLoader and try again.
 

Casual_Bean

Slime Collector
I just tried with ExampleMod and it works. Can you tell me more about what mod and npc cause the problem?
well, this mod has an npc named ed the custom weapon developer. i didnt want him in my world, so i disable the mod, and i went back to my world and it said "load backup?"
So i did that, but it failed to load the backup.( then i realized it was the mod true eternity that causes the worlds to fail loading)
 

Lolkat

Skeletron Prime
How would one go about making an NPC spawn additional NPCs every few seconds, say, an NPC spawning another modded NPC every 5 seconds?
 

Sin Costan

Eye of Cthulhu
How do I make something happen for 10 seconds?
Depends on what is causing the thing to happen for 10 seconds.

How would one go about making an NPC spawn additional NPCs every few seconds, say, an NPC spawning another modded NPC every 5 seconds?
Using npc's "npc.ai" variables helps with this, so you would probably do something like this with your NPC.

Code:
public override void AI()
{
    if(npc.ai[0] == 360) //we can also do if (npc.ai[0] % 360 ==0)
    {
       NPC.NewNPC(//Stuff in here, too lazy to fill in);
       npc.ai[0] = 0; //if we do the other way, then you wouldn't need this
    }
    npc.ai[0] += 1f;
}
 
Last edited:

Lolkat

Skeletron Prime
Depends on what is causing the thing to happen for 10 seconds.


Using npc's "npc.ai" variables helps with this, so you would probably do something like this with your NPC.

Code:
public override void AI()
{
    if(npc.ai[0] == 360) //we can also do if (npc.ai[0] % 360 ==0)
    {
       NPC.NewNPC(//Stuff in here, too lazy to fill in);
       npc.ai[0] = 0; //if we do the other way, then you wouldn't need this
    }
    npc.ai[0] += 1f;
}


Code:
        public override void AI()
        {
            if(npc.ai[87] % 360 ==0)
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("notimportant"));
            }
            npc.ai[87] += 1f;
        }

So I'm trying to get it to use the crimson mimic AI by default instead of 0, but this causes it not to spawn anymore. I probably missed something, I'm not to experienced with AI stuff.
 

Sin Costan

Eye of Cthulhu
Code:
        public override void AI()
        {
            if(npc.ai[87] % 360 ==0)
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("notimportant"));
            }
            npc.ai[87] += 1f;
        }

So I'm trying to get it to use the crimson mimic AI by default instead of 0, but this causes it not to spawn anymore. I probably missed something, I'm not to experienced with AI stuff.
Try using PostAI() instead of just AI() it could work since it is called after vanilla code.
[DOUBLEPOST=1457133899,1457133583][/DOUBLEPOST]
Try using PostAI() instead of just AI() it could work since it is called after vanilla code.
Actually I just saw why it doesn't work, there are only, I believe, 4 places ai can store those being
Code:
npc.ai[0]
npc.ai[1]
npc.ai[2]
npc.ai[3]

You need to choose one of those slots unless you increased the amount of npc.ai slots. I would recommend that you go through them all because there is a chance that some or all of these npc.ai are already being used by the Crimson Mimic AI.
 
Top Bottom