Standalone [1.3] tModLoader - A Modding API

a little question about the math of terraria. according to the wiki the lets say accessory damage bonuses are added together first right? (http://terraria.wiki.gg/Damage_types). why is it then when i for example call this in globalitem
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage -= 0.1f;
            }
        }
that the damage when equipping the sniper scope changes like it would multiplicately instead of deleting the sniperscope 10% boost? is tmodloaders hook somewhere different than i thought? how does it handle the damage boosts that
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage += 0.1f;
            }
        }
isnt the same as
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.2f;
            }
        }
or why does it completely :red: up when i go like
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
            }
        }
does it handle each boost on it own and then read what to do next? is the wiki wrong? can i not remove or change vanilla item damage boosts like sniper scope to 0% or avenger emblem to 15% because as the tooltip says 12%+3% is not 15% even though the wiki says they are added first.
 
a little question about the math of terraria. according to the wiki the lets say accessory damage bonuses are added together first right? (http://terraria.wiki.gg/Damage_types). why is it then when i for example call this in globalitem
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage -= 0.1f;
            }
        }
that the damage when equipping the sniper scope changes like it would multiplicately instead of deleting the sniperscope 10% boost? is tmodloaders hook somewhere different than i thought? how does it handle the damage boosts that
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage += 0.1f;
            }
        }
isnt the same as
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.2f;
            }
        }
or why does it completely :red: up when i go like
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
            }
        }
does it handle each boost on it own and then read what to do next? is the wiki wrong? can i not remove or change vanilla item damage boosts like sniper scope to 0% or avenger emblem to 15% because as the tooltip says 12%+3% is not 15% even though the wiki says they are added first.

use *= 1.01f
 
use *= 1.01f
wow facepalm me. why did i not think of that. if i want to remove 10% i should simply take it times 0.9... thx man
 
how would I make a projectile spawn at the cursor and fire directly down?
 
how would I make a projectile spawn at the cursor and fire directly down?
In the shoot method, change the position to Main.MouseWorld.X, etc, change the SpeedX tp 0 and SpeedY to a positive number
 
can i somehow detect if another mod is also loaded so i can change settings depending on if its loaded? something like
int test = base.mod.ItemType("SomeItemFromOtherMod")
if (test != 0)
{
//mod gefunden
}else //
could something like this work or is there an better way? for reference: i am the creator of both mods which were one mod before but i wanted to split the original mod into two but need to change some things depending on if both are loaded.

also is there a method to change a vanilla item into a modded item as soon as the game loads and only then (so he can change it back with a recipe if he wants to uninstall)? i know how to do it with right click
public override void RightClick(Player player)
{
int num = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, this.originalType, 1, false, 0, false, false);
Main.item[num].Prefix((int)base.item.prefix);
Main.item[num].newAndShiny = false;
}
but i would prefer this to be done automatically on load so the user doesnt need to right click the items in question. would load()/postsetupcontent() work for this? sry so many things i cant do on my own... this weekend isnt my greatest ^^
 
can i somehow detect if another mod is also loaded so i can change settings depending on if its loaded? something like
int test = base.mod.ItemType("SomeItemFromOtherMod")
if (test != 0)
{
//mod gefunden
}else //
could something like this work or is there an better way? for reference: i am the creator of both mods which were one mod before but i wanted to split the original mod into two but need to change some things depending on if both are loaded.

also is there a method to change a vanilla item into a modded item as soon as the game loads and only then (so he can change it back with a recipe if he wants to uninstall)? i know how to do it with right click
public override void RightClick(Player player)
{
int num = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, this.originalType, 1, false, 0, false, false);
Main.item[num].Prefix((int)base.item.prefix);
Main.item[num].newAndShiny = false;
}
but i would prefer this to be done automatically on load so the user doesnt need to right click the items in question. would load()/postsetupcontent() work for this? sry so many things i cant do on my own... this weekend isnt my greatest ^^
// Here is an example of how your npc can sell items from other mods.
using system.linq;
if (ModLoader.GetLoadedMods().Contains("SummonersAssociation"))
{
// Stuff
}

For your second question, I'm not sure why you'd want that. If you want to change a vanilla item, just change it in globalitem. Maybe if you explain more precisely I can help you find the best solution.
 
