• Labor of Love is here! Visit our Labor of Love thread for a special message from the team, a look at brand new Labor of Love merch, and the changelog (minus a few surprises 😉)

Standalone [1.3] tModLoader - A Modding API

Solo-Ion

Dungeon Spirit
This issue has been getting annoying. Error CS0103: The name 'player' does not exist in the current context. Like, how?

C:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader.IO;
using Terraria.UI;
using Terraria.Utilities;
using NewJourney.Tiles;
using Terraria;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using NewJourney.Projectiles;

namespace NewJourney.NPCs
{
    public class StuffedSlime : ModNPC
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Stuffed Slime");
    }
        public override void SetDefaults()
        {
            npc.width = 20;
            npc.height = 20;
            npc.damage = 6;
            npc.defense = 4;
            npc.lifeMax = 60;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 50f;
            npc.knockBackResist = 1f;
        npc.noGravity = false;
        npc.scale = 1f;
        npc.aiStyle = -1;
        npc.buffImmune[20] = true;
        npc.buffImmune[24] = true;
            Main.npcFrameCount[npc.type] = 2;
            animationType = 535;
        }

        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
        if (spawnInfo.player.ZoneOverworldHeight && Main.dayTime)
           return SpawnCondition.OverworldDaySlime.Chance * 0.1f;
            return SpawnCondition.OverworldNight.Chance * 0.05f;  
        }

        public override void NPCLoot()
        {
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 23, Main.rand.Next(1, 20));
    }

    private const int AI_State_Slot = 0;
    private const int AI_Timer_Slot = 1;
    private const int AI_Shoot_Time_Slot = 2;

    private const int State_Asleep = 0;
    private const int State_Slime = 1;
    private const int State_ShootSlime = 2;

    public float AI_State {
        get => npc.ai[AI_State_Slot];
        set => npc.ai[AI_State_Slot] = value;
    }
    public float AI_Timer {
        get => npc.ai[AI_Timer_Slot];
        set => npc.ai[AI_Timer_Slot] = value;
    }

    public float AI_ShootTime {
        get => npc.ai[AI_Shoot_Time_Slot];
        set => npc.ai[AI_Shoot_Time_Slot] = value;
    }

    public override void AI()
        {
        if (AI_State == State_Asleep) {
            npc.TargetClosest(true);
            if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f) {
                AI_State = State_Slime;
                AI_Timer = 0;
                Main.PlaySound(SoundID.NPCHit1, npc.position);
            }
        }
        else if (AI_State == State_Slime) {
            if (Main.player[npc.target].Distance(npc.Center) < 750f) {
                AI_Timer++;
                if (AI_Timer == 1) {
                    npc.TargetClosest(true);
                    npc.velocity = new Vector2(npc.direction * 2, -2f);
                }
                else if (AI_Timer >= 360) {
                    Vector2 velocity = player.Center - npc.Center;
                    float magnitude = Magnitude(velocity);
                    int type = 468;
                    if (magnitude > 0)
                    {
                        velocity *= 18 / magnitude;
                    }
                    else
                    {
                        velocity = new Vector2(0f, 5f);
                    }
                        Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, mod.ProjectileType("SlimeBall"), 30, 3f, Main.myPlayer, 1, 8);
                        Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, 605, 30, 3f, Main.myPlayer, 4, 4);
                    AI_State = State_ShootSlime;
                    AI_Timer = 0;
                    Main.PlaySound(SoundID.NPCHit1, npc.position);
                }
            }
        }
        else if (AI_State == State_ShootSlime) {
            npc.aiStyle = -1;
            AI_Timer += 1;
            if (AI_Timer == 1 && Main.netMode != NetmodeID.MultiplayerClient) {
                AI_ShootTime = Main.rand.NextBool() ? 150 : 200;
                npc.netUpdate = true;
                Vector2 velocity = player.Center - npc.Center;
                float magnitude = Magnitude(velocity);
                int type = 468;
                if (magnitude > 0)
                {
                    velocity *= 18 / magnitude;
                }
                else
                {
                velocity = new Vector2(0f, 5f);
                }
                Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, mod.ProjectileType("SlimeBall"), 30, 3f, Main.myPlayer, 1, 8);
                Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, 605, 30, 3f, Main.myPlayer, 4, 4);
            }
            if (AI_Timer > AI_ShootTime) {
                AI_State = State_Slime;
                AI_Timer = 0;
                Main.PlaySound(SoundID.NPCHit1, npc.position);
            }
        }
    }
    private const int Frame_Slime_1 = 0;
    private const int Frame_Slime_2 = 1;

    public override void FindFrame(int frameHeight) {
        npc.spriteDirection = npc.direction;
        npc.frameCounter++;
        if (npc.frameCounter < 10) {
            npc.frame.Y = Frame_Slime_1 * frameHeight;
        }
        else if (npc.frameCounter < 20) {
            npc.frame.Y = Frame_Slime_2 * frameHeight;
        }
        else {
            npc.frameCounter = 0;
        }
    }
    }
}
Apparently, the code doesn't like it when I replace 'player' with 'Player', because it gives me another error. Error CS0120: An object reference was required for the non-static field, method, or property, 'Entity.Center'

