tModLoader Official tModLoader Help Thread

Just copy that line, that code works fine for me. Did you also set NPCID.Sets.MPAllowedEnemies[type] to true in your NPC like the comments say?
Okay, i understood how spawn bosses, but how i can spawn any npc (include hostile npcs) in multiplayer?
 
Last edited:
It's very similar to the previous code, call NPC.NewNPC() rather than NPC.SpawnOnPlayer(), and use MessageID.SyncNPC for the netcode part
I don't know what i'm doing wrong but my code don't work:

public override void OnConsumeItem(Player player)
{
int NPCType = rnd.Next(-65, 578);
int npcid = NPC.NewNPC(new EntitySource_ItemUse(player, Item.ModItem.Item), (int)player.Center.X, (int)player.Center.Y, NPCType);
NetMessage.SendData(MessageID.SyncNPC, number: npcid);
}

And why at description of NewNPC() method says "This method should't be called on multiplayer clients"?
 
You're using negative numbers for NPCType which won't work, NetID npcs are weird when it comes to summoning them. It spawns the actual base NPC, like a Blue Slime, then applies the NetID defaults to it to change it to another, like Green Slime.

Also if you are in multiplayer, you should always spawn an NPC on the Server, so it's spawned for everyone.
 
You're using negative numbers for NPCType which won't work, NetID npcs are weird when it comes to summoning them. It spawns the actual base NPC, like a Blue Slime, then applies the NetID defaults to it to change it to another, like Green Slime.

Also if you are in multiplayer, you should always spawn an NPC on the Server, so it's spawned for everyone.
How i can run mod on Server or what i'm need to do if i want spawn NPC on server? Please, i can't find solution for three days now , i'm really need help.
 
Some hooks run on client and server at the same time, some are client only. If you hover over them in VS it'll explain, otherwise you can read the docs at
TML Docs

Then you'd just do netmode checks before certain code, like check if the NetMode == NetModeID.Server
Netcode Guide
 
Some hooks run on client and server at the same time, some are client only. If you hover over them in VS it'll explain, otherwise you can read the docs at
TML Docs

Then you'd just do netmode checks before certain code, like check if the NetMode == NetModeID.Server
Netcode Guide
I'm know about check net mode and I'm need which hooks use by server or client and server. I had checked Main.NetMode value and it always equals 1 in OnConsumeItem method and UseItem method. I had tried switch net mode, syncs NPC, use some hooks, find examples with npc spawn, read the tmodloader documentation, but all of that don't give me result. Maybe you can give me example or you know how change Net mode or what I'm need to doing, I really tired with that question... .
 
You can't change the netmode yourself. It's either server, singleplayer client or multiplayer client. Hooks automatically run on certain netmodes or all 3, and in that case you'd just check the netmode before running your code. If the docs don't say what netmode something runs for, you'll just have to experiment.
 
I solved my problem! I used OnConsumeItem hook which run only on client side, but I should use hook UseItem, which run on server and client side. Thanks you a lot, michaelsoftman!
 
In my mod I added a buff that let's you move through the ground, and I want the swimming animation (or something similar) to play while moving like this otherwise it looks silly. How can I do this, or more generally how do I move the player's arms and legs and stuff? Been looking for ages through the source and just can't figure it out. Any help would be greatly appreciated!
 
Hello, I have a problem that I dont understand hhow to fix, if somebody knows how to fix this problem with the resolution please message me
 

Attachments

  • QUE.png
    QUE.png
    666.4 KB · Views: 5
Back
Top Bottom