tModLoader Official tModLoader Help Thread

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: 94
Hi! I have a problem with Terraria using TML. I've been playing with Calamity mod for a while but when I kill the Wall of Flesh, my game crashes. I've searched for some info and some people recommend turning the rest of the mods off and trying again, but Calamity is the only mod I have downloaded. Idk what to do. This is the announcement that appears when the game crashes.
 

Attachments

  • Captura de pantalla 2024-08-14 152636.png
    Captura de pantalla 2024-08-14 152636.png
    59.1 KB · Views: 41
Hi! I have a problem with Terraria using TML. I've been playing with Calamity mod for a while but when I kill the Wall of Flesh, my game crashes. I've searched for some info and some people recommend turning the rest of the mods off and trying again, but Calamity is the only mod I have downloaded. Idk what to do. This is the announcement that appears when the game crashes.
¿Puedes enviar el archivo client.log aqui?
 
What happened to all the photos in the first post?
It looks like they were being hosted on GitHub. Probably they were removed and the author of this thread hasn't bothered to fix it because this thread isn't really used since they moved to Discord.
 
Years ago when I was IP banned from the Tmod Discord because my old account got hijacked by a scam I fell for. I would love to rejoin the community a much more matured and less gullible person. Is there a way I could get into the ban appealing process of the server if it's even possible?
 
Hi I'm looking to see if anyone else remembers the jarkos mod. It vanished from the steam workshop and my files but I still have items from it, just unloaded ones. I really wanna know what happened to it and if anyone has the file for it as although it made up a small part of my build I was dependent on it and am considering making a new character. If anyone know what happened to the mod please lmk!
 

Attachments

  • 1726779951536.png
    1726779951536.png
    77 KB · Views: 28
Back
Top Bottom