Standalone [1.3] tModLoader - A Modding API

I'll actually be adding a hook in the next update to make it easier to adjust the texture's offset when the player uses an item.
Well, I'm looking forward to, then.
By the way, there is a question I have been wondering for a long time.
Every item has their "item.height" "item.width". I thought they would be the size in the game or the size of the texture.png, but they're actually not. And it should come to size of the texture.png to decide the size in the game. Then what's the meaning of these two settings? They seem to effect nothing.
 
Nope, that hasn't been added yet. I'm trying to add in hooks for ModPlayer and ModWorld first; after that I'll decide between focusing on custom UIs or server support.
I see. I would be totally fine with a simple PreDrawInterface hook, like both tAPI and tConfig did (difference being tConfig had it part of ModWorld). That aside, I can't wait for the good old ModPlayer hook to be back too, I literally like to feed off of global player hooks.
Keep up the good work you people, I've been waiting for an API to reach the same potential as good old tAPI for a while now, and hearing it's almots behind the corner is fairly exciting to say the least.

Yes, it works like a charm.
And next thing I wanna ask is about the texture.
Only when I made myself a sniper rifle, did I discover this matter about the texture. Since the sniper rifle can be super long compare to other melee weapons, it looks quite odd when shoots, especially the stock. So I looked into the vanilla sniper rifle carefully, its stock actually sinks into player's body... Well, kinda like the one I set in NPC: public override void DrawTownAttackGun(ref float scale, ref int item, ref int closeness).
This closeness, it defines these stuff. I guess there may also be a closeness definition of mod items, using public virtual void UseStyle(Player player).
:sigh:But I don't know how to call it.
I had to deal with the same issue. While we will have proper support for easy sprite offsetting, this is my temporary workaround.
Code:
public int dir = 1;
    
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
        dir = Main.mouseX+Main.screenPosition.X > player.Center.X ? 1 : -1;
        return true;
}
    
public override void UseStyle(Player player)
{
        int distance = -20;
        player.itemLocation.X += (float)(Math.Cos(player.itemRotation) * distance) * dir;
        player.itemLocation.Y += (float)(Math.Sin(player.itemRotation) * distance) * dir;
}
Ofc, change distance with your desired value.

Well, I'm looking forward to, then.
By the way, there is a question I have been wondering for a long time.
Every item has their "item.height" "item.width". I thought they would be the size in the game or the size of the texture.png, but they're actually not. And it should come to size of the texture.png to decide the size in the game. Then what's the meaning of these two settings? They seem to effect nothing.
They affect the hitbox's size and potentially drawing. If you rotate a sprite with an improperly sized hitbox, you'll notice the sprite is not perfectly centered. For actual sprite size, you want to use item.scale, 1f being the default value.
 
They affect the hitbox's size and potentially drawing. If you rotate a sprite with an improperly sized hitbox, you'll notice the sprite is not perfectly centered. For actual sprite size, you want to use item.scale, 1f being the default value.
I see. Thx for reply, anyway.
So normally I should just set the "item.height" and "item.width" to the same as the texture? But I'm asking, 'cause I find a lot of vanilla items' "item.height" or "item.width" are not fit with their texture sizes. Why is that?
 
I see. Thx for reply, anyway.
So normally I should just set the "item.height" and "item.width" to the same as the texture? But I'm asking, 'cause I find a lot of vanilla items' "item.height" or "item.width" are not fit with their texture sizes. Why is that?
It's probably to make the weapon's hitbox a slight bit smaller than the actual sprite. Transparency can easily make the hitbox seem bigger if the actual texture's size is used. This most commonly happens with weapons which don't fill up the entire texture size or undersized swords which are either really tight or lack a pointy end. That said, you usually want a size that gets as close as possible to the actual texture size. Having the proper size can be really important for spinning projectiles however as even the slightest pixel off can mess up the centering. Weapons should be otherwise fine with even quite a bit of pixels off, hitbox issues aside.
 
It's probably to make the weapon's hitbox a slight bit smaller than the actual sprite. Transparency can easily make the hitbox seem bigger if the actual texture's size is used. This most commonly happens with weapons which don't fill up the entire texture size or undersized swords which are either really tight or lack a pointy end. That said, you usually want a size that gets as close as possible to the actual texture size. Having the proper size can be really important for spinning projectiles however as even the slightest pixel off can mess up the centering. Weapons should be otherwise fine with a few pixels off.
Well, it's getting too complicated for me. Maybe I'll look into this afterwards.
I put your codes in my rifle and it looks superbly awesome right now. Time to move onto next question.
In order to gain a pretty high velocity of the sniper rifle I made, I set "item.shootspeed" pretty high, up to 100f, and it seems nothing different from the vanilla sniper rifle. Then I increased the speedX and speedY in Shoot hook, and it ain't working too. Is there a limit of velocity in the game? And if there is, can I break it?
 
