tModLoader Official tModLoader Help Thread

I'm having trouble with NetSend for GlobalItem on servers, as a client.
Every time I pick up an item, I'll constantly start getting duplicates of said item in my inventory until I exit the game of my inventory gets full.
And as far as I could test, it only happens when ItemInfo is referenced, regardless if it actually contains anything.
I'm also compiling it in game in case that has any effect what so ever.

Here's some very small example code that causes my problems, and yes, I've tested this piece of code multiple times. Every time, I'll keep getting constant duplicate items.
And yes, I have absolutely no other mods loaded.
Code:
using Terraria;
using Terraria.ModLoader;
using System.IO;
namespace TestMod {
    public class TestMod : Mod {
        public TestMod() {
            this.Properties = new ModProperties() {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
    }
    public class GItem : GlobalItem {
        public override void NetSend(Item item, BinaryWriter writer) {
            IInfo info = item.GetModInfo<IInfo>(this.mod); // As long as this is here, I keep getting duplicate items constantly
            writer.Write("DERP");
        }
    }
    public class IInfo : ItemInfo {}
}
I've tried asking for help on Discord, but it's either at a bad time (someone else gets more priority help or the time of day), or there's nobody who can really help me.
Where's your NetReceive?
 
That's in the main mod itself. Regardless if NetReceive is there, and does anything at all, I just keep getting duplicates. I've been constantly stripping code slowly and testing over and over for the past few days to try and find the source of the problem. This is what I came up with.

Unless I remove the ItemInfo reference in NetSend, but of course I need that else NetSend is pointless.
 
That's in the main mod itself. Regardless if NetReceive is there, and does anything at all, I just keep getting duplicates. I've been constantly stripping code slowly and testing over and over for the past few days to try and find the source of the problem. This is what I came up with.

Unless I remove the ItemInfo reference in NetSend, but of course I need that else NetSend is pointless.
The thing is, if there's nothing done in NetReceive, you are writing data which is unused.
 
Here's the code from one of my mods I'm yet to release, but can't because of this problem.
Code:
        public override void NetSend(Item item, BinaryWriter writer) {
            D2AItemInfo info = item.GetModInfo<D2AItemInfo>(this.mod);
            if (info.HasAffix(item)) {
                writer.Write("D2ASendAffix");
                writer.Write(info.prefixID);
                writer.Write(info.suffixID);
                writer.Write(info.itemQuality);
            }
        }
       