I'm attempting to make a mod, yet I have a problem.... I can't compile the mod. ;(
 

Attachments

  • Screenshot (1).png
    Screenshot (1).png
    426.3 KB · Views: 207
  • Screenshot (2).png
    Screenshot (2).png
    627.5 KB · Views: 218
I'm attempting to make a mod, yet I have a problem.... I can't compile the mod. ;(
As mentioned earlier, when updating to 0.8, delete mp3sharp.dll.
 
Delete the mp3sharp.dll that is in the terraria steam folder
[doublepost=1462072686,1462072531][/doublepost]
If you want to change the damage, do that in the ModifyHitNPC hook.

public static bool downedBoss1 = false;
public static bool downedBoss2 = false;
public static bool downedBoss3 = false;
public static bool downedQueenBee = false;
public static bool downedSlimeKing = false;

Also note that "Main.rand.Next(1) == 0" is always true since the parameter in Next is the exclusive upper bound.

i know that this is 100%
"Main.rand.Next(1) == 0"

it was remains from the code i had as
"Main.rand.Next(20) == 0"


i cant seem to find the downedboss for WoF and thebrain



can i se a example on how to change damage in this hook ModifyHitNPC
 
i know that this is 100%
"Main.rand.Next(1) == 0"

it was remains from the code i had as
"Main.rand.Next(20) == 0"


i cant seem to find the downedboss for WoF and thebrain



can i se a example on how to change damage in this hook ModifyHitNPC
Downed wall of flesh is just hardMode. The brain would share boss2 I think.

I haven't done anything with that hook personally, but you can say: damage = damage + 10; or whatever math you want
 
Downed wall of flesh is just hardMode. The brain would share boss2 I think.

I haven't done anything with that hook personally, but you can say: damage = damage + 10; or whatever math you want

well thats not a example code thats just a example
without the code i cant do anything

EDIT/ADD
i been trying and trying but does not matter what i do it wont change the damages
 
Last edited:
how am i suposed to install 8.0 if i installed the 7.11
 
there is two why and the first one doesn't work so there is an other copy the file and paste it in the terraria folder and i have already the older version there
 
the error
Code:
c:\Users\Dominik\Documents\My Games\Terraria\ModLoader\Mod Sources\TheRebirthMod\TheRebirthMod.cs(8,26) : error CS0115: 'TheRebirthMod.TheRebirthMod
the code
Code:
using System;
using Terraria;
using Terraria.ModLoader;

namespace TheRebirthMod {
public class TheRebirthMod : Mod
{
    public override void SetModInfo(out string name, ref ModProperties properties)
    {
        name = "TheRebirthMod";
        properties.Autoload = true;
    }
}}
 
I've met with a horrible bug (maybe for me it's horrible) with my throwing knife's durability system in multiplayer... I dunno whether it is a exclusive bug for the multiplayer or whether it is fixable for now.
First I'd give a brief description of my throwing knife's durability system.
Every throwing knife is supposed to have 3 "items/parts":
Code:
    public class IchorKnife : ModItem
    {
        public int durability = 1000;

        public override void SetDefaults()
        {
            item.name = "Ichor Knife";
            item.toolTip = "Decreases target's defense";
            item.autoReuse = true;
            item.useStyle = 1;
            item.shootSpeed = 12f;
            item.damage = 29;
            item.width = 18;
            item.height = 20;
            item.useSound = 39;
            item.useAnimation = 16;
            item.useTime = 16;
            item.noUseGraphic = true;
            item.noMelee = true;
            item.value = Item.sellPrice(0, 20, 0, 0);
            item.knockBack = 2.75f;
            item.melee = true;
            item.rare = 8;
            item.shoot = mod.ProjectileType("IchorKnifeProjectile");
        }

        public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
        {
            Main.spriteBatch.DrawString(Main.fontItemStack, durability.ToString(), new Vector2(position.X - 8f, position.Y + 11f), Color.White, 0f, default(Vector2), scale, SpriteEffects.None, 0f);
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            durability--;
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            return durability > 0;
        }

        public override void SaveCustomData(BinaryWriter writer)
        {
            writer.Write(durability);
        }

        public override void LoadCustomData(BinaryReader reader)
        {
            durability = reader.ReadInt32();
        }
Code:
    public class IchorKnifeProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Ichor Knife";
            projectile.alpha = 0;
            projectile.scale = 1f;
            projectile.width = 14;
            projectile.height = 28;
            projectile.aiStyle = 2;
            projectile.friendly = true;
            projectile.penetrate = 3;
            projectile.melee = true;
            //projectile.light = 0.2f;
            projectile.ignoreWater = true;
            //aiType = 48;
        }

        public override bool PreAI()
        {
            Lighting.AddLight((int)((projectile.position.X + (float)(projectile.width / 2)) / 16f), (int)((projectile.position.Y + (float)(projectile.height / 2)) / 16f), 1f, 1f, 0f);

            int d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 169, 0f, 0f, 100, default(Color), 1f);
            if (Main.rand.Next(2) == 0)
            {
                Main.dust[d].noGravity = true;
                Main.dust[d].scale *= 1.5f;
            }

            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;

            projectile.ai[0] += 1f;
            if (projectile.ai[0] >= 35f)
            {
                projectile.velocity.Y = projectile.velocity.Y + 0.4f;
                projectile.velocity.X = projectile.velocity.X * 0.97f;
            }

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

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(69, 600, false);
        }

        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            Main.PlaySound(0, (int)projectile.position.X, (int)projectile.position.Y, 1);
            return true;
        }
