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

How do i make it so that for an accessory, on being hit you explode? I am assuming that i could make a custom bomb projectile and spawn it in with postHit, and just have it have a time of 1 so that on its death it explodes, but is there a way to make it so upon hit it produces a nonharmful explosion?
 
How do i make it so that for an accessory, on being hit you explode? I am assuming that i could make a custom bomb projectile and spawn it in with postHit, and just have it have a time of 1 so that on its death it explodes, but is there a way to make it so upon hit it produces a nonharmful explosion?
Inside Providing Help for Accessories by Berberborscing...

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TAPI;
using Terraria;
namespace InternalModName.Items //replace InternalModName with the internal name of your mod
{
public class ItemName : ModItem //replace ItemName with the name of your accessory
{
public override void Effects(Player p) //Where it says "p" is the variable used to represent "player". In this case, every p stands for player. This is called when the accessory is on.
{
p.noFallDmg = true; //This is where an effect from the list goes.
}
public override void DamageNPC(Player p, NPC n, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult) //This is called when the player attacks an NPC
{
p.statLife += 5; //any effect goes here, this gives the player 5 life upon attack of any NPC
}
public override void DamagePlayer(NPC n, Player p, int hitDir, ref int damage, ref bool crit, ref float critMult) //This is called when the player is damaged by an NPC
{
p.panic = true; //This would give the player the panic buff when hit by the NPC
}
}
}

The public override void DamagePlayer(NPC, Player, ref int, ref bool, ref float) is the one you are looking for.

To make a non harmful explosion, I recommend you to make a transparent projectile with the Bunny Cannonball AI (AI style of 49) and have it at around maybe 64x64 (A little bit bigger than a player). Sort of like this.

Explosion.JSON
Code:
{
    "displayName": "Explosion",
    "size": [64, 64],
    "aiStyle": 49,
    "timeLeft": 60,
    "friendly": true,
    "hostile": false,
    "tileCollide": false,
    "ignoreWater": true,
    "penetrate": -1,
}

And in your accessory, you probably want it something like this...

Accesory CS
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace InternalModName.Items
{
    public class AccessoryName : ModItem
    {
        public override void DamagePlayer(NPC n, Player p, int hitDir, ref int damage, ref bool crit, ref float critMult)
        {
            Projectile.NewProjectile(p.Center.X - 32, p.Center.Y - 32, 0, 0, "InternalModName:Explosion", 60, 10, Main.myPlayer); //Maybe switch Main.myPlayer to item.owner?
            //I'm just approximating the position of the projectile... As just setting the projectile to p.Center does not work. Projectile's position is determined by the top left corner of the texture I beleive...
        }
    }
}
 
  • Like
Reactions: Azu
So I have no idea where to ask this but where should I go if I need help with spriting? I'm assuming the W.I.P page but still kinda unsure.
If you need help with spriting I would go to the general mod discussion section, its a good place to post requests and things like that, also once I get some free time I may be able to help you sprite.
 
If you need help with spriting I would go to the general mod discussion section, its a good place to post requests and things like that, also once I get some free time I may be able to help you sprite.
Alright thank you for the information. And I would appreciate any help mainly spriting, lets just say it's not my strong suit.
 
is there any code that gets called when you switch off an item in your inventory slot? like say I have an item in slot 1, is there something I can do to make the code activate when I switch to another slot (2,3,4 etc)?
 
Ok, I need a serious CS coder at the moment! Just need to ask questions! Anyone willing to help please?
 
is there any code that gets called when you switch off an item in your inventory slot? like say I have an item in slot 1, is there something I can do to make the code activate when I switch to another slot (2,3,4 etc)?
There is no event to listen for as far as I'm aware. But it shouldn't be too difficult to implement. I would use a nullable byte to store the currently selected item. Then have code run each update, if your variable is null, you store the currently selected slot to your variable. If your variable is not null, you compare its value to the currently selected item slot. If the two are equal, do nothing. If they differ, run your code, then store the newly selected item slot to your variable.
Code:
private byte? _previouslySelectedItem;

public override Update() {

    if (_previouslySelectedItem == null) {

        _previouslySelectedItem = Main.localPlayer.selectedItem;

    } else if (_previouslySelectedItem != Main.localPlayer.selectedItem) {

        SlotSwitched(); // Your custom code;
        _previouslySelectedItem = Main.localPlayer.selectedItem;

    }

}
You may need to handle some special cases carefully. Such as when the player's inventory is open and the mouse cursor is holding an item. At that time it's the currently selected slot. If that case should be avoided, test for Main.localPlayer.selectedItem == 58 (I believe that's the right number), and if so set _previouslySelectedItem to null. Then when there's no longer a mouse item the Update() function will just reset itself to the currently selected slot.
Ok, I need a serious CS coder at the moment! Just need to ask questions! Anyone willing to help please?
If you have a few questions you may PM me and I'll do my best to answer in a timely manner. But if you think the solution may be useful for others to see as well, then you can ask the question in this thread.
 
i'm a good C# programmer but i don't understand a thing of deobfuscate terraria source code can you help me understanding the deobfuscate code ???? [maybe starting a coversation between us would be better]
Sorry are you talking to me or @Neojin ?

:D
 
Back
Top Bottom