• Console & Mobile Terrarians - news for 1.4.4.9! iOS and Android 1.4.4.9 out now. PS and Xbox should be very soon. Switch and Amazon are in submission. Great way to end the year - everyone on the same version of Terraria! More details HERE.

Terraria Community Forums

W1K
W1K
Check the example mod, ExampleGlobalNPC in the NPCs folder, the SetupShop method near the bottom of the file.
Everybody
Everybody
@W1K yeah, I got it a bit ago. I'm trying to figure out how to make NPC's now (Town and enemy).
Everybody
Everybody
@W1K do you know how to make an accessory that triggers an effect on player hit or on enemy hit? Do you have any sample code?
W1K
W1K
I've never made a town NPC myself, but I assume the method should work roughly the same way. Otherwise I'm sure there's a town NPC example in the example mod too.
W1K
W1K
For the accessory, I'm not sure whether tModLoader has any easier way, but the way I do it is a bit tricky for newbs and it involves a global player code checking whether any player is equipping X item when specific methods are called (for example, I have an armor that deals damage in an area every time the Hurt method in global player is called, but only runs the code if they have the full armor set equipped).
Everybody
Everybody
@W1K do you have example of that code? It goes in the .cs of the actual mod, right?
W1K
W1K
No, it would go in a different .cs file in the mod's root folder (the same folder where the mod's main .cs file is). This code is untested but roughly what it should look like for a global code that checks whether an accessory is equipped and run an effect on the event of the player getting damaged.
https://puu.sh/xoTnf/f4b355699f.txt
W1K
W1K
Everybody
Everybody
I tried an OnHitPlayer hook but it told me something about nothing to override.
Top Bottom