Well, it's getting too complicated for me. Maybe I'll look into this afterwards.
I put your codes in my rifle and it looks superbly awesome right now. Time to move onto next question.
In order to gain a pretty high velocity of the sniper rifle I made, I set "item.shootspeed" pretty high, up to 100f, and it seems nothing different from the vanilla sniper rifle. Then I increased the speedX and speedY in Shoot hook, and it ain't working too. Is there a limit of velocity in the game? And if there is, can I break it?
Yes, there is a limit of 16f. You can break it by setting the projectile's extraUpdates field to a number greater than 0 (this makes it update multiple times in a single tick). If you want a weapon to shoot faster on any kind of projectile, then you can override the Shoot hook, manually create the projectile yourself, increment the projectile's extraUpdates field from there, then return false.
 
Yes, there is a limit of 16f. You can break it by setting the projectile's extraUpdates field to a number greater than 0 (this makes it update multiple times in a single tick). If you want a weapon to shoot faster on any kind of projectile, then you can override the Shoot hook, manually create the projectile yourself, increment the projectile's extraUpdates field from there, then return false.
This is exactly another question I want to ask, about this "projectile.extraUpdates". What's the function of this definition?

Edit: And, yeah, how should create a exactly same projectile of the default setting in Shoot hook? Since the gun uses ammo, not only using one kind of projectile, I'm quite confused.
 
This is exactly another question I want to ask, about this "projectile.extraUpdates". What's the function of this definition?

Edit: And, yeah, how should create a exactly same projectile of the default setting in Shoot hook? Since the gun uses ammo, not only using one kind of projectile, I'm quite confused.
For example, the Shadowbeam staff projectile has 100 extra updates. By default, projectiles will run the AI code and collision detection once per frame. (1 + extraUpdates, which defaults to 0) If a projectile is going faster than the width of a block (16), it will pass through blocks on occasion. The shadow beam projectile will do 101 updates each frame, this is why the projectile can bounce off a bunch of walls the instant you fire it.

You'll need to use extraUpdates on somewhat rare occasions. Note that changing extraUpdates will mean you'll have to adjust shootspeed and such, so don't do it unless you need to.

Also, tell us precisely what you mean by your ammo question, I wouldn't want to answer wrongly.
 
For example, the Shadowbeam staff projectile has 100 extra updates. By default, projectiles will run the AI code and collision detection once per frame. (1 + extraUpdates, which defaults to 0) If a projectile is going faster than the width of a block (16), it will pass through blocks on occasion. The shadow beam projectile will do 101 updates each frame, this is why the projectile can bounce off a bunch of walls the instant you fire it.

You'll need to use extraUpdates on somewhat rare occasions. Note that changing extraUpdates will mean you'll have to adjust shootspeed and such, so don't do it unless you need to.

Also, tell us precisely what you mean by your ammo question, I wouldn't want to answer wrongly.
Yeah, yeah, I should have known my expression going ambiguously again, sorry about that.
Buy this "ammo", I mean, what a gun shoots does not decide on what its "item.shoot" is, but decide on the ammo it's using. So, if this is the case, how should I create the projectile of the ammo-decided projectile in Shoot hook? Now normally regarding some laser weapons, they have their own projectile. If I'm to modify their lasers, it's quite simple. And if I'm to modify what a gun shoots, that can be a lot of works to do, since I don't know how to refer to what a gun is shooting, I can only use "if" to judge this type by type. Maybe you could give me some examples about how to create a projectile (same as a gun is shooting) in Shoot hook.
And in a NewProjectile call:
Code:
Projectile.NewProjectile(float, float, float, float, int, int, float, int, float, float)
There seems not to be a value that defines the update times, How should I call this ExtraUpdates?
 
What should i do if mod cannot be build because of extraUpdate ?
It make this error : Cannot implicitly convert type 'bool' to 'int'
 
Is this a virus? Webroot says it's a virus
for testing, i downloaded the linux version to see if i could help someone who was having issues. it said something along the lines of 'malware detected, download cancelled'. are you sure that you are downloading for the right platform?
 
I got this working :D
I also figured out how to record gifs
thanks @Eldrazi
ezgif-1370311511.gif
 
That look amazing
can you post the AI code ?
Eldrazi helped with the code
Code:
public override bool PreAI()
{
    projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.03f * (float)projectile.direction;
    projectile.localAI[1] += 1f;
    if (projectile.localAI[1] >= 20f) // Change this '20' value if you want the knife to fly longer before dropping
    {
        projectile.velocity.Y = projectile.velocity.Y + 0.4f;
        projectile.velocity.X = projectile.velocity.X * 0.98f;
    }
    else
    {
        projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
    }

    if (projectile.velocity.Y > 16f)
    {
        projectile.velocity.Y = 16f;
    }
 
    return false;
}
 
Back
Top Bottom