public static void Handle(Player player) { // Gather information. WorldObject target = player.GetTarget(); if (target == null) { ChatManager.SendSystemMessage(player, "You must select a target."); return; } Npc npc = target.AsNpc(); if (npc == null) { ChatManager.SendSystemMessage(player, "You must select an NPC."); return; } // Log admin activity. SpawnHolder npcSpawn = npc.GetSpawnHolder(); LocationHolder npcLocation = npcSpawn.GetLocation(); if (Config.LOG_ADMIN) { LogManager.LogAdmin(player.GetName() + " used command /delete " + npc + " " + npcLocation); } // Delete NPC. npc.DeleteMe(); // Send player success message. int npcId = npc.GetNpcHolder().GetNpcId(); ChatManager.SendSystemMessage(player, "You have deleted " + npcId + " from " + npcLocation); // Store in database. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(SPAWN_DELETE_QUERY, con); cmd.Parameters.AddWithValue("npc_id", npcId); cmd.Parameters.AddWithValue("x", npcLocation.GetX()); cmd.Parameters.AddWithValue("y", npcLocation.GetY()); cmd.Parameters.AddWithValue("z", npcLocation.GetZ()); cmd.Parameters.AddWithValue("heading", npcLocation.GetHeading()); cmd.Parameters.AddWithValue("respawn_delay", npcSpawn.GetRespawnDelay()); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } }
public static void Handle(Player player, string command) { // Gather information from parameters. string[] commandSplit = command.Split(' '); int npcId; if (commandSplit.Length > 1) { npcId = int.Parse(commandSplit[1]); } else { ChatManager.SendSystemMessage(player, "Proper syntax is /spawn npcId delaySeconds(optional)."); return; } int respawnDelay = 60; if (commandSplit.Length > 2) { respawnDelay = int.Parse(commandSplit[2]); } // Log admin activity. LocationHolder playerLocation = player.GetLocation(); LocationHolder npcLocation = new LocationHolder(playerLocation.GetX(), playerLocation.GetY(), playerLocation.GetZ(), playerLocation.GetHeading()); if (Config.LOG_ADMIN) { LogManager.LogAdmin(player.GetName() + " used command /spawn " + npcId + " " + respawnDelay + " at " + npcLocation); } // Spawn NPC. Npc npc = SpawnData.SpawnNpc(npcId, npcLocation, respawnDelay); // Broadcast NPC information. NpcInformation info = new NpcInformation(npc); player.ChannelSend(info); foreach (Player nearby in WorldManager.GetVisiblePlayers(player)) { nearby.ChannelSend(info); } // Send player success message. ChatManager.SendSystemMessage(player, "You have spawned " + npcId + " at " + npcLocation); // Store in database. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(SPAWN_SAVE_QUERY, con); cmd.Parameters.AddWithValue("npc_id", npcId); cmd.Parameters.AddWithValue("x", npcLocation.GetX()); cmd.Parameters.AddWithValue("y", npcLocation.GetY()); cmd.Parameters.AddWithValue("z", npcLocation.GetZ()); cmd.Parameters.AddWithValue("heading", npcLocation.GetHeading()); cmd.Parameters.AddWithValue("respawn_delay", respawnDelay); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } }
public void SetLocation(LocationHolder location) { SetLocation(location.GetX(), location.GetY(), location.GetZ(), location.GetHeading()); }