Standalone [1.3] tModLoader - A Modding API

Ah yeah, you'll need to make that last line to the following:
Code:
return base.Shoot(item, player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack);
Just copy paste, that was my bad (knockBack needed a capital B :p).
Well, I failed to notice this.
now it should be:
Code:
        public override bool Shoot(Item item, Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            if (item.useAmmo == 1 && player.HasBuff(mod.BuffType("Archery2Buff")) > 0)
            {
                speedX *= 1.35F; speedY *= 1.35F;
            }
            return base.Shoot(item, player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack);
        }
And it works just fine! Coll!
Now I'm going to create something else. Bound to be questions, though. Ask you later.
 
Okay, I know I would encounter something really soon.
Aiming to make some life regeneration and mana regeneration, I get puzzled by so many factors in the reference:
upload_2015-12-12_10-37-40.png

upload_2015-12-12_10-36-51.png

The manaRegenBuff is a boolean, so it should refer to the exact buff Mana Regeneration.
So which factor does Mana Regeneration Potion change? Too hard for me to figure this out.
 
Okay, I know I would encounter something really soon.
Aiming to make some life regeneration and mana regeneration, I get puzzled by so many factors in the reference:
View attachment 88129
View attachment 88128
The manaRegenBuff is a boolean, so it should refer to the exact buff Mana Regeneration.
So which factor does Mana Regeneration Potion change? Too hard for me to figure this out.
As you have guessed, chugging the mana regen potion gives you the mana regen buff, which in turn sets player.manaRegenBuff to true.
This boolean is only used in the following snippet (take from vanilla code):
Code:
if (this.manaRegenBuff && this.manaRegenDelay > 20)
{
    this.manaRegenDelay = 20;
}
if (this.manaRegenDelay <= 0)
{
    this.manaRegenDelay = 0;
    this.manaRegen = this.statManaMax2 / 7 + 1 + this.manaRegenBonus;
    if ((this.velocity.X == 0f && this.velocity.Y == 0f) || this.grappling[0] >= 0 || this.manaRegenBuff)
    {
        this.manaRegen += this.statManaMax2 / 2;
    }
    float num2 = (float)this.statMana / (float)this.statManaMax2 * 0.8f + 0.2f;
    if (this.manaRegenBuff)
    {
        num2 = 1f;
    }
    this.manaRegen = (int)((double)((float)this.manaRegen * num2) * 1.15);
}
else
{
    this.manaRegen = 0;
}
It's very late (or VERY early) where I am atm, so too tired to figure out its exact usage. I hope you can do something with this!

EDIT:
Allright, there are actually a few ways to modify the mana regeneration:
You can do a check like so:
Code:
if(player.manaRegenDelay > 10)
    player.manaRegenDelay = 10;
Which will make you gain mana faster, but you can also modify 'player.manaRegenDelayBonus' for a faster mana regen. I'm sure there are other ways, but like I said: too late :p
 
Last edited:
As you have guessed, chugging the mana regen potion gives you the mana regen buff, which in turn sets player.manaRegenBuff to true.
This boolean is only used in the following snippet (take from vanilla code):
Code:
if (this.manaRegenBuff && this.manaRegenDelay > 20)
{
    this.manaRegenDelay = 20;
}
if (this.manaRegenDelay <= 0)
{
    this.manaRegenDelay = 0;
    this.manaRegen = this.statManaMax2 / 7 + 1 + this.manaRegenBonus;
    if ((this.velocity.X == 0f && this.velocity.Y == 0f) || this.grappling[0] >= 0 || this.manaRegenBuff)
    {
        this.manaRegen += this.statManaMax2 / 2;
    }
    float num2 = (float)this.statMana / (float)this.statManaMax2 * 0.8f + 0.2f;
    if (this.manaRegenBuff)
    {
        num2 = 1f;
    }
    this.manaRegen = (int)((double)((float)this.manaRegen * num2) * 1.15);
}
else
{
    this.manaRegen = 0;
}
It's very late (or VERY early) where I am atm, so too tired to figure out its exact usage. I hope you can do something with this!
I went in the game and consumed some mana to see how it works.
Originally, when I use the staff, the mana begin to decrease until it became 0. So the mana won't regen when you're actually consuming it. Once you don't use magic, the system will detect it, and regen your mana after a few secs.
To see the codes with this, I guess the manaRegenDelay is merely a counter, but not an attribute. And it will be set to 20 when it detects that player is consuming mana. Once the player stop, it will count from 20 to 0. Then player's mana will regen.
manaregen may indicate how much mana regen per sec.
From this.manaRegen = this.statManaMax2 / 7 + 1 + this.manaRegenBonus;
I guess "this.statManaMax2 / 7 + 1" would be the basic speed of manaregen.
So manaregenbonus is a bonus to manaregen, it's added to manaregen directly.
Don't know whether these guesses are right or not. If it's right, then manaRegenDelayBonus should be a bonus to manaRegenDelay. When it's adapted, manaRegenDelay may be shortened, like 20 to 18, or somehow. It will shorten the time between the regeneration.
... Then what does this manaRegenCount function?
So complex.......:confused:
 