And just in case you are asking: Yes, I have had this issue a few times before.
Looking through your code, you have several different references to player. Main.player[npc.target] and player.Center. Main.player[npc.target] is a reference to a specific player in the player array, but player.Center has nothing before it to say which player is being targeted. I don't know exactly what all of your code is for, but you may want to use Main.player[npc.target].Center.
 

mistermiggens

Terrarian
hi Jofairden
Tmodloader browser is down for me when i click download on a mod it show that its downloading then it just returns to the browser.

i think it has something to do with my computer running off of Ubuntu Linux

i've tried re-installing Tmodloader but it doesn't work

do you know why its not working?
 

Simple

Official Terrarian
Anybody know how to make an item have a chance to place different tiles? I want to make a watermelon that can place 4 different tiles, all are watermelon. I'd greatly appreciate any help that is sent!
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace NewJourney.Items.Placeable
{
    public class Watermelon : ModItem
    {
        public override void SetStaticDefaults()
        {
            ItemID.Sets.SortingPriorityMaterials[item.type] = 58;
            DisplayName.SetDefault("Watermelon");
            Tooltip.SetDefault("");
        }

        public override void SetDefaults()
        {
            item.useStyle = ItemUseStyleID.SwingThrow;
            item.useTurn = true;
            item.useAnimation = 15;
            item.useTime = 10;
            item.autoReuse = true;
            item.maxStack = 999;
            item.consumable = true;
            item.width = 12;
            item.height = 12;
            item.value = 3000;
            item.rare = 1;
            if (Main.rand.NextBool(4)) {
                item.createTile = TileType<Tiles.WatermelonTile1>();
            }
            else if (Main.rand.NextBool(4)) {
                item.createTile = TileType<Tiles.WatermelonTile2>();
            }
            else if (Main.rand.NextBool(4)) {
                item.createTile = TileType<Tiles.WatermelonTile3>();
            }
            else if (Main.rand.NextBool(4)) {
                item.createTile = TileType<Tiles.WatermelonTile4>();
            }
        }
    }
}
I believe I need something more complicated then just that...
 

Myth

Terrarian
I checked the github for new releases and it says tmodloader has been updated for 1.4 on steam, but when I launch tmodloader on steam it says 1.3.5.3. Any reason why?
 

BlackScout

Terrarian
I checked the github for new releases and it says tmodloader has been updated for 1.4 on steam, but when I launch tmodloader on steam it says 1.3.5.3. Any reason why?
z4ho84U.png
 

Stickweedy

