Standalone [1.3] tModLoader - A Modding API

Help, i tried to use
public virtual bool CanExplode(int i, int j)
but it wont work. I tried to return false .
you need
to tell us
what you are doing

public override bool CanExplode(int i, int j) goes in your modtile or globaltile, whatever you are using it for

make sure those virtuals are overrides
 
If I'm not able to deny a player's picking up, I come up with a rounded way to do this.
But once again met with some problems. It's about NewItem. Item generated by this, if using player's position, will be picked instantly by the player. I noticed that there is this bool NoGrabDelay, and whatever I set it to true or false, there is no delay. The item will be picked up instantly anyways.
I dunno whether this is because it ain't working. But how to generate an item, in the way like how mobs drop items, or just grant some seconds before it can be picked up? Since NoGrabDelay ain't working, anything else can I do?
Code:
Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, mod.ItemType("IchorKnifeOnPickup"), item.stack, false, 0, false, false);
 
This is because of how the projectile is drawn. If you want it to draw along its origin correctly, use the following code on your ModProjectile in the PreDraw function:
Code:
Texture2D texture = Main.projectileTexture[projectile.type];
Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)(texture.Height / Main.projFrames[projectile.type]) * 0.5f);
SpriteEffects effect = projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Main.spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Rectangle?(Utils.Frame(texture, 1, Main.projFrames[projectile.type], 0, projectile.frame)), lightColor * projectile.Opacity, projectile.rotation, origin, projectile.scale, effect, 0);
return false;
How to change the position of spawning, like, go to/spawn at mouse cursor position?
 
Could you show us your tile code as it is now?
Nope, because i figured it out. Thanks anyway
[doublepost=1461750430,1461749955][/doublepost]How would I make a set bonus that creates a temporary "Bubble" around you that protects you
[doublepost=1461750572][/doublepost]Like, when you sitting still is when the bubble comes and it disappears when you do anything
 
Nope, because i figured it out. Thanks anyway
[doublepost=1461750430,1461749955][/doublepost]How would I make a set bonus that creates a temporary "Bubble" around you that protects you
[doublepost=1461750572][/doublepost]Like, when you sitting still is when the bubble comes and it disappears when you do anything
On your ModPlayer class, create three variables and use them as follows:
Code:
public bool bubbleArmor;
public bool bubbleActive;
public int bubbleTimer;

public override void ResetEffects()
{
    this.bubbleArmor = false;
    this.bubbleActive = false;
}

public override void PostUpdateEquips()
{
    if(this.bubbleArmor)
    {
        if(player.velocity == Vector2.Zero)
        {
            if(this.bubbleTimer++ >= 120) // 2 second cooldown
            {
                this.bubbleActive = true;
            }
        }
        else
        {
            this.bubbleTimer = 0;
            this.bubbleActive = false;
        }
    }
    else
    {
        this.bubbleTimer = 0;
        this.bubbleActive = false;
    }
}
public override
Now all you want to do when you update your set is setting bubbleArmor to true.
Also don't forget to use the PreHurt hook to modify the damage done to the player if bubbleActive is true.
 
On your ModPlayer class, create three variables and use them as follows:
Code:
public bool bubbleArmor;
public bool bubbleActive;
public int bubbleTimer;

public override void ResetEffects()
{
    this.bubbleArmor = false;
    this.bubbleActive = false;
}

public override void PostUpdateEquips()
{
    if(this.bubbleArmor)
    {
        if(player.velocity == Vector2.Zero)
        {
            if(this.bubbleTimer++ >= 120) // 2 second cooldown
            {
                this.bubbleActive = true;
            }
        }
        else
        {
            this.bubbleTimer = 0;
            this.bubbleActive = false;
        }
    }
    else
    {
        this.bubbleTimer = 0;
        this.bubbleActive = false;
    }
}
public override
Now all you want to do when you update your set is setting bubbleArmor to true.
Also don't forget to use the PreHurt hook to modify the damage done to the player if bubbleActive is true.
I am so very sorry, but I have never used Prehurt before... but thank you for the code!
 
