• Journey's End on PC - Find info here and here. Please report bugs and issues for PC 1.4 and 1.4.1 to Re-Logic here.
  • Journey's End on Mobile - Find info here. Report bugs for Mobile 1.4 to DR Studios at this link and give as much detail as possible.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Console and Switch - The latest news can be found here. To report a bug, please use this link.

Standalone [1.3] tModLoader - A Modding API

XCiD

Terrarian
example? I never used modplayer before
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Mod
{
     public class Player : ModPlayer
{
     public bool accessoryOn;//this is the property Im talking about
}
}
 

Endershot355

Steampunker
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Mod
{
     public class Player : ModPlayer
{
     public bool accessoryOn;//this is the property Im talking about
}
}
Yes I know bool I just dont know how to use it in the sit im talking about
 

XCiD

Terrarian
Yes I know bool I just dont know how to use it in the sit im talking about
In an if statement, you would use

((Player)player.GetModPlayer(mod, "Player")).accessoryOn

NOTE: You have to replace "Player" with another name because Player is already an existing class (ex: change "Player" to "myModPlayer" or something)
 

Endershot355

Steampunker
so...
if
{
((Player)player.GetModPlayer(mod, "Player")).accessoryOn
}
then
{
spawning params?
]

how do I get it to spawn thou? I dont want it to spawn instantly, like an item. I just want it to enable spawning of that mob.

Oh I just relized

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
If
{ ((Player)player.GetModPlayer(mod, "Player")).accessoryOn
}
then
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0.5f : 0f;
}
}
 

XCiD

Terrarian
so...
if
{
((Player)player.GetModPlayer(mod, "Player")).accessoryOn
}
then
{
spawning params?
]

how do I get it to spawn thou? I dont want it to spawn instantly, like an item. I just want it to enable spawning of that mob.

Oh I just relized

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
If
{ ((Player)player.GetModPlayer(mod, "Player")).accessoryOn
}
then
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0.5f : 0f;
}
}
Yeah, just change "Player" to another name. Your code would allow your mob to spawn on the surface during day. Make sure, however, that CanSpawn() returns 0f if the accessoryOn is false
 

Endershot355

Steampunker
Yeah, just change "Player" to another name. Your code would allow your mob to spawn on the surface during day. Make sure, however, that CanSpawn() returns 0f if the accessoryOn is false
Does that mean it wont spawn?
[DOUBLEPOST=1457561402,1457561159][/DOUBLEPOST]
Yeah, just change "Player" to another name. Your code would allow your mob to spawn on the surface during day. Make sure, however, that CanSpawn() returns 0f if the accessoryOn is false
Also, its !Main.Day.Time. The ! means it wont, so it spawns at night ^_^
[DOUBLEPOST=1457561688][/DOUBLEPOST]One last thing, how do I make the bool go to true when I equip it?
 

XCiD

Terrarian
Does that mean it wont spawn?
[DOUBLEPOST=1457561402,1457561159][/DOUBLEPOST]
Also, its !Main.Day.Time. The ! means it wont, so it spawns at night ^_^
[DOUBLEPOST=1457561688][/DOUBLEPOST]One last thing, how do I make the bool go to true when I equip it?
Totally knew that ;)
In the Update() method of ModItem:
((Player)player.GetModPlayer(mod, "Player")).accessoryOn = true;
EDIT: also, in the PreUpdate() method of ModPlayer:
((Player)player.GetModPlayer(mod, "Player")).accessoryOn = false;
what this does is make it so that when the accessory is taken off the NPC wont spawn anymore
[DOUBLEPOST=1457564818][/DOUBLEPOST]
Does that mean it wont spawn?
and no, you would put the "return 0f;" outside of the if statement, like in an else statement.
this makes it so that the NPC wont spawn if you dont have the accessory on
 

Endershot355