        public override void NetReceive(Item item, BinaryReader reader) {
            if (reader.ReadString() == "D2ASendAffix") {
                D2AItemInfo info = item.GetModInfo<D2AItemInfo>(this.mod);
                info.Initialize(item, reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
            }
        }
All the syncing works, but still keep getting constant duplicates of what's been picked up.
 
I'm having trouble with NetSend for GlobalItem on servers, as a client.
Every time I pick up an item, I'll constantly start getting duplicates of said item in my inventory until I exit the game of my inventory gets full.
And as far as I could test, it only happens when ItemInfo is referenced, regardless if it actually contains anything.
I'm also compiling it in game in case that has any effect what so ever.

Here's some very small example code that causes my problems, and yes, I've tested this piece of code multiple times. Every time, I'll keep getting constant duplicate items.
And yes, I have absolutely no other mods loaded.
Code:
using Terraria;
using Terraria.ModLoader;
using System.IO;
namespace TestMod {
    public class TestMod : Mod {
        public TestMod() {
            this.Properties = new ModProperties() {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
    }
    public class GItem : GlobalItem {
        public override void NetSend(Item item, BinaryWriter writer) {
            IInfo info = item.GetModInfo<IInfo>(this.mod); // As long as this is here, I keep getting duplicate items constantly
            writer.Write("DERP");
        }
    }
    public class IInfo : ItemInfo {}
}
I've tried asking for help on Discord, but it's either at a bad time (someone else gets more priority help or the time of day), or there's nobody who can really help me.
I can't replicate this, even on 0.9.2.1 or 0.9.2.2.
 
Question: Is there a way to load another mod's ModPlayer into your own mod so that you can work with the contents of the other mod's ModPlayer (i.e. changing the value of a boolean from the other ModPlayer with code from your mod)
 
Back again, with something rather simple.
Is it just not possible to set a UIImage's alpha?
I need to change the alpha of a UI image, but there seems to be no .SetColor or .SetAlpha, or anything. The next best thing is .ImageScale, but I REALLY want to modify it's alpha instead.
 
I know I asked this a while ago, but what would the code for that be? I can't figure out how to reference the BuffTime

Also, how would I make a projectile increase the duration of a buff only if the player already has that buff?
Yeah, It's not exactly obvious how to find the timeLeft of a buff. The timeLeft for all buffs are stored on the player in an array of ints, and you need the index of your buff to find it's timeLeft. Thankfully, Update hook for ModBuff knows your buffIndex. Just stick the following inside the buffs update hook.
Code:
if (player.buffTime[buffIndex] == 2)
{
    //do stuff
}
 
Back again, with something rather simple.
Is it just not possible to set a UIImage's alpha?
I need to change the alpha of a UI image, but there seems to be no .SetColor or .SetAlpha, or anything. The next best thing is .ImageScale, but I REALLY want to modify it's alpha instead.
UIImage doesn't have that, so make your own:
Code:
    public class UITransparantImage : UIElement
    {
        private Texture2D _texture;
        public float ImageScale = 1f;
        private Color color;

        public UITransparantImage(Texture2D texture, Color color)
        {
            this._texture = texture;
            this.Width.Set((float)this._texture.Width, 0f);
            this.Height.Set((float)this._texture.Height, 0f);
            this.color = color;
        }

        public void SetImage(Texture2D texture)
        {
            this._texture = texture;
            this.Width.Set((float)this._texture.Width, 0f);
            this.Height.Set((float)this._texture.Height, 0f);
        }

        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            CalculatedStyle dimensions = base.GetDimensions();
            spriteBatch.Draw(this._texture, dimensions.Position() + this._texture.Size() * (1f - this.ImageScale) / 2f, null, color, 0f, Vector2.Zero, this.ImageScale, SpriteEffects.None, 0f);
        }
    }

And pass in
Code:
Color.White * 0.5f
as the color parameter. Should work.
 
Could someone tell me what's wrong with this item, what I want to do is (basically) override the ModItem methods (as OnCraft, OnPickUp, etc) but I'm getting this kind of error:
c:\Users\erty\Documents\My Games\Terraria\ModLoader\Mod Sources\test\Items\testitem.cs(36,30) : error CS0115: 'test.Items.testitem.OnCraft(Terraria.Item, Terraria.Recipe)': no suitable method found to override
And the item has this code:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace test.Items
{
    public class testitem : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "testitem";
            item.damage = 50;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.toolTip = "This is a modded sword.";
            item.useTime = 20;
            item.useAnimation = 20;
            item.useStyle = 1;
            item.knockBack = 6;
            item.value = 10000;
            item.rare = 2;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }

        public override void OnCraft(Item item, Recipe recipe)
        {
            Main.NewText("test");
        }
    }
}

Remove Item item from the parameters of OnCraft, there should only be Recipe recipe there.
 
I have a problem...(Sorry for broken english btw)
So, I was messing with mod and my NPC (even the mobs) turn green...
I try everythings, disable mods, turn them on, even restarting my computer!
Noting work.
Help?
 

Attachments

  • Capture 2017-03-26 17_42_12.png
    Capture 2017-03-26 17_42_12.png
    189.4 KB · Views: 132
Hopefully the last of my issues, in modifying the UI for Resource Bars, is there no way to remove/modify ONLY the health and mana bars, but not the buff list and air meter?
 
Hi, I'm trying to synchronize a couple of bools in my ModPlayer class between clients in multiplayer, but I can't find how this is done in the example mod. Basically what I want to happen is when a keybinding is pressed, I want to toggle a bool and update that information across clients. I have the toggle part down-pact, I just can't work out how to send the new state of the bool to other clients.

Thanks you.
 
Hey guys I have a question. Im creating a boss and I dont know how to get it to do something. i'm trying to make it spawn an NPC every little bit, like the Eye of Cthulu does with the servants so I have a spawnTimer variable set to 300, and spawnTimer -= "insert code for random number 1-5 here" in the AI section followed by if spawnTimer <= 0 ... but how would I get it to spawn a modNPC?
 
I can't spawn pets and light pets. The effect shows up but the pet/light pet doesn't actually appear.
 

Attachments

  • Mod List.txt
    2.5 KB · Views: 221
how to force a item out of your accessory slots when a condition is met.(i have a bool that when it is false it should disable its usage.)
 
Back
Top Bottom