I went in the game and consumed some mana to see how it works.
Originally, when I use the staff, the mana begin to decrease until it became 0. So the mana won't regen when you're actually consuming it. Once you don't use magic, the system will detect it, and regen your mana after a few secs.
To see the codes with this, I guess the manaRegenDelay is merely a counter, but not an attribute. And it will be set to 20 when it detects that player is consuming mana. Once the player stop, it will count from 20 to 0. Then player's mana will regen.
manaregen may indicate how much mana regen per sec.
From this.manaRegen = this.statManaMax2 / 7 + 1 + this.manaRegenBonus;
I guess "this.statManaMax2 / 7 + 1" would be the basic speed of manaregen.
So manaregenbonus is a bonus to manaregen, it's added to manaregen directly.
Don't know whether these guesses are right or not. If it's right, then manaRegenDelayBonus should be a bonus to manaRegenDelay. When it's adapted, manaRegenDelay may be shortened, like 20 to 18, or somehow. It will shorten the time between the regeneration.
... Then what does this manaRegenCount function?
So complex.......:confused:
Allright, so everything that has to do with 'delay': You know that when your mana is totally depleted (0) it'll take a really long while before it'll start regenerating again? That's got to do with manaRegenDelay. Now once this delay is gone, it'll start the actual regenerating of mana.
These calculations are a bit odd, but you can safely state that manaRegen gets bigger and bigger because of this line:
this.manaRegen = (int)((double)((float)this.manaRegen * num2) * 1.15);
It uses itself to be a larger number, so it's almost comparable to squaring manaRegen.
Anyway, there are multiple options regarding mana regenerating you have:
You can either make changes to the delay, which will make sure that when you use spells, your mana starts regenerating again after a shorter timespan, or
you can check 'if (this.manaRegenDelay <= 0)' and then make changes to 'manaRegen' to make the actual regenerating go faster. You can also modify 'player.manaRegenCount' since this is the value that is eventually checked to see if it's regen time.

I hope I'm not too vague with this explanation (please tell if I am ;)).
 
Hey... I'm kinda having a problem where it just doesn't load the maps while using Tmodloader... But since you guys are busy with another person, I'm just gonna leave the error message here.

Object reference not set to an instance of an object.
at Terraria.ModLoader.BuffLoader.Update(Int32 buff, Player player, Int32& buffIndex)
at Terraria.Player.UpdateBuffs(Int32 i)
at Terraria.Player.Update(Int32 i)
at Terraria.WorldGen.do_playWorldCallBack(Object threadContext)
at Terraria.WorldGen.playWorldCallBack(Object threadContext)
 
Hey... I'm kinda having a problem where it just doesn't load the maps while using Tmodloader... But since you guys are busy with another person, I'm just gonna leave the error message here.
We have enough space XD
Could you enlighten me/us: are you using any mods or just plain tModLoader? If you are using mods, which?
Also on which platform are you?
 
Hey... I'm kinda having a problem where it just doesn't load the maps while using Tmodloader... But since you guys are busy with another person, I'm just gonna leave the error message here.
Buffs have this bug in the current version (related to their ID being saved improperly), since buff support hasn't actually been completed yet. This problem will be fixed in the next update.
 
Phew! Thought that it was just the mods or my computer. But thank you guys for the answers! :D
That said, you might be able to fix it by enabling all the mods you have. Once in game, right click on any buffs you have and exit again. It worked for me before. Sorry about the bug.
 
