tAPI Getting Started with Modding

Status
Not open for further replies.
How do I make projectiles have frames?
In the projectile's image file, draw the frames vertically next to each other, making sure that each frame has the exact same height. Then use the "frameCount" property in the projectile's .json file to let the program know how many frames the image represents. Finally, to change the projectile's frame, do stuff like
Code:
projectile.frame = 0; //for the first frame
projectile.frame = 1; //for the second frame
//etc.
 
Whenever you get your mod to successfully build, but it crashes when trying to load, then most likely there's either a crash occurring in a .cs file or you forgot to name an image file after an item file. So there can't be any problem with the .json.
Edit: This isn't the problem, but just to avoid future problems, if your file name is called Rune_bolt, then the .cs class name has to follow the same capitalization. Also, you're making sure to both rebuild and reload your mod after every thing you try, right? I forget to do that sometimes.
Yeah, I've been removing and rebuilding it every time. I tried it without the .cs file, and it didn't work that time either. Does it require the .cs file to run, or would it work without it if that was the problem?
 
In the projectile's image file, draw the frames vertically next to each other, making sure that each frame has the exact same height. Then use the "frameCount" property in the projectile's .json file to let the program know how many frames the image represents. Finally, to change the projectile's frame, do stuff like
Code:
projectile.frame = 0; //for the first frame
projectile.frame = 1; //for the second frame
//etc.

What hook do I put that in and don't I have to input the frame speed?
 
Yeah, I've been removing and rebuilding it every time. I tried it without the .cs file, and it didn't work that time either. Does it require the .cs file to run, or would it work without it if that was the problem?
Hm, this is weird. Items, projectiles, and those kinds of things don't require .cs files to run; .cs files just essentially add extra stuff to them. At the moment, the only thing I can think of is maybe a slight typo/capitalization error in the file names, but you've already checked over all of that.
Actually, do you have a class that overrides ModBase? I remember some stuff require the existence of a ModBase class to work, but I don't remember exactly what.
What hook do I put that in and don't I have to input the frame speed?
You'll basically put that in the AI method. There is no frame speed, because you need to change projectile.frame manually yourself. You can use projectile.frameCounter to keep track of how long the current frame has been lasting. So a simple animation would go something like this:
Code:
projectile.frameCounter++;
if(projectile.frameCounter >= 5) //replace this number with how many ticks one frame should last
{
    projectile.frame++;
    projectile.frame %= 5; //replace this number with how many frames there are
    projectile.frameCounter = 0;
}
 
Hm, this is weird. Items, projectiles, and those kinds of things don't require .cs files to run; .cs files just essentially add extra stuff to them. At the moment, the only thing I can think of is maybe a slight typo/capitalization error in the file names, but you've already checked over all of that.
Actually, do you have a class that overrides ModBase? I remember some stuff require the existence of a ModBase class to work, but I don't remember exactly what.
What I posted is what is in the mod, there's literally those two items with images, a projectile with an image, the modinfo, and the .cs file which I already removed.
 
What I posted is what is in the mod, there's literally those two items with images, a projectile with an image, the modinfo, and the .cs file which I already removed.
In that case, try adding a .cs file named after your mod, and make it a subclass of TAPI.ModBase. Not really sure if this will work, but it's worth a try.
 
Thank you sooo much! Now I can start modding over summer break and weekends! This is amazing, I've always wanted my own mod :joy:
 
What method do I have to use to spawn a tile? I'm making a projectile that's supposed to spawn a block of thin ice when it hits water.
 
What method do I have to use to spawn a tile? I'm making a projectile that's supposed to spawn a block of thin ice when it hits water.
You'd have to do something along these lines:
Code:
int x = (int)(projectile.Center.X / 16f);
int y = (int)(projectile.Center.Y/ 16f);
Main.tile[x, y].type = /*insert tile ID here*/;
Main.tile[x, y].active(true);
Main.tile[x, y].liquid = 0;
if (Main.netMode == 2)
{
    NetMessage.SendTileSquare(-1, x, y, 1);
}
else
{
    WorldGen.SquareTileFrame(x, y, true);
}
 
