TConfig I need help with some Coding.

Discussion in 'Released Mods' started by Geohexamon, Nov 27, 2012.

  1. Geohexamon

    Geohexamon Green Slime

    I really need help. I've tried my best to no avail. Basically I'm trying to make a mod that adds an item that shoots a projectile which costs 2oo mana to use, takes out 5000 points of damage, as the projectile goes through tiles it destroys the tiles, explodes after hitting and removing 25 tiles, and you can't use it again for 24 minutes via buff. I'm calling it the Hadoken mod.

    So far I got it so that it cost's the 200 mana and shoots the projectile which takes out 5000 HP. All being done inside the .ini file.

    The problem I'm having is everything I haven't done yet. Specifically making it so the buff happens when you use the item. I'm not used to C#, but I know a little Java. If someone knows how to make this work or at least can tell me what they know it would be most appreciated.
  2. Yoraiz0r

    Yoraiz0r The Wizard

    code wise , here's some facts.
    terraria has an object type 'Tile'.
    terraria keeps the current played world as a 2d array of tiles , named 'tile' under Main class , so to reference a tile you write 'Main.tile[x,y]' where x and y are the coordinates.
    terraria is set up so that each tile takes up 16 pixels , and the game is scaled in a ratio of 1 distance unit per pixel , meaning objects tile position coordinates can be calculated by 'object.position.X/16' for example , rounded down.
    terraria Tile objects have a property 'active' , it is a boolean that if set to false , makes it so the tile is air.
    terraria projectile objects have a property 'tileCollide' , it is a boolean that if set to false , a projectile goes through tiles.
    tConfig lets you add code subclasses to a projectile , which lets you run custom code with several hooks , the ones you look for are AI and PostKill.

    taking this knowledge , lets put things up to code...
    what we will do , is make the projectile not collide with tiles , and instead manually detect if it does , and when it does , we will remove those tiles and count up the number we removed , and when we removed enough , we blow the tile up.

    first off add this
    in your ini file for the projectile.

    secondly , add a file of a .cs type extension named the same way as your ini file , for example you'd have hadoken.ini and hadoken.cs .
    open up the cs file , and add this code inside (note that you can use notepad , its just a text file after all)
    int count = 0;
    public void PostAI()
          Vector2 startpos = projectile.position;
          Vector2 endpos = startpos + new Vector2(projectile.width,projectile.height);
          Vector2 tilesize = new Vector2(Main.maxTilesX,Main.maxTilesY);
          startpos = Vector2.Clamp(startpos,Vector2.Zero,tilesize);
          endpos = Vector2.Clamp(endpos,Vector2.Zero,tilesize);
          for(int i = (int)startpos.X; i < (int)endpos.X; i++)
              for(int j = (int)startpos.Y; j < (int)endpos.Y; j++)
                    if(Main.tile[i,j].active && Main.tileSolid[(int)Main.tile[i,j].type])
                          if(!Main.tile[i,j].active) count++; //there's a chance a tile has special code preventing its destruction , like chests , so we check for activity anyways
                          if(Main.netMode != 0 && !Main.tile[i,j].active)
                              NetMessage.SendData(17, -1, -1, "", 0, i, j, 0f, 0); //netstuff cuz you care about multiplayer even if you don't say so! >=c
          if(count >= 25)
    so far , this code will make it so after every phase of the ai , 60 times a second , all the tiles in the area covering the tile's bounding box are checked for solidness , if any of them is solid , it is destroyed (note , this makes tables and suchs be ignored , but you can freely just remove the solid condition in the code)
    if a tile is destroyed , the count is increased by 1 , and if it reaches 25 , we simply kill the tile.

    now......for killing.......
    there's two approaches you can go , I wouldn't include extra code until you explain what the explosion does exactly (is it only graphical or actually hitting anyone?)

    inb4 randomly writing walls of text......
  3. Geohexamon

    Geohexamon Green Slime

    Thank you for the help. The kind of explosion I'm looking for is the type of explosion where it destroys land in a similar fashion to TNT or something, but instead of it being as large of an explosion, I was thinking of having it be a 25% larger explosion then if you were to use TNT.

    After what you said at the beginning of the message and analyzing your code, I think I'm starting to see how Terraria works. From what I can tell, if I want an explosion to happen I think I would add code the the projectiles Kill(); method. Or am I mistaken?

Share This Page