Allright, so everything that has to do with 'delay': You know that when your mana is totally depleted (0) it'll take a really long while before it'll start regenerating again? That's got to do with manaRegenDelay. Now once this delay is gone, it'll start the actual regenerating of mana.
These calculations are a bit odd, but you can safely state that manaRegen gets bigger and bigger because of this line:
this.manaRegen = (int)((double)((float)this.manaRegen * num2) * 1.15);
It uses itself to be a larger number, so it's almost comparable to squaring manaRegen.
Anyway, there are multiple options regarding mana regenerating you have:
You can either make changes to the delay, which will make sure that when you use spells, your mana starts regenerating again after a shorter timespan, or
you can check 'if (this.manaRegenDelay <= 0)' and then make changes to 'manaRegen' to make the actual regenerating go faster. You can also modify 'player.manaRegenCount' since this is the value that is eventually checked to see if it's regen time.

I hope I'm not too vague with this explanation (please tell if I am ;)).
After a long-time test, finally understand your words!
Well, my guess about manaRengeDelay is right. If I set it to 0,mana will regen no matter what. And manaRegen controls the speed. Since it will multiply upon itself, something like manaRegen += 20 I did before will take little effect.
Code:
if (this.manaRegenBuff && this.manaRegenDelay > 20)
{
    this.manaRegenDelay = 20;
}
if (this.manaRegenDelay <= 0)
{
    this.manaRegenDelay = 0;
    this.manaRegen = this.statManaMax2 / 7 + 1 + this.manaRegenBonus;
    if ((this.velocity.X == 0f && this.velocity.Y == 0f) || this.grappling[0] >= 0 || this.manaRegenBuff)
    {
        this.manaRegen += this.statManaMax2 / 2;
    }
    float num2 = (float)this.statMana / (float)this.statManaMax2 * 0.8f + 0.2f;
    if (this.manaRegenBuff)
    {
        num2 = 1f;
    }
    this.manaRegen = (int)((double)((float)this.manaRegen * num2) * 1.15);
}
else
{
    this.manaRegen = 0;
}
These codes describe the situation where you have mana Regeneration buff. What if a player don't have the buff? What are these values then?
 
After a long-time test, finally understand your words!
Well, my guess about manaRengeDelay is right. If I set it to 0,mana will regen no matter what. And manaRegen controls the speed. Since it will multiply upon itself, something like manaRegen += 20 I did before will take little effect.
Code:
if (this.manaRegenBuff && this.manaRegenDelay > 20)
{
    this.manaRegenDelay = 20;
}
if (this.manaRegenDelay <= 0)
{
    this.manaRegenDelay = 0;
    this.manaRegen = this.statManaMax2 / 7 + 1 + this.manaRegenBonus;
    if ((this.velocity.X == 0f && this.velocity.Y == 0f) || this.grappling[0] >= 0 || this.manaRegenBuff)
    {
        this.manaRegen += this.statManaMax2 / 2;
    }
    float num2 = (float)this.statMana / (float)this.statManaMax2 * 0.8f + 0.2f;
    if (this.manaRegenBuff)
    {
        num2 = 1f;
    }
    this.manaRegen = (int)((double)((float)this.manaRegen * num2) * 1.15);
}
else
{
    this.manaRegen = 0;
}
These codes describe the situation where you have mana Regeneration buff. What if a player don't have the buff? What are these values then?
The same, but without the buff boolean taken into account :p manaRegenDelay actually gets set to maxRegenDelay, which is set in multiple ways.
 
There is never an easy way in my modding process... Need some helps again.
I'm trying to make myself a... well, I called it "Gunner Potion". I want this potion to increase bullet damage and more importantly, increase attack speed of guns.
So I found myself player.bulletDamage += 0.1f in the reference, this could increase the damage of a gun.
Then to increase attack speed, I set GlobalItem like last time:
Code:
    public class GunnerBuffInterval : GlobalItem
    {
        public override void UpdateEquip(Item item, Player player)
        {
            if (player.HasBuff(mod.BuffType("GunnerBuff")) >= 0)
            {
                item.useTime = (int)(item.useTime * 0.9);
            }
        }
    }
It doesn't work out. Even if I changed "item.useTime" to "item.useTime = 1", nothing really happened.
Another thing, if I'm gonna describe arrow, it would be "item.useAmmo == 1". Which number refers to bullet?
 
There is never an easy way in my modding process... Need some helps again.
I'm trying to make myself a... well, I called it "Gunner Potion". I want this potion to increase bullet damage and more importantly, increase attack speed of guns.
So I found myself player.bulletDamage += 0.1f in the reference, this could increase the damage of a gun.
Then to increase attack speed, I set GlobalItem like last time:
Code:
    public class GunnerBuffInterval : GlobalItem
    {
        public override void UpdateEquip(Item item, Player player)
        {
            if (player.HasBuff(mod.BuffType("GunnerBuff")) >= 0)
            {
                item.useTime = (int)(item.useTime * 0.9);
            }
        }
    }