Terrarian
Hey everyone , i'm having a problem creating a TML server, when i start a server with mods or i even tried with no mods i get an error in the log file:
[18:41:56] [10/WARN] [tML]: Silently Caught Exception:
System.Runtime.InteropServices.COMException: The requested resource is in use. (Exception of HRESULT : 0x800700AA)
at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription)
at Terraria.Netplay.OpenPort()
at Terraria.Netplay.ServerLoop(Object threadContext)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
therefore nobody is able to join through IP, but i can join from 127.0..0.1 but not from IP.

And if i launch it from "Host & Play" friends can join the world via steam.
I had a server for 1.4 vanilla terraria and never had an issue.
Is there anything im doing wrong or is there something missing for the tModLoaderServer.exe to run smoothly?
 

Attachments

  • server.log
    3.6 KB · Views: 88

White_Shadow

Eye of Cthulhu
Hello guys, my friend is having a problem with one of his worlds. When he tried to load it, the load was successful but once it did load the whole screen except for the UI was a deep purple color. Any subsequent load attempts returned an error. Could a mod be causing this or is it something with the world file?
 

Nyanisty

Terrarian
Hello guys, my friend is having a problem with one of his worlds. When he tried to load it, the load was successful but once it did load the whole screen except for the UI was a deep purple color. Any subsequent load attempts returned an error. Could a mod be causing this or is it something with the world file?

try pressing try pressing F11 or F12 when he loads in game.one of those buttons removes the ui.
he probably pressed it by mistake
 

CST1229

Official Terrarian
rip theres anti-piracy now
i guess i cannot play modded from now on

UPDATE: I bought the game. ok?
 
Last edited:

Segnitia

Terrarian
I recently downloaded the tmodloader v0.11.7.4 but because of my 2gb ram, I couldnt play any game with mods. I thought about playing vanilla terraria and for some reason, the game crashes when i click single player. I get a glimpse of my characters and the color they originally had was different. I know that you can uninstall tmodloader uaing steams verify game files but sadly, our internet has been dead for months. Is there any other way to revert this problem?
 

Solo-Ion

Dungeon Spirit
I recently downloaded the tmodloader v0.11.7.4 but because of my 2gb ram, I couldnt play any game with mods. I thought about playing vanilla terraria and for some reason, the game crashes when i click single player. I get a glimpse of my characters and the color they originally had was different. I know that you can uninstall tmodloader uaing steams verify game files but sadly, our internet has been dead for months. Is there any other way to revert this problem?
If you installed tModLoader via Steam, you simply need to launch Terraria instead of tModLoader. But if you installed with the zip file, open Terraria's install folder and assuming that it wasn't overwritten, you should see both the vanilla and moded .exe files. Rename the moded one to something else and rename the vanilla one to Terraria.exe.
 

Segnitia

Terrarian
If you installed tModLoader via Steam, you simply need to launch Terraria instead of tModLoader. But if you installed with the zip file, open Terraria's install folder and assuming that it wasn't overwritten, you should see both the vanilla and moded .exe files. Rename the moded one to something else and rename the vanilla one to Terraria.exe.
Thats the mistake i made. I overwritten the contents folder which i think is the problem
 

Solo-Ion

Dungeon Spirit
Thats the mistake i made. I overwritten the contents folder which i think is the problem
If you happen to know someone with the vanilla game, they could give you the files you're missing on a usb drive. Otherwise, you'll need to find a way to get an internet connection. Do you have a mobile with an internet connection? Could you do a USB tether to get internet?
 

SapphireSuicune

Spazmatism
The name 'player' does not exist in the current context.
using Terraria.ModLoader;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.UI;
using System.IO;
using System.Numerics;
using Microsoft.Xna.Framework;
using System;