Steampunker
Totally knew that ;)
In the Update() method of ModItem:
((Player)player.GetModPlayer(mod, "Player")).accessoryOn = true;
EDIT: also, in the PreUpdate() method of ModPlayer:
((Player)player.GetModPlayer(mod, "Player")).accessoryOn = false;
what this does is make it so that when the accessory is taken off the NPC wont spawn anymore
[DOUBLEPOST=1457564818][/DOUBLEPOST]
and no, you would put the "return 0f;" outside of the if statement, like in an else statement.
this makes it so that the NPC wont spawn if you dont have the accessory on
Can you make a quick example thing for me so I can easily copy paste it when I get back from dinner?
 

XCiD

Terrarian
Can you make a quick example thing for me so I can easily copy paste it when I get back from dinner?
Player:

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Mod
{
public class myModPlayer : ModPlayer
{
public bool accessoryOn = false;


public override void PreUpdate()
{
accessoryOn = false;
}

}
////////////////////////////////////////////////
Accessory:

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Mod.Items
{
public class Accessory : ModItem
{
public override void SetDefaults()
{
item.name = "NPC Thingy";
item.width = 24;
item.height = 24;
item.toolTip = "Allows stuff to spawn";
item.value = Item.buyPrice(0, 10, 0, 0);
item.rare = 9;
item.accessory = true;
item.defense = 6;
}

public override void UpdateAccessory(Player player)
{
((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn= true;
}


}
}
////////////////////////////////////////////////////////////////
NPC(just paste this in within your NPC class):

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
if(((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true;)
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0.5f : 0f;
}
return 0f;
}
 

Endershot355

Steampunker
Player:

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Mod
{
public class myModPlayer : ModPlayer
{
public bool accessoryOn = false;


public override void PreUpdate()
{
accessoryOn = false;
}

}
////////////////////////////////////////////////
Accessory:

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Mod.Items
{
public class Accessory : ModItem
{
public override void SetDefaults()
{
item.name = "NPC Thingy";
item.width = 24;
item.height = 24;
item.toolTip = "Allows stuff to spawn";
item.value = Item.buyPrice(0, 10, 0, 0);
item.rare = 9;
item.accessory = true;
item.defense = 6;
}

public override void UpdateAccessory(Player player)
{
((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn= true;
}


}
}
////////////////////////////////////////////////////////////////
NPC(just paste this in within your NPC class):

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
if(((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true;)
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0.5f : 0f;
}
return 0f;
}
Thanks so much
 

Endershot355

Steampunker
aw crap
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Items\EnderuimTotem.cs(23,22) : error CS0115: 'Enderuim.Items.EnderuimTotem.UpdateAccessory(Terraria.Player)': no suitable method found to override

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Enderuim.Items
{
public class EnderuimTotem : ModItem
{
public override void SetDefaults()
{
item.name = "Enderuim Totem";
item.width = 30;
item.height = 30;
item.toolTip = "Awakens monsters of Dark Mode when worn";
item.value = Item.buyPrice(0, 10, 0, 0);
item.rare = 9;
item.accessory = true;
item.defense = 6;
}

public override void UpdateAccessory(Player player)
{
((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn= true;
}


}
}
 

Eldrazi

Eater of Worlds
aw crap
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Items\EnderuimTotem.cs(23,22) : error CS0115: 'Enderuim.Items.EnderuimTotem.UpdateAccessory(Terraria.Player)': no suitable method found to override

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Enderuim.Items
{
public class EnderuimTotem : ModItem
{
public override void SetDefaults()
{
item.name = "Enderuim Totem";
item.width = 30;
item.height = 30;
item.toolTip = "Awakens monsters of Dark Mode when worn";
item.value = Item.buyPrice(0, 10, 0, 0);
item.rare = 9;
item.accessory = true;
item.defense = 6;
}

public override void UpdateAccessory(Player player)
{
((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn= true;
}


}
}
Code:
public override void UpdateAccessory(Player player, bool hideVisual)
^ That's the correct method signature.
 

Endershot355

Steampunker
speaking of which, how can I create something that walks around like a fighter but I can still control the spawns... Its really important for my mod.
 
Top Bottom