From f4aa36b8d1469e47dca13c7cb49419b951228e9a Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 12:12:02 +0200 Subject: [PATCH] Fixed a possible bug causing TSPlayer.StrikeNPC to cause NullReferenceExceptions depending on the calling thread. --- TShockAPI/TSPlayer.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 986d3147..bd13cfd4 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -899,6 +899,10 @@ namespace TShockAPI public void StrikeNPC(int npcid, int damage, float knockBack, int hitDirection) { + // Main.rand is thread static. + if (Main.rand == null) + Main.rand = new Random(); + Main.npc[npcid].StrikeNPC(damage, knockBack, hitDirection); NetMessage.SendData((int) PacketTypes.NpcStrike, -1, -1, "", npcid, damage, knockBack, hitDirection); }