You'd have to do something along these lines:
Code:
int x = (int)(projectile.Center.X / 16f);
int y = (int)(projectile.Center.Y/ 16f);
Main.tile[x, y].type = /*insert tile ID here*/;
Main.tile[x, y].active(true);
Main.tile[x, y].liquid = 0;
if (Main.netMode == 2)
{
    NetMessage.SendTileSquare(-1, x, y, 1);
}
else
{
    WorldGen.SquareTileFrame(x, y, true);
}
That works, thanks. How do I detect which liquid it is? Would it be Main.tile[x,y].liquidType?
 
That works, thanks. How do I detect which liquid it is? Would it be Main.tile[x,y].liquidType?
Yup, it looks like Main.tile[x,y].liquidType() should work. And if you don't want to remember the number for each liquid type, you can use Main.tile[x,y].lava(), Main.tile[x,y].honey(), and Main.tile[x,y].water(). Unfortunately, it also looks like all tiles without liquid are actually treated as having water with a volume of 0, so I'm not sure how to detect whether or not there actually is liquid yet.
 
How do I make dust ignore lighting? I could have sworn it was Main.dust[DustID].ignoreLighting = true;
 
How do I make dust ignore lighting? I could have sworn it was Main.dust[DustID].ignoreLighting = true;
If you mean how to make it display in its full color and brightness regardless of lighting, I usually just use Main.dust[DustID].OverrideLightColor = Color.White. (I haven't bothered to find out whether there's a better way yet.)
 
Okay, let me ask some newbie questions:
1. Is Defense a Signed or Unsigned number? Can I go negative with defense of say, an accessory?
2. In this situation:
[{
"items": { "Light Shard": 1, "Dark Shard": 1, "Soul of Sight": 20. "Mana Crystal":2 },
"tiles": [ "Mythril Anvil","Orichalcum Anvil" ],
"creates": 1
}]

Will the "Tiles" function work, even though there are more than one tile that can be used to make this item? Thanks.
 
1. Is Defense a Signed or Unsigned number? Can I go negative with defense of say, an accessory?
It's signed - with Ichor, zero defense enemies can go into the negative.
2. In this situation:
[{
"items": { "Light Shard": 1, "Dark Shard": 1, "Soul of Sight": 20. "Mana Crystal":2 },
"tiles": [ "Mythril Anvil","Orichalcum Anvil" ],
"creates": 1
}]

Will the "Tiles" function work, even though there are more than one tile that can be used to make this item? Thanks.
If I'm not mistaken, that would force the player to have both a Mythril and Orichalcum anvil to craft it. By putting just "Mythril Anvil" tAPI automatically lets you use both HM anvils.
 
It's signed - with Ichor, zero defense enemies can go into the negative.

If I'm not mistaken, that would force the player to have both a Mythril and Orichalcum anvil to craft it. By putting just "Mythril Anvil" tAPI automatically lets you use both HM anvils.
Not sure if I got it right, so let me clarify (mostly to myself): Can I assign a negative value to an accessory's defense property? Thanks though! Helps a ton.
 
Not sure if I got it right, so let me clarify (mostly to myself): Can I assign a negative value to an accessory's defense property? Thanks though! Helps a ton.
I believe so, yes. If not, you can use the .cs file to reduce the players defence, because I know that in-game, and entity's defence can be negative.
 
I believe so, yes. If not, you can use the .cs file to reduce the players defence, because I know that in-game, and entity's defence can be negative.
Thanks for the help!

Edit: I need help again. I'm creating a cooldown debuff. Is there a way to check if player p doesn't have Debuff "x"?
 
Last edited:
Status
Not open for further replies.
Back
Top Bottom