It doesn't work out. Even if I changed "item.useTime" to "item.useTime = 1", nothing really happened.
Another thing, if I'm gonna describe arrow, it would be "item.useAmmo == 1". Which number refers to bullet?
I've just had 2 hours of sleep, so I deem myself smart enough to once again answer your questions! Here goes nothing:
The way you're trying to modify the item.useTime variabele is kinda... Wrong. You're never resetting the value, so it keeps getting smaller and smaller, without ever getting reset (at least, I don't think that useTime gets recalculated every frame internally).
I'm going to run some tests to see what works (Although I'm kinda booked today, but we'll see).

As for the ammo: the I'd of bullets as ammo is 14 or 10... One of those two!
 
I've just had 2 hours of sleep, so I deem myself smart enough to once again answer your questions! Here goes nothing:
The way you're trying to modify the item.useTime variabele is kinda... Wrong. You're never resetting the value, so it keeps getting smaller and smaller, without ever getting reset (at least, I don't think that useTime gets recalculated every frame internally).
I'm going to run some tests to see what works (Although I'm kinda booked today, but we'll see).

As for the ammo: the I'd of bullets as ammo is 14 or 10... One of those two!
Glad to have you online. My head is gradually out of order due to these stuff!
item.useTime = (int)(item.useTime * 0.9)
Yeah, you're right. This is kinda like x = 0.9x, it's conspicuously wrong!
But why would item.useTime = 1; also take no effect?
 
Glad to have you online. My head is gradually out of order due to these stuff!
item.useTime = (int)(item.useTime * 0.9)
Yeah, you're right. This is kinda like x = 0.9x, it's conspicuously wrong!
But why would item.useTime = 1; also take no effect?
Um, why would it even matter what the useTime of an accessory is? You aren't using the accessory at all, it is just equipped in an accessory slot.

I'm not sure if what you are attempting is possible. Usually you'd want to model your effect after existing items that have the effect, but no item in Terraria does anything like what you are attempting. Melee speed has code, but there is no code for modifying speed for other items. You may be able to hack it out, but I haven't seen a way yet.

Also, if you ever what to know anything about items, such as which ammo they use, there is a spreadsheet that will tell you anything you wish to know: https://github.com/bluemagic123/tModLoader/wiki/Vanilla-Item-Field-Values
 
Um, why would it even matter what the useTime of an accessory is? You aren't using the accessory at all, it is just equipped in an accessory slot.

I'm not sure if what you are attempting is possible. Usually you'd want to model your effect after existing items that have the effect, but no item in Terraria does anything like what you are attempting. Melee speed has code, but there is no code for modifying speed for other items. You may be able to hack it out, but I haven't seen a way yet.

Also, if you ever what to know anything about items, such as which ammo they use, there is a spreadsheet that will tell you anything you wish to know: https://github.com/bluemagic123/tModLoader/wiki/Vanilla-Item-Field-Values
Thanks!
I can't really use this spreadsheet very well. I can only get IDs from it. How should express an entire class of items? Like item.useAmmo == 1, this "1" refers to all kinds of arrows. Which number should I change to so it refers to all kinds of bullets?
 
So, it's been a really long time since I've last updated. The main reason for this is school, suddenly giving a ton of projects towards the end of the year. However, now the only thing left before my semester ends are the finals (which I don't need to study much for), and I get an entire month for winter break. My hope is to try to finish the next update by either the end of the month or the end of winter break, but we'll see what happens with that.

In the meantime, here's an example of one kind of thing that will be newly possible in the next update, using ModPlayer:
 
So, it's been a really long time since I've last updated. The main reason for this is school, suddenly giving a ton of projects towards the end of the year. However, now the only thing left before my semester ends are the finals (which I don't need to study much for), and I get an entire month for winter break. My hope is to try to finish the next update by either the end of the month or the end of winter break, but we'll see what happens with that.

In the meantime, here's an example of one kind of thing that will be newly possible in the next update, using ModPlayer:
Look forward to. Don't forget the maxlife and the button "B" and... I don't knoo. Just don't work too hard. We're not rushing to something.
 
Back
Top Bottom