Code:
    public class IchorKnifeOnPickup : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Ichor Knife";
            item.consumable = true;
            item.maxStack = 1000;
            item.width = 18;
            item.height = 20;
            item.rare = 8;
        }

        public override bool OnPickup(Player player)
        {
            for (int i = 0; i < 51; i++)
            {
                Item item2 = player.inventory[i];
                if (item2.stack > 0 && item2.type > 0 && item2.type == mod.ItemType("IchorKnife"))
                {
                    if (((IchorKnife)item2.modItem).durability <= 999)
                    {
                        Main.PlaySound(7, (int)player.position.X, (int)player.position.Y, 0);
                        ItemText.NewText(item, item.stack, false, false);
                        ((IchorKnife)item2.modItem).durability += item.stack;
                        break;
                    }
                }
                if (i == 50)
                {
                    int a = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, mod.ItemType("IchorKnifeOnPickup"), item.stack, false, 0, false, false);
                    Main.item[a].noGrabDelay = 60;
                }
            }
            return false;
        }
  • Every throwing knife will be crafted with a maximum durability 1000.
  • The durability will be reduced upon using. (conduct by shoot hook)
  • The throwing knife will act like the vanilla throwing weapons. It has its 50% chance to drop the ammo when killed.
  • In this case, it won't drop the weapon itself, which is "IchorKnife". It will drop the exclusive item "IchorKnifeOnPickup" instead.
  • When the "IchorKnifeOnPickup" was picked up by a player,
  • if the player has the apt throwing knife and the durability was not full, he will pick it up, and increase the durability of the particular throwing knife, but the item won't appear in his inventory (the OnPickup hook returns false);
  • if the player does not has the throwing knife, he will also pick it up, but meanwhile a new and totally identical item will be created on his face, which makes it look like that he cannot pick up the item (I swear, this is the best case I can think out after several days' rocking my head).
However, this made-look-like-cannot-pickup function went dead when it comes to multiplayer. The player will pick up the "IchorKnifeOnPickup" regardless of their having the apt throwing knife facts. If a player possesses the throwing knife, yeah, the durability will get increased damn nice. But every player without the knife will swallow the "IchorKnifeOnPickup" as if they love to eat it...
This is the first time that I ever found that something worked like a charm in single player will end up screwing up in the multiplayer. This is frustrating and I have totally totally no idea about what's going on, and I need help!!!

EDIT: @jopojelly I duuno whether you're online but your profit pic is green. If you see this, well, please give a quick look. Thx:)
 
Last edited:
the error
Code:
c:\Users\Dominik\Documents\My Games\Terraria\ModLoader\Mod Sources\TheRebirthMod\TheRebirthMod.cs(8,26) : error CS0115: 'TheRebirthMod.TheRebirthMod
the code
Code:
using System;
using Terraria;
using Terraria.ModLoader;

namespace TheRebirthMod {
public class TheRebirthMod : Mod
{
    public override void SetModInfo(out string name, ref ModProperties properties)
    {
        name = "TheRebirthMod";
        properties.Autoload = true;
    }
}}

namespace TheRebirthMod
{
public class TheRebirthMod: Mod
{
public TheRebirthMod()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
};
}
}
}

try this
 
something with the word Mod isn't ok?(in the code)
 
Thank you so much, Jopojelly! :)
 
Last edited:
Back
Top Bottom