public PlayerNPC(string name, Level level, PlayerLocation playerLocation, onInteract action = null, string gameName = "") : base(name, level) { NameTag = name; KnownPosition = playerLocation; string npcSkinLocation; if (string.IsNullOrEmpty(gameName) || !File.Exists((npcSkinLocation = $@"C:\Users\Administrator\Desktop\npc-skins\{gameName}-npc.png"))) { Skin = new Skin { SkinData = Skin.GetTextureFromFile("Skin.png") }; } else { Skin = new Skin { SkinData = Skin.GetTextureFromFile(npcSkinLocation) }; } Scale = 1.8D; //Ensure this NPC is visible Width = 0.43; Height = 3.0D; _action = action; }
public static void SpawnHubNPC(GameLevel level, string npcName, PlayerLocation spawnLocation, string command) { NPCSpawnTask spawnTask = (gameLevel) => { try { if (String.IsNullOrEmpty(npcName)) { Console.WriteLine("§c§l(!) §r§cInvalid NPC text. /hologram <text>"); return; } npcName = npcName.Replace("_", " ").Replace("&", "§"); if (npcName.Equals("\"\"")) { npcName = ""; } string gameName = command; onInteract action = null; if (!String.IsNullOrEmpty(command)) { if (command.StartsWith("GID:")) { gameName = command.Split(':')[1]; switch (gameName) { case "murder": case "build-battle": { action = player => { //Freeze the players movement player.Freeze(true); RunnableTask.RunTaskLater(() => ExternalGameHandler.AddPlayer(player, gameName), 200); }; break; } } } } if (gameName.Equals(command)) { SkyUtil.log($"Unknown game command '{command}'"); return; } //Ensure this NPC can be seen PlayerNPC npc; /*if (action != null) * { * npc = new PlayerNPC("§a(Punch to play)", gameLevel, spawnLocation, action, gameName) { Scale = 1.5 }; * } * else * { * npc = new PlayerNPC("§e(Coming Soon)", gameLevel, spawnLocation, null, gameName) { Scale = 1.5 }; * }*/ npc = new PlayerNPC("", gameLevel, spawnLocation, action, gameName) { Scale = 1.5 }; SkyCoreAPI.Instance.AddPendingTask(() => { npc.KnownPosition = spawnLocation; //npc.Width = 0D; //npc.Height = 1.0D; npc.SpawnEntity(); }); { PlayerLocation playerCountLocation = (PlayerLocation)spawnLocation.Clone(); //Spawn a hologram with player counts PlayerCountHologram hologram = new PlayerCountHologram(npcName, gameLevel, playerCountLocation, gameName); SkyCoreAPI.Instance.AddPendingTask(() => hologram.SpawnEntity()); } { PlayerLocation gameNameLocation = (PlayerLocation)spawnLocation.Clone(); gameNameLocation.Y += 3.1f; Hologram gameNameHologram = new Hologram(npcName, gameLevel, gameNameLocation); SkyCoreAPI.Instance.AddPendingTask(() => gameNameHologram.SpawnEntity()); } Console.WriteLine($"§e§l(!) §r§eSpawned NPC with text '{npcName}§r'"); } catch (Exception e) { Console.WriteLine(e); } }; if (String.IsNullOrWhiteSpace(command)) { SkyUtil.log("Found null command as key. Using npc game name instead."); command = npcName; } GameNPCs.Add(command, spawnTask); if (level != null) { spawnTask.Invoke(level); } }