tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
I have a question. (I am using r11)
I want to have double Loot for every monster (including Vanilla)
But when I use the PostNPCLoot() hook, I do not have the monster object.
Am I correctly using PostNPCLoot() ? Or should I use other hook?
 
I have a question. (I am using r11)
I want to have double Loot for every monster (including Vanilla)
But when I use the PostNPCLoot() hook, I do not have the monster object.
Am I correctly using PostNPCLoot() ? Or should I use other hook?

If you wanna implement double monster loot, you should probably create a GlobalNPC then override PostNPCLoot(), and the monster object is in the class already, just reference it with npc. For example:

Code:
[GlobalMod]
    public class GlobalNPC : ModNPC
    {
        //How much more loot we should get, implemented so we don't get an infinite loop of NPCLoot() calling PostNPCLoot(), which calls NPCLoot() again
        int xmoreLoot = 1;

        public override void PostNPCLoot()
        {
            if (xmoreLoot > 0)
            {
                xmoreLoot--;
                npc.NPCLoot();
            }
        }
    }

This is just how I would do it, but if there is a better method somebody please let me know. :)
 
Last edited:
Thanks a lot, I just don't know the reference.
Apart from this, I just wonder how to find those variables name. Also, if I call PreNPCLoot() inside PostNPCLoot(), will it call all the PreNPCLoot() from the other mod, or just call the one in my mod? If I want to call PreNPCLoot() from all other loaded mod, how can I do? Call base.PreNPCLoot()??
 
Thanks a lot, I just don't know the reference.
Apart from this, I just wonder how to find those variables name. Also, if I call PreNPCLoot() inside PostNPCLoot(), will it call all the PreNPCLoot() from the other mod, or just call the one in my mod? If I want to call PreNPCLoot() from all other loaded mod, how can I do? Call base.PreNPCLoot()??
no... just no... don't do this. Do not call either of these hooks from within the other one, you will cause a circular reference issue and break things.

Let me explain:
PreNPCLoot() should be used to modify all NPC loot globally BEFORE the NPC loot is calculated.
e.g. - I want to remove coins from all NPC drops in the game.

PostNPCLoot() should be used globally to adjust the loot that has already been calculated and dropped.
e.g. - I want to add a torch to every NPC drop in the game
 
Last edited:
I just found that my PostNPCLoot() doesn't get called.
Code:
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Terraria;

using TAPI;

namespace ATest
{
    public class GlobalNPC : TAPI.ModNPC
    {
        public override void PostNPCLoot()
        {
            Main.NewText("A1", 255, 25, 25, false);
        }
    }
}
 
I just found that my PostNPCLoot() doesn't get called.
Code:
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Terraria;

using TAPI;

namespace ATest
{
    public class GlobalNPC : TAPI.ModNPC
    {
        public override void PostNPCLoot()
        {
            Main.NewText("A1", 255, 25, 25, false);
        }
    }
}
You forgot your [GlobalMod] attribute, put it right above your class declaration like this-
Code:
[GlobalMod]
public class GlobalNPC : ModNPC
{
    //Code here
}
 
Great work for the new release! But can anybody help me to code mods? I tryed TheHuckleberryWill and it didn't work. His tutorials are for R5, and I think that may be the problem, as I was using R10 last time I tryed. Could someone help me, I generally need help with everything. Or could someone tell me how to get Tapi R5? Thanks.
 
Some bugs for R11:
1. clicking loot all from piggy bank will sometimes crash the game
2. When I right click on the Old Man on the surface, the Dungeon Guardian appear...
 
I've worked a bit with the release now and it's great. The new hooks are so useful.
I only have one problem: How would I generate a fixed structure? Let's say, I want to create my own underground houses when creating a new world, how would I code that? Also, where would I put it? Is there a global world file?
 
I've worked a bit with the release now and it's great. The new hooks are so useful.
I only have one problem: How would I generate a fixed structure? Let's say, I want to create my own underground houses when creating a new world, how would I code that? Also, where would I put it? Is there a global world file?
Use the ModWorld.ModifyWorldGenTasks (or something like that) hook to add a task to the task list.

DO NOT do the generation stuff there, but create a custom WorldGen task.
 
Use the ModWorld.ModifyWorldGenTasks (or something like that) hook to add a task to the task list.

DO NOT do the generation stuff there, but create a custom WorldGen task.
Alright, got it. Though I still don't know how I'd do the generation itself. Has anyone done this yet?
 
Alright, got it. Though I still don't know how I'd do the generation itself. Has anyone done this yet?
That completely depends on what you want to do.

General rule:
1. get the X and Y position of the tile you want to modify
2. use:
Code:
    Main.tile[X, Y].active = true | false;
    Main.tile[X, Y].type   = TileDef.tile[<tile name>];
    Main.tile[X, Y].wall   = TileDef.wall[<wall name>];
or a combination of them.
 
That completely depends on what you want to do.

General rule:
1. get the X and Y position of the tile you want to modify
2. use:
Code:
    Main.tile[X, Y].active = true | false;
    Main.tile[X, Y].type   = TileDef.tile[<tile name>];
    Main.tile[X, Y].wall   = TileDef.wall[<wall name>];
or a combination of them.
Thanks! I'll play around with that.
 
Some bugs for R11:
1. clicking loot all from piggy bank will sometimes crash the game
2. When I right click on the Old Man on the surface, the Dungeon Guardian appear...
After testing these issues, I am unable to reproduce either in base tAPI. Try disabling all mods and attempting these things again and they are not an issue. Perhaps there is a mod interacting with them somehow?
 
Last edited:
Could somebody help me, I've got a problem. I followed TheHuckleberryWill's basic item tutorial, and already something's gone wrong. A screenshot of the error and my code will be provided with this post. Please ignore the titles of the screenshot files and the caps in the title of the files as well. Thanks.
 

Attachments

  • SCREENSHOT THREE.PNG
    SCREENSHOT THREE.PNG
    37.5 KB · Views: 263
  • SCREENSHOT UN DEUX.PNG
    SCREENSHOT UN DEUX.PNG
    34.5 KB · Views: 251
  • SCREENSHOT.PNG
    SCREENSHOT.PNG
    50.3 KB · Views: 296
Could somebody help me, I've got a problem. I followed TheHuckleberryWill's basic item tutorial, and already something's gone wrong. A screenshot of the error and my code will be provided with this post. Please ignore the titles of the screenshot files and the caps in the title of the files as well. Thanks.
You must rename Item into Items
 
Status
Not open for further replies.
Back
Top Bottom