tAPI tAPI Community Resources - Development assistance for developers, by developers.

In your tiles cs file try -
Code:
public override bool TileFrame(int x, int y) {
   
    if (Main.tile[x, y + 1] != null && !Main.tile[x, y + 1].active()) {
       
        Main.tile[x, y].active(false);
        int damage = 10; // Or whatever
        int type = yourCustomProjectileType;
        Projectile.NewProjectile((float)(x * 16 + 8), (float)(y * 16 + 8), 0f, 0.41f, type, damage, 0f, Main.myPlayer, 0f, 0f);
        WorldGen.SquareTileFrame(x, y);
       
    }
   
    return false; // Might try true as well to see which works better
   
}
Its strange, while this method works, it only seems to work with vanilla projectiles, it won't spawn mine.
Well, I may be stupid, or lazy, but is there just a way to make the projectile die when it meets your cursor? Or, if you don't know that, is there a way to make it so you can place a tile in midair?
There is likely some way to do it, whether or not I know of that way is the question, unfortunately I don't know of an easy way to do this.( or a hard way for that matter)
 
question, how would one accomplish the whole, OnTileCollide place this block? Is it something like, tile.newTile? If so, it would be greatly appreciated if you could post the string to accomplish this
int xPos => X Position in Tile Coordinates
int yPos => Y Position in Tile Coordinates
int tileType => ID of the tile to place
bool mute => If true do not play sound and do not create dust. Default is false
bool forced => If true override current tile. Default is false
int player => The ID of the player placing the tile. Used to determine the players direction when placing a directional tile. Default is -1, no player direction check.
int tileStyle => The style of tile to place. All banners are tile ID 91. The style is what determines which one is created. Default is 0.

WorldGen.PlaceTile(xPos, yPos, tileType, mute, forced, player, tileStyle);
Thanks! just one more question, in the line "int type = myprojectile;" would I have to type something like "projdef.byName["my projectile"] to make it work with my custom projectile?
ProjDef.byName["InternalModName:ProjectileName"].type is what you would use.
most likely, that's what it seems like you would need to do... there may be a different method, however
[DOUBLEPOST=1431388396,1431388263][/DOUBLEPOST]
or even better, as I'm not sure that ProjDef.byname could be converted to an integer, you may just want to go into the line
Code:
 Projectile.NewProjectile((float)(x * 16 + 8), (float)(y * 16 + 8), 0f, 0.41f, type, damage, 0f, Main.myPlayer, 0f, 0f);