namespace ZephyrMod.Projectiles
{
public class ZephyrBarrierBookProjectile : ModProjectile
{
public override void SetStaticDefaults()
{
// DisplayName.SetDefault("ZephyrBarrierBook"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
}

public override void SetDefaults()
{
projectile.Name = "ZephyrBarrierBook";
projectile.width = 400;
projectile.height = 400;
projectile.aiStyle = 71;
projectile.friendly = true;
projectile.penetrate = 3;
projectile.magic = true;
}
public override void AI()
{
Player p = Main.player[projectile.owner];

double deg = (double)projectile.ai[1];
double rad = deg * (Math.PI / 180);
double dist = 64;

projectile.position.X = player.Center.X - (int)(Math.Cos(rad) * dist) - projectile.width / 2;
projectile.position.Y = player.Center.Y - (int)(Math.Sin(rad) * dist) - projectile.height / 2;


projectile.ai[1] += 1f;
}
}
}
 

Solo-Ion

Dungeon Spirit
The name 'player' does not exist in the current context.
using Terraria.ModLoader;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.UI;
using System.IO;
using System.Numerics;
using Microsoft.Xna.Framework;
using System;

namespace ZephyrMod.Projectiles
{
public class ZephyrBarrierBookProjectile : ModProjectile
{
public override void SetStaticDefaults()
{
// DisplayName.SetDefault("ZephyrBarrierBook"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
}

public override void SetDefaults()
{
projectile.Name = "ZephyrBarrierBook";
projectile.width = 400;
projectile.height = 400;
projectile.aiStyle = 71;
projectile.friendly = true;
projectile.penetrate = 3;
projectile.magic = true;
}
public override void AI()
{
Player p = Main.player[projectile.owner];

double deg = (double)projectile.ai[1];
double rad = deg * (Math.PI / 180);
double dist = 64;

projectile.position.X = player.Center.X - (int)(Math.Cos(rad) * dist) - projectile.width / 2;
projectile.position.Y = player.Center.Y - (int)(Math.Sin(rad) * dist) - projectile.height / 2;


projectile.ai[1] += 1f;
}
}
}
Change
Player p = Main.player[projectile.owner];
to
Player player = Main.player[projectile.owner];

Or else player.Center.X and .Y won't have a clue which player you mean.
 

Yeahfrick

Official Terrarian
c:\Users\AARONCITO\Documents\My Games\Terraria\ModLoader\Mod Sources\noname\Items\LatormWings.cs(10,30) : error CS0115: 'noname.Items.WingsName.Autoload(ref string, ref string, System.Collections.Generic.IList<Terraria.ModLoader.EquipType>)': no se encontró ningún miembro adecuado que invalidar

c:\Users\AARONCITO\Documents\My Games\Terraria\ModLoader\Mod Sources\noname\Items\LatormWings.cs(32,30) : error CS0115: 'noname.Items.WingsName.VerticalWingSpeeds(ref float, ref float, ref float, ref float, ref float)': no se encontró ningún miembro adecuado que invalidar

c:\Users\AARONCITO\Documents\My Games\Terraria\ModLoader\Mod Sources\noname\Items\LatormWings.cs(42,30) : error CS0115: 'noname.Items.WingsName.HorizontalWingSpeeds(ref float, ref float)': no se encontró ningún miembro adecuado que invalidar

(sorry i have terraria in spanish)

code:

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

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

public override void SetDefaults()
{
item.name = "LatormWings";
item.width = 22;
item.height = 20;
item.toolTip = "";
item.value = 10000;
item.rare = 4;
item.accessory = true;
}

public override void UpdateAccessory(Player player, bool hideVisual)
{
player.wingTimeMax = 10; //wings Height
}

public override void VerticalWingSpeeds(ref float ascentWhenFalling, ref float ascentWhenRising,
ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend)
{
ascentWhenFalling = 0.85f;
ascentWhenRising = 0.15f;
maxCanAscendMultiplier = 1f;
maxAscentMultiplier = 3f;
constantAscend = 0.135f;
}

public override void HorizontalWingSpeeds(ref float speed, ref float acceleration)
{
speed = 9f;
acceleration *= 2.5f;
}

public override void AddRecipes() //How to craft this item
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "latorm", 10); //you need 10 Wood
recipe.AddTile(TileID.anvil); //at work bench
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

the code is from Al0n37 . i think i have this error because its outdated
 
Last edited:
Top Bottom