On your ModItem, override the shoot function, set the position vector to Main.MouseWorld and return true. Done.
How to change the position by minor coordiantes? The projectile is spawning at the bottom, I would like to spawn it on the tip
mx9os8C.png
 
Like this eldrazi?
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Enderuim.Projectiles
{
    public class EnderuimBubble : ModPlayer
    {
            public bool bubbleArmor;
public bool bubbleActive;
public int bubbleTimer;

public override void ResetEffects()
{
    this.bubbleArmor = false;
    this.bubbleActive = false;
}

public override void PostUpdateEquips()
{
    if(this.bubbleArmor)
    {
        if(player.velocity == Vector2.Zero)
        {
            if(this.bubbleTimer++ >= 120) // 2 second cooldown
            {
                this.bubbleActive = true;
            }
        }
        else
        {
            this.bubbleTimer = 0;
            this.bubbleActive = false;
        }
    }
    else
    {
        this.bubbleTimer = 0;
        this.bubbleActive = false;
    }
}
public override
 
I am so very sorry, but I have never used Prehurt before... but thank you for the code!
Example:
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 string deathText)
{
    if(this.bubbleActive)
    {
        damage = 0; // Will take 0 damage when the player is hurt when the bubble is active.
    }
}
How to change the position by minor coordiantes? The projectile is spawning at the bottom, I would like to spawn it on the tip
mx9os8C.png
That is because the drawing is now done differently, as the projectile is rotating around its origin.
Like this eldrazi?
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Enderuim.Projectiles
{
    public class EnderuimBubble : ModPlayer
    {
            public bool bubbleArmor;
public bool bubbleActive;
public int bubbleTimer;

public override void ResetEffects()
{
    this.bubbleArmor = false;
    this.bubbleActive = false;
}

public override void PostUpdateEquips()
{
    if(this.bubbleArmor)
    {
        if(player.velocity == Vector2.Zero)
        {
            if(this.bubbleTimer++ >= 120) // 2 second cooldown
            {
                this.bubbleActive = true;
            }
        }
        else
        {
            this.bubbleTimer = 0;
            this.bubbleActive = false;
        }
    }
    else
    {
        this.bubbleTimer = 0;
        this.bubbleActive = false;
    }
}
public override
Is that ALL your code? If not, that last line is out of place.
 
Example:
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 string deathText)
{
    if(this.bubbleActive)
    {
        damage = 0; // Will take 0 damage when the player is hurt when the bubble is active.
    }
}

That is because the drawing is now done differently, as the projectile is rotating around its origin.

Is that ALL your code? If not, that last line is out of place.
Do I get rid of the last line? and yes, thats all of the code.
 
Do I get rid of the last line? and yes, thats all of the code.
Whelp, then you have a bad case of incorrect line endings. If that's all the code, it should look like this:
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Enderuim.Projectiles
{
    public class EnderuimBubble : ModPlayer
    {
        public bool bubbleArmor;
        public bool bubbleActive;
        public int bubbleTimer;

        public override void ResetEffects()
        {
            this.bubbleArmor = false;
            this.bubbleActive = false;
        }

        public override void PostUpdateEquips()
        {
            if(this.bubbleArmor)
            {
                if(player.velocity == Vector2.Zero)
                {
                    if(this.bubbleTimer++ >= 120) // 2 second cooldown
                    {
                        this.bubbleActive = true;
                    }
                }
                else
                {
                    this.bubbleTimer = 0;
                    this.bubbleActive = false;
                }
            }
            else
            {
                this.bubbleTimer = 0;
                this.bubbleActive = false;
            }
        }
    }
}
 
Do I put the prehurt in the bubble or the armour code?
First of all, it should not be 'bubble code'. I advice you to only use one ModPlayer class instance for every mod you make, since usage of more might result in lag.
Second, the PreHurt should be one the ModPlayer class. If you followed the link I gave you, you would have seen the method was part of that class.
So it is not possible to change?
Hmmm, it might be with some tweaking, but not really sure what a good way would be atm.
 
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Items\Armor\EnderuimChest.cs(36,4) : error CS0103: The name 'bubbleArmour' does not exist in the current context

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Projectiles\EnderuimBubble.cs(45,26) : error CS0161: 'Enderuim.Projectiles.EnderuimBubble.PreHurt(bool, bool, ref int, ref int, ref bool, ref bool, ref bool, ref bool, ref string)': not all code paths return a value

Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Enderuim.Items.Armor
{
    public class EnderuimChest : ModItem
    {
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Body);
            return true;
        }

        public override void SetDefaults()
        {
            item.name = "Enderuim Chestplate";
            item.width = 22;
            item.height = 24;
            AddTooltip2("Increase of Melee speed and Melee damage");
            item.value = 100000;
            item.rare = 2;
            item.defense = 38;
        }
                public override bool IsArmorSet(Item head, Item body, Item legs)
        {
            return body.type == mod.ItemType("EnderuimHelm") && legs.type == mod.ItemType("EnderuimLeggings");
        }
                public override void UpdateArmorSet(Player player)
        {
            player.setBonus = "Increased Melee Stats";
            player.meleeDamage *= 0.3f;
            player.meleeSpeed += 0.3f;
            bubbleArmour = true;

        }
                        public override void UpdateEquip(Player player)
        {
            player.meleeDamage += 0.2f;
            player.meleeSpeed += 0.2f;
        }

    }
}
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Enderuim.Projectiles
{
    public class EnderuimBubble : ModPlayer
    {
        public bool bubbleArmor;
        public bool bubbleActive;
        public int bubbleTimer;

        public override void ResetEffects()
        {
            this.bubbleArmor = false;
            this.bubbleActive = false;
        }

        public override void PostUpdateEquips()
        {
            if(this.bubbleArmor)
            {
                if(player.velocity == Vector2.Zero)
                {
                    if(this.bubbleTimer++ >= 120) // 2 second cooldown
                    {
                        this.bubbleActive = true;
                    }
                }
                else
                {
                    this.bubbleTimer = 0;
                    this.bubbleActive = false;
                }
            }
            else
            {
                this.bubbleTimer = 0;
                this.bubbleActive = false;
            }
        }
                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 string deathText)
{
    if(this.bubbleActive)
    {
        damage = 0; // Will take 0 damage when the player is hurt when the bubble is active.
    }
}
    }
}
[doublepost=1461752217,1461752093][/doublepost]
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Items\Armor\EnderuimChest.cs(36,4) : error CS0103: The name 'bubbleArmour' does not exist in the current context

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Projectiles\EnderuimBubble.cs(45,26) : error CS0161: 'Enderuim.Projectiles.EnderuimBubble.PreHurt(bool, bool, ref int, ref int, ref bool, ref bool, ref bool, ref bool, ref string)': not all code paths return a value

Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Enderuim.Items.Armor
{
    public class EnderuimChest : ModItem
    {
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Body);
            return true;
        }

        public override void SetDefaults()
        {
            item.name = "Enderuim Chestplate";
            item.width = 22;
            item.height = 24;
            AddTooltip2("Increase of Melee speed and Melee damage");
            item.value = 100000;
            item.rare = 2;
            item.defense = 38;
        }
                public override bool IsArmorSet(Item head, Item body, Item legs)
        {
            return body.type == mod.ItemType("EnderuimHelm") && legs.type == mod.ItemType("EnderuimLeggings");
        }
                public override void UpdateArmorSet(Player player)
        {
            player.setBonus = "Increased Melee Stats";
            player.meleeDamage *= 0.3f;
            player.meleeSpeed += 0.3f;
            bubbleArmour = true;

        }
                        public override void UpdateEquip(Player player)
        {
            player.meleeDamage += 0.2f;
            player.meleeSpeed += 0.2f;
        }

    }
}
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Enderuim.Projectiles
{
    public class EnderuimBubble : ModPlayer
    {
        public bool bubbleArmor;
        public bool bubbleActive;
        public int bubbleTimer;

        public override void ResetEffects()
        {
            this.bubbleArmor = false;
            this.bubbleActive = false;
        }

        public override void PostUpdateEquips()
        {
            if(this.bubbleArmor)
            {
                if(player.velocity == Vector2.Zero)
                {
                    if(this.bubbleTimer++ >= 120) // 2 second cooldown
                    {
                        this.bubbleActive = true;
                    }
                }
                else
                {
                    this.bubbleTimer = 0;
                    this.bubbleActive = false;
                }
            }
            else
            {
                this.bubbleTimer = 0;
                this.bubbleActive = false;
            }
        }
                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 string deathText)
{
    if(this.bubbleActive)
    {
        damage = 0; // Will take 0 damage when the player is hurt when the bubble is active.
    }
}
    }
}
my fault on the first one, it needs to be modPlayer.bubbleArmor = true; right?
 
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Items\Armor\EnderuimChest.cs(36,4) : error CS0103: The name 'bubbleArmour' does not exist in the current context

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Projectiles\EnderuimBubble.cs(45,26) : error CS0161: 'Enderuim.Projectiles.EnderuimBubble.PreHurt(bool, bool, ref int, ref int, ref bool, ref bool, ref bool, ref bool, ref string)': not all code paths return a value

Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Enderuim.Items.Armor
{
    public class EnderuimChest : ModItem
    {
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Body);
            return true;
        }

        public override void SetDefaults()
        {
            item.name = "Enderuim Chestplate";
            item.width = 22;
            item.height = 24;
            AddTooltip2("Increase of Melee speed and Melee damage");
            item.value = 100000;
            item.rare = 2;
            item.defense = 38;
        }
                public override bool IsArmorSet(Item head, Item body, Item legs)
        {
            return body.type == mod.ItemType("EnderuimHelm") && legs.type == mod.ItemType("EnderuimLeggings");
        }
                public override void UpdateArmorSet(Player player)
        {
            player.setBonus = "Increased Melee Stats";
            player.meleeDamage *= 0.3f;
            player.meleeSpeed += 0.3f;
            bubbleArmour = true;

        }
                        public override void UpdateEquip(Player player)
        {
            player.meleeDamage += 0.2f;
            player.meleeSpeed += 0.2f;
        }

    }
}
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;

namespace Enderuim.Projectiles
{
    public class EnderuimBubble : ModPlayer
    {
        public bool bubbleArmor;
        public bool bubbleActive;
        public int bubbleTimer;

        public override void ResetEffects()
        {
            this.bubbleArmor = false;
            this.bubbleActive = false;
        }

        public override void PostUpdateEquips()
        {
            if(this.bubbleArmor)
            {
                if(player.velocity == Vector2.Zero)
                {
                    if(this.bubbleTimer++ >= 120) // 2 second cooldown
                    {
                        this.bubbleActive = true;
                    }
                }
                else
                {
                    this.bubbleTimer = 0;
                    this.bubbleActive = false;
                }
            }
            else
            {
                this.bubbleTimer = 0;
                this.bubbleActive = false;
            }
        }
                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 string deathText)
{
    if(this.bubbleActive)
    {
        damage = 0; // Will take 0 damage when the player is hurt when the bubble is active.
    }
}
    }
}
Uhm...
In the Armor set update, you'll want to get your ModPlayer class instance from the given player and set the bubbleArmor boolean that way. There is no bubbleArmor variable in your ModItem now, is there?
And in the PreHurt function, return true.
So it is not possible to change?
Hang on, try the following draw line instead:
Code:
Main.spriteBatch.Draw(texture, (projectile.position - origin) - Main.screenPosition, new Rectangle?(Utils.Frame(texture, 1, Main.projFrames[projectile.type], 0, projectile.frame)), lightColor * projectile.Opacity, projectile.rotation, origin, projectile.scale, effect, 0);
 
Back
Top Bottom