and replace the type, with ProjDef.byname["myprojectile'sname"].type
byName is a IDictionary<string, Projectile>. You provide a string, and a projectile is returned. Adding '.type' to the end would indeed return the projectiles type.
I found some code for that awhile ago on either the Tapi page or another modding help page, however it was for turning liquids into a tile when the projectile hit it, I edited it a bit, so it should work but I haven't tested it with this method of giving gravity to blocks, but here it is anyway
Code:
        public override void PostKill()
        {
     int x = (int)(projectile.Center.X / 16f);
int y = (int)(projectile.Center.Y/ 16f);
Main.tile[x, y].type = TileDef.byName["Ardium:ScarredSand"];
Main.tile[x, y].active(true);
if (Main.netMode == 2)
{
    NetMessage.SendTileSquare(-1, x, y, 1);
}
else
{
    WorldGen.SquareTileFrame(x, y, true);
I give full credit to bluemagic for this code.
I would use this when transforming one active tile into another, and WorldGen.PlaceTile when placing a tile into an empty spot. I use something similar to the code you showed to transform a Closed Hatch tile into an Open Hatch tile and back, but use PlaceTile when first placing the tile.
Well, I may be stupid, or lazy, but is there just a way to make the projectile die when it meets your cursor? Or, if you don't know that, is there a way to make it so you can place a tile in midair?
Main.mouseWorld returns the mouses position in the world as a Vector2. You can compare that to the projectiles position.
 
Main.mouseWorld returns the mouses position in the world as a Vector2. You can compare that to the projectiles position.
Yes, but is there a code like projectile.kill? or projectile.active = false?

I'm thinking something long the lines of, if(projectile.position.X == Main.mouseWorld.X && projectile.positon.Y == Main.mouseWorld.Y)
{
kill it here?
}
 
Yes, but is there a code like projectile.kill? or projectile.active = false?

I'm thinking something long the lines of, if(projectile.position.X == Main.mouseWorld.X && projectile.positon.Y == Main.mouseWorld.Y)
{
kill it here?
}
projectile.Kill(); is correct
 
alright, I got it to work, now I have an even stupider question, is there any way to kill a tile after a set amount of time? (I know how to do a timer)
 
alright, I got it to work, now I have an even stupider question, is there any way to kill a tile after a set amount of time? (I know how to do a timer)
Int xPos
Int yPos
Bool fail => If true don't actually kill the tile, default is false
Bool effectOnly => If true show effects but don't kill the tile, default is false
Bool noItem => If true don't drop an item, default is false

WorldGen.KillTile(xPos, yPos, fail, effectOnly, noItem);
 
I need help cause this is beyond my current (read little) programming knowledge.

I'm wanting to make an ability for a sword(s) that has a damaging dash attack towards the cursor akin to the Master Ninja Gear, preferably assigned to the right mouse button, and makes you take 40% less damage during the dash.

(I kinda went in over my head on this. :sigh:
 
I'm sorry if someone already asked this, but how can I add a button to the player creation screen?
 
I need help cause this is beyond my current (read little) programming knowledge.

I'm wanting to make an ability for a sword(s) that has a damaging dash attack towards the cursor akin to the Master Ninja Gear, preferably assigned to the right mouse button, and makes you take 40% less damage during the dash.

(I kinda went in over my head on this. :sigh:
I was thinking about that, I'm not sure how to do a right click, but I think that you could do the dash with projectiles... and a bit of player position manipulation... something like, make the player's new position 200 pixels to the right, and have it spawn a 200 pixel long projectile that does damage, looks like someone dashing and lasts for 5 seconds the projectile could look something like
Ninjadash.png
 
Last edited:
Hello once again!

Does anyone know how to make mounts? :)

Thanks again!
 
I was thinking about that, I'm not sure how to do a right click, but I think that you could do the dash with projectiles... and a bit of player position manipulation... something like, make the player's new position 200 pixels to the right, and have it spawn a 200 pixel long projectile that does damage, looks like someone dashing and lasts for 5 seconds

You can do this by creating an events argra for on right click. After this, you can use something like Cursor.Position and make the player move towards it. This isn't a very professional method of reducing the damage, but you can also calculate the players defense and add 40% to it (Make sure to change it back after the dash) You could use the code for the master ninja gear by coping it into your item, or you could see if it triggers a variable (i.e. InDase = true) and do the same thing. You can also set the player speed equal to a certain value like in the dash and create particles using a thread in the op.

EDIT: Use Main.mouseWorld for cursor position.
 
Hello once again!

Does anyone know how to make mounts? :)

Thanks again!
Currently undoable, sorry, as it seems to be a buff, with a mount attached, kind alike a minion but allows you to do other things, but anyway, it hasn't been added in tAPI yet
 
Currently undoable, sorry, as it seems to be a buff, with a mount attached, kind alike a minion but allows you to do other things, but anyway, it hasn't been added in tAPI yet
Noooooo! Thanks for your quick reply.
 
I seem to be having trouble with a bit of worldgen, I'm trying to get an ore to generate only in the ocean biome, so would something like Main.rand.Next((int)oceanBG, 0) for the minX and maxX? or, rather than oceanBG, should I do areaWater?

TLDR: is there something like Main.hellLayer that I can use for the ocean? To make and ore only generate there, and to make mobs that only spawn there
 
I seem to be having trouble with a bit of worldgen, I'm trying to get an ore to generate only in the ocean biome, so would something like Main.rand.Next((int)oceanBG, 0) for the minX and maxX? or, rather than oceanBG, should I do areaWater?

TLDR: is there something like Main.hellLayer that I can use for the ocean? To make and ore only generate there, and to make mobs that only spawn there
You want to target tiles to the far left and the far right of the world, at and above the World Surface layer.

If you have a tile position of (x, y)
You're in an ocean biome -
Code:
if (y < Main.worldSurface + 10) {
    if (x < 380 || x > Main.maxTilesX - 380) {
        // I'm in an Ocean Biome
    }
}

For Ore Generation something like -
Code:
int xPos; // X Coordinate to generate ore
int yPos; // Y Coordinate to generate ore
int side = Main.rand.Next(2); // Which side of the world to generate on

if (side == 0) { // Left Side of the world
    xPos = Main.rand.Next(10,380); // Lowest random number is 10 so we're not too close to the world boundary
} else { // Right Side of the world
    xPos = Main.rand.Next(Main.maxTilesX - 380, Main.maxTilesX - 10); // Not to close to the right side world boundary
}

yPos = Main.rand.Next(10, Main.worldSurface + 10); // Somewhere above the world surface could limit this to (Main.worldSurface - 50, Main.worldSurface + 10)

int safetyCount = 0; // Safety Counter to prevent infinite loop.
while (!Main.tile[xPos, yPos].active() || Main.tile[xPos, yPos].type != 53) { // Keep trying different locations till you find a Sand tile
    
    if (side == 0) {
        xPos = Main.rand.Next(10,380);
    } else {
        xPos = Main.rand.Next(Main.maxTilesX - 380, Main.maxTilesX - 10); 
    }
    
    yPos = Main.rand.Next(10, Main.worldSurface + 10);
    
    safetyCount++; // Increment Safety Counter

    if (safetyCount > 250) { // Try 250 times, or 500, or 1000, or 50, however determined you are for it to generate
        return;
    }

}

// Generate ore at (xPos, yPos)
 
I'm pretty sure I've asked this before, but is there a way that anyone knows of to make a projectile "die" when it reaches your cursor?

something like if(projectile.center.X == Main.mouseWorld.X && projectile.center.Y == Main.mouseWorld.Y)
{
kill it here;
}
 
I'm pretty sure I've asked this before, but is there a way that anyone knows of to make a projectile "die" when it reaches your cursor?

something like if(projectile.center.X == Main.mouseWorld.X && projectile.center.Y == Main.mouseWorld.Y)
{
kill it here;
}
Change Kill It Here To
Code:
projectile.kill
Im Not Sure That Is Correct Though
 
projectile.Kill();
well, I know how that works (thanks so much though!), mostly what I was wondering was, would the projectile and mouse position work?
 
Back
Top Bottom