public static InGameMap BuildMap(Map map) { InGameMap igMap = new InGameMap(); foreach (MapObject mapObject in map.Objects) { switch (mapObject.MapObjectType) { case MapObjectType.Ped: igMap.Peds.Add(CreatePed(mapObject)); break; case MapObjectType.Prop: igMap.Objects.Add(CreateObject(mapObject)); break; case MapObjectType.Vehicle: igMap.Vehicles.Add(CreateVehicle(mapObject)); break; } Script.Yield(); } return(igMap); }
private void LoadMap() { // this function is going to deserialize the map editor file in the path we specified in the settings. // if the file doesn't exist we just return to make sure we're not getting any errors. try { var serializer = new XmlSerializer(typeof(Map)); StreamReader reader = new StreamReader(_mapName); Map map = (Map)serializer.Deserialize(reader); reader.Close(); _inGameMap = MapBuilder.BuildMap(map); var blip = _inGameMap.AddBlip(); blip.Sprite = BlipSprite.CaptureHouse; blip.Name = Path.GetFileNameWithoutExtension(_mapName); // make sure that the meta data is not null. if (map.Metadata == null) { return; } // There's no meta data to display. if (string.IsNullOrEmpty(map.Metadata.Name) && string.IsNullOrEmpty(map.Metadata.Creator) && string.IsNullOrEmpty(map.Metadata.Description)) { return; } HelpText.Display($"{(!string.IsNullOrEmpty(map.Metadata.Name) ? "Name: " + map.Metadata.Name : "")}" + $"\n{(!string.IsNullOrEmpty(map.Metadata.Creator) ? "Creator: " + map.Metadata.Creator : "")}~s~" + $"\n{(!string.IsNullOrEmpty(map.Metadata.Description) ? "Description: " + map.Metadata.Description : "")}", false); } catch (Exception e) { UI.Notify("Map Error: ~r~" + e.Message); string prevText = string.Empty; const string path = "./scripts/ArrestErrors.log"; if (File.Exists(path)) { prevText = File.ReadAllText(path); } File.WriteAllText(path, $"{prevText}[{DateTime.UtcNow:hh:mm:ss}] [ERROR] " + e.Message + "\n" + e.StackTrace + "\n"); } }