tModLoader Check my Accessory & ModPlayer code

RADICALAdrift

Official Terrarian
Hi there,

I've had someone help me with this on the tModLoader discord but it doesn't seem to be working though i get no errors when compiling so im confused

Accessory code: hastebin
ModPlayer code: hastebin
 
It looks correct, to further test it try removing the random chance and see if it does anything. Chance PreHurt to this code below. What this does is remove the random chance from seeing if the accessory works, as well as outputting a message in game. You'll see the message if it worked correctly.

Code:
        public override bool PreHurt(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
        {
            if (dodgeAccessory) {
            Main.NewText("Effect has activated", 175, 75, 255, false);
            return false;
            }
            return true;
        }
 
It looks correct, to further test it try removing the random chance and see if it does anything. Chance PreHurt to this code below. What this does is remove the random chance from seeing if the accessory works, as well as outputting a message in game. You'll see the message if it worked correctly.

Code:
        public override bool PreHurt(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
        {
            if (dodgeAccessory) {
            Main.NewText("Effect has activated", 175, 75, 255, false);
            return false;
            }
            return true;
        }
Well that answers of it works or not i guess lol
1650974215215.png
 
Yeah so there you go, now just revise the code to make it a percent chance of working, like you had before, and leave the NewText line in to debug it if you have any issues.
 
So i guess like how i had it with "Main.rand.NextFloat() < 0.8f)" yeah unless there is a better method to use and i suppose i could leave the text line there till i know its working and i have the right percentage
 
honestly i don't know why but when i thought of dodging i thought it would literally make me dodge but i guess it works in a different way and i guess i would do a similar thing if i wanted to do a thorns effect for example as that was an accessory idea i got from someone
 
The way you have the code, when you return false, your character won't get hit based on whatever would have hit them at the moment. You should consider changing the immunity time as well otherwise it'll just trigger over and over as they are constantly making contact with the NPC and / or projectile.

If you mean a dodge like the player character actually moving out of the way, it's more complex but you can do that as well.
 
Yeah ill have a look later about the immunity time which should be easy to add if i had to guess and depending on how complex it is i might consider the movement though some may find it annoying to have their character randomly move,
+ best part is when the update is ready i can just comment out the "effect has activated" line instead of removing it
 
The way you have the code, when you return false, your character won't get hit based on whatever would have hit them at the moment. You should consider changing the immunity time as well otherwise it'll just trigger over and over as they are constantly making contact with the NPC and / or projectile.

If you mean a dodge like the player character actually moving out of the way, it's more complex but you can do that as well.
Well i'd certainly be curious to know how to do the movement thing even if it is complex but i'll deff add/adjust the immunity time to stop it spamming if i knew where to look for references etc
 
Just add or subtract to player.velocity.X and player.velocity.Y, based on how you want the player to move.
I guess that would be inside the {} where the text bit is as to where i would put player.velocity.X and Y
C:
public override bool PreHurt(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
        {
            //The effect & Chance percentage of the effect activating
            if (dodgeAccessory && Main.rand.NextFloat() < 0.80f)
            {
                player.velocity.X something something here example
                //For the Debugging purposes to tell if the effect is working correctly, Will probably be commented out for release
                Main.NewText("Effect has activated", 175, 75, 255, false);
                return false;
            }
            return true;
        }
 
Okay cool ill experiement in a bit with it and just so i know it would be player.velocity.X then what or would Visual studio tell me what to type when i go to put it in, i'd imagine it would do that wouldn't it
 
You'd need to experiment around with different checks on how you want it to go, like check if what is hitting you is to your left or right, then move the player left or right, etc... But the basic code statement would just be something like
player.velocity.X += 5f;
player.velocity.Y -= 1f;
That would move your player to the right, with a slight hop.
 
Okay, Well i want to re-install vs2019 to my SSD as it opens so slowly on my HDD so ill experiment with the basic code after that first then try to figure out the checks for left and right which if i cant i suppose i can just jump on the discord and see if someone can help me in the right direction lol (And yeah i figured it would be a float number just wasn't sure what would be inbetween it and player.velocity.X/Y)
 
Back
Top Bottom