protected void addWaypointType(int id, string name) { Data.WaypointType attr = new Data.WaypointType(); attr.ID = id; attr.Name = name; WaypointTypes.Add(attr); }
public SerializableWaypoint CreateWaypoint(WaypointTypes type, Vector3 pos, Entity ent) { var wpy = new SerializableWaypoint(); wpy.Type = type; wpy.Position = pos; wpy.Duration = 0; wpy.VehicleSpeed = 20f; wpy.DrivingStyle = 0xC00AB; switch (type) { case WaypointTypes.EnterVehicle: if (ent != null && ent.IsValid() && ent.IsVehicle()) { wpy.VehicleTargetModel = ent.Model.Hash; } break; } if (_mainPed != null) { _mainPed.Waypoints.Add(wpy); } else { _mainActorObjective.Waypoints.Add(wpy); } return(wpy); }
public void BuildCreateWaypointMenu() { CreateWaypointMenu.Clear(); var list = new List <string>(Enum.GetNames(typeof(WaypointTypes))); _placingWaypointType = (WaypointTypes)Enum.Parse(typeof(WaypointTypes), list[0]); for (int i = 0; i < list.Count; i++) { var item = new NativeMenuItem("Create Waypoint of Type: " + list[i]); CreateWaypointMenu.AddItem(item); } CreateWaypointMenu.OnIndexChange += (sender, index) => { _placingWaypointType = (WaypointTypes)Enum.Parse(typeof(WaypointTypes), list[index]); }; CreateWaypointMenu.RefreshIndex(); }
public override bool HandleCommand(ulong userId, string command) { string[] words = command.Split(' '); if (!PluginSettings.Instance.WaypointsEnabled) { if (!PluginSettings.Instance.WaypointsEnabled) { return(false); } } string[] splits = General.SplitString(string.Join(" ", words)); if (splits.Length != 6 && splits.Length != 7 && splits.Length != 5 && splits.Length != 1) { Communication.SendPrivateInformation(userId, GetHelp()); return(true); } List <WaypointItem> items = Waypoints.Instance.Get(userId); if (PluginSettings.Instance.WaypointsMaxPerPlayer > 0 && items.Count >= PluginSettings.Instance.WaypointsMaxPerPlayer) { Communication.SendPrivateInformation(userId, string.Format("Waypoint limit has been reached. You may only have {0} waypoints at a time on this server. Please remove some waypoints in order to add new ones.", PluginSettings.Instance.WaypointsMaxPerPlayer)); return(true); } if (splits.Length == 1) { long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId); IMyEntity playerEntity = Player.FindControlledEntity(playerId); if (playerEntity == null) { Communication.SendPrivateInformation(userId, string.Format("Can't find your position")); return(true); } Vector3D pos = playerEntity.GetPosition(); string name = splits[0]; Communication.SendClientMessage(userId, string.Format("/waypoint add \"{0}\" \"{0}\" Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z))); WaypointItem item = new WaypointItem(); item.SteamId = userId; item.Name = name; item.Text = name; item.Position = pos; item.WaypointType = WaypointTypes.Neutral; Waypoints.Instance.Add(item); Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position))); } else { int len = 5; if (splits.Length > 5) { len = 6; } for (int r = len - 3; r < len; r++) { double test = 0d; if (!double.TryParse(splits[r], out test)) { Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", splits[r])); return(true); } } string add = ""; foreach (string split in splits) { if (add == "") { add += split.ToLower(); } else { add += " " + split; } } Communication.SendClientMessage(userId, string.Format("/waypoint add {0}", add)); string group = ""; if (splits.Length == 7) { group = splits[7]; } WaypointItem item = new WaypointItem(); item.SteamId = userId; item.Name = splits[0]; int diff = splits.Length > 5 ? 1 : 0; item.Text = splits[diff]; WaypointTypes type = WaypointTypes.Neutral; Enum.TryParse <WaypointTypes>(splits[diff + 1], true, out type); item.WaypointType = type; item.Position = new Vector3D(double.Parse(splits[diff + 2]), double.Parse(splits[diff + 3]), double.Parse(splits[diff + 4])); item.Group = group; Waypoints.Instance.Add(item); Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position))); } return(true); }
private void HandleWaypointAdd(string name, string text, WaypointTypes type, Vector3D position, long distance) { string waypointBuilder = @"<?xml version=""1.0""?> <MyObjectBuilder_CubeGrid xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <EntityId>0</EntityId> <PersistentFlags>CastShadows InScene</PersistentFlags> <PositionAndOrientation> <Position x=""0"" y=""0"" z=""0"" /> <Forward x=""0"" y=""-0"" z=""-1"" /> <Up x=""0"" y=""1"" z=""0"" /> </PositionAndOrientation> <GridSizeEnum>Large</GridSizeEnum> <CubeBlocks> <MyObjectBuilder_CubeBlock xsi:type=""MyObjectBuilder_Beacon""> <SubtypeName>LargeBlockBeacon</SubtypeName> <EntityId>0</EntityId> <Min x=""0"" y=""1"" z=""0"" /> <BlockOrientation Forward=""Forward"" Up=""Up"" /> <ColorMaskHSV x=""0"" y=""-1"" z=""0"" /> <ShareMode>None</ShareMode> <DeformationRatio>0</DeformationRatio> <ShowOnHUD>false</ShowOnHUD> <Enabled>true</Enabled> <BroadcastRadius>{0}</BroadcastRadius> </MyObjectBuilder_CubeBlock> <MyObjectBuilder_CubeBlock xsi:type=""MyObjectBuilder_Reactor""> <SubtypeName>Waypoint</SubtypeName> <EntityId>0</EntityId> <Min x=""0"" y=""0"" z=""0"" /> <BlockOrientation Forward=""Forward"" Up=""Up"" /> <ColorMaskHSV x=""0"" y=""-1"" z=""0"" /> <ShareMode>None</ShareMode> <DeformationRatio>0</DeformationRatio> <ShowOnHUD>false</ShowOnHUD> <Enabled>true</Enabled> <Inventory> <Items> <MyObjectBuilder_InventoryItem> <Amount>1</Amount> <PhysicalContent xsi:type=""MyObjectBuilder_Ingot""> <SubtypeName>Uranium</SubtypeName> </PhysicalContent> <ItemId>0</ItemId> <AmountDecimal>1</AmountDecimal> </MyObjectBuilder_InventoryItem> </Items> <nextItemId>1</nextItemId> </Inventory> </MyObjectBuilder_CubeBlock> </CubeBlocks> <IsStatic>true</IsStatic> <Skeleton /> <LinearVelocity x=""0"" y=""0"" z=""0"" /> <AngularVelocity x=""0"" y=""0"" z=""0"" /> <XMirroxPlane xsi:nil=""true"" /> <YMirroxPlane xsi:nil=""true"" /> <ZMirroxPlane xsi:nil=""true"" /> <BlockGroups /> <Handbrake>false</Handbrake> <DisplayName>Waypoint</DisplayName> </MyObjectBuilder_CubeGrid>"; try { waypointBuilder = string.Format(waypointBuilder, distance); Logging.Instance.WriteLine(string.Format("Adding Waypoint: {0} - {1} - {2}", name, type, position)); MyObjectBuilder_CubeGrid cubeGrid = MyAPIGateway.Utilities.SerializeFromXML<MyObjectBuilder_CubeGrid>(waypointBuilder); cubeGrid.DisplayName = string.Format("Waypoint_{0}", name); foreach (MyObjectBuilder_CubeBlock block in cubeGrid.CubeBlocks) { if (block is MyObjectBuilder_Beacon) { MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)block; beacon.CustomName = text; if (type == WaypointTypes.Enemy) beacon.Owner = FindEnemyPlayer(MyAPIGateway.Session.Player.PlayerID); else if (type == WaypointTypes.Allied) beacon.Owner = MyAPIGateway.Session.Player.PlayerID; } } cubeGrid.PositionAndOrientation = new MyPositionAndOrientation(position, Vector3.Forward, Vector3.Up); IMyEntity entity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(cubeGrid); if (entity != null) Logging.Instance.WriteLine(string.Format("Waypoint added")); // This makes the model invisible, but still function if (entity.PositionComp == null) Logging.Instance.WriteLine(string.Format("PositionComp is null")); else entity.PositionComp.Scale = 0.001f; if(entity.Physics == null) Logging.Instance.WriteLine(string.Format("Physics is null")); else entity.Physics.Enabled = false; } catch (Exception ex) { Logging.Instance.WriteLine(string.Format("HandleWaypointAdd(): {0}", ex.ToString())); } }
public override bool HandleCommand(ulong userId, string[] words) { if (!PluginSettings.Instance.WaypointsEnabled) { if (!PluginSettings.Instance.WaypointsEnabled) { return(false); } } string[] splits = General.SplitString(string.Join(" ", words)); if (splits.Length != 6 && splits.Length != 7 && splits.Length != 1) { Communication.SendPrivateInformation(userId, GetHelp()); return(true); } string playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId); long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId); IMyFaction faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId); if (faction == null) { Communication.SendPrivateInformation(userId, string.Format("Unable to find your faction information. You must be in a faction to use this.")); return(true); } List <WaypointItem> items = Waypoints.Instance.Get((ulong)faction.FactionId); if (PluginSettings.Instance.WaypointsMaxPerFaction > 0 && items.Count >= PluginSettings.Instance.WaypointsMaxPerFaction) { Communication.SendPrivateInformation(userId, string.Format("Waypoint limit has been reached. You may only have {0} faction waypoints at a time on this server. Please remove some waypoints in order to add new ones.", PluginSettings.Instance.WaypointsMaxPerPlayer)); return(true); } if (splits.Length == 1) { IMyEntity playerEntity = Player.FindControlledEntity(playerId); if (playerEntity == null) { Communication.SendPrivateInformation(userId, string.Format("Can't find your position")); return(true); } Vector3D pos = playerEntity.GetPosition(); string name = splits[0]; foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers) { if (Player.CheckPlayerSameFaction(userId, steamId)) { Communication.SendClientMessage(steamId, string.Format("/waypoint add \"{0}\" \"{0}\" Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z))); } } WaypointItem item = new WaypointItem(); item.SteamId = (ulong)faction.FactionId; item.Name = name; item.Text = name; item.Position = pos; item.WaypointType = WaypointTypes.Neutral; item.Leader = faction.IsLeader(playerId); Waypoints.Instance.Add(item); Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: {0} at {1} by {2}", item.Name, General.Vector3DToString(item.Position), playerName)); } else { for (int r = 3; r < 6; r++) { double test = 0d; if (!double.TryParse(splits[r], out test)) { Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", splits[r])); return(true); } } string add = ""; foreach (string split in splits) { if (add == "") { add += split.ToLower(); } else { add += " " + split; } } foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers) { if (Player.CheckPlayerSameFaction(userId, steamId)) { Communication.SendClientMessage(steamId, string.Format("/waypoint add {0}", add)); } } string group = ""; if (splits.Length == 7) { group = splits[7]; } WaypointItem item = new WaypointItem(); item.SteamId = (ulong)faction.FactionId; item.Name = splits[0]; item.Text = splits[1]; WaypointTypes type = WaypointTypes.Neutral; Enum.TryParse <WaypointTypes>(splits[2], true, out type); item.WaypointType = type; item.Position = new Vector3D(double.Parse(splits[3]), double.Parse(splits[4]), double.Parse(splits[5])); item.Group = group; item.Leader = faction.IsLeader(playerId); Waypoints.Instance.Add(item); Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: {0} at {1} by {2}", item.Name, General.Vector3DToString(item.Position), playerName)); } return(true); }
private void HandleWaypointAdd(string name, string text, WaypointTypes type, Vector3D position, long distance) { string waypointBuilder = @"<?xml version=""1.0""?> <MyObjectBuilder_CubeGrid xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <EntityId>0</EntityId> <PersistentFlags>CastShadows InScene</PersistentFlags> <PositionAndOrientation> <Position x=""0"" y=""0"" z=""0"" /> <Forward x=""0"" y=""-0"" z=""-1"" /> <Up x=""0"" y=""1"" z=""0"" /> </PositionAndOrientation> <GridSizeEnum>Large</GridSizeEnum> <CubeBlocks> <MyObjectBuilder_CubeBlock xsi:type=""MyObjectBuilder_Beacon""> <SubtypeName>LargeBlockBeacon</SubtypeName> <EntityId>0</EntityId> <Min x=""0"" y=""1"" z=""0"" /> <BlockOrientation Forward=""Forward"" Up=""Up"" /> <ColorMaskHSV x=""0"" y=""-1"" z=""0"" /> <ShareMode>None</ShareMode> <DeformationRatio>0</DeformationRatio> <ShowOnHUD>false</ShowOnHUD> <Enabled>true</Enabled> <BroadcastRadius>{0}</BroadcastRadius> </MyObjectBuilder_CubeBlock> <MyObjectBuilder_CubeBlock xsi:type=""MyObjectBuilder_Reactor""> <SubtypeName>Waypoint</SubtypeName> <EntityId>0</EntityId> <Min x=""0"" y=""0"" z=""0"" /> <BlockOrientation Forward=""Forward"" Up=""Up"" /> <ColorMaskHSV x=""0"" y=""-1"" z=""0"" /> <ShareMode>None</ShareMode> <DeformationRatio>0</DeformationRatio> <ShowOnHUD>false</ShowOnHUD> <Enabled>true</Enabled> <Inventory> <Items> <MyObjectBuilder_InventoryItem> <Amount>1</Amount> <PhysicalContent xsi:type=""MyObjectBuilder_Ingot""> <SubtypeName>Uranium</SubtypeName> </PhysicalContent> <ItemId>0</ItemId> <AmountDecimal>10000</AmountDecimal> </MyObjectBuilder_InventoryItem> </Items> <nextItemId>1</nextItemId> </Inventory> </MyObjectBuilder_CubeBlock> </CubeBlocks> <IsStatic>true</IsStatic> <Skeleton /> <LinearVelocity x=""0"" y=""0"" z=""0"" /> <AngularVelocity x=""0"" y=""0"" z=""0"" /> <XMirroxPlane xsi:nil=""true"" /> <YMirroxPlane xsi:nil=""true"" /> <ZMirroxPlane xsi:nil=""true"" /> <BlockGroups /> <Handbrake>false</Handbrake> <DisplayName>Waypoint</DisplayName> </MyObjectBuilder_CubeGrid>"; try { waypointBuilder = string.Format(waypointBuilder, distance); Logging.Instance.WriteLine(string.Format("Adding Waypoint: {0} - {1} - {2}", name, type, position)); MyObjectBuilder_CubeGrid cubeGrid = MyAPIGateway.Utilities.SerializeFromXML<MyObjectBuilder_CubeGrid>(waypointBuilder); cubeGrid.DisplayName = string.Format("Waypoint_{0}", name); foreach (MyObjectBuilder_CubeBlock block in cubeGrid.CubeBlocks) { if (block is MyObjectBuilder_Beacon) { MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)block; beacon.CustomName = text; if (type == WaypointTypes.Enemy) beacon.Owner = FindEnemyPlayer(MyAPIGateway.Session.Player.PlayerID); else if (type == WaypointTypes.Allied) beacon.Owner = MyAPIGateway.Session.Player.PlayerID; } } MyAPIGateway.Entities.RemapObjectBuilder(cubeGrid); cubeGrid.PositionAndOrientation = new MyPositionAndOrientation( position, Vector3.Forward, Vector3.Up ); IMyEntity entity = MyAPIGateway.Entities.CreateFromObjectBuilder( cubeGrid ); if ( entity != null ) Logging.Instance.WriteLine( string.Format( "Waypoint added" ) ); if ( entity.Physics == null ) Logging.Instance.WriteLine( string.Format( "Physics is null" ) ); else entity.Physics.Enabled = false; entity.Flags &= ~EntityFlags.Visible; entity.Flags &= ~EntityFlags.Sync; entity.Flags &= ~EntityFlags.Save; //TODO: Make sure this works //((MyEntity)entity).IsPreview = true; ClientWaypoints.Add( entity.EntityId ); MyAPIGateway.Entities.AddEntity( entity, true ); //HACK: workaround because the Sync flag is not being respected //remove this whenever the devs fix it //spawn the waypoint in disabled because they show up for one game tick //on all remote clients. wait a bit for them to cleanup then turn it on /* Timer timer = new Timer( ); timer.Interval = 100; timer.Elapsed += ( object source, ElapsedEventArgs e ) => { List<IMySlimBlock> blocks = new List<IMySlimBlock>( ); ((IMyCubeGrid)entity).GetBlocks( blocks ); foreach ( IMySlimBlock block in blocks ) { IMyCubeBlock cubeBlock = block.FatBlock; if ( cubeBlock.BlockDefinition.TypeId == typeof( MyObjectBuilder_Beacon ) ) { Sandbox.ModAPI.Ingame.IMyBeacon beacon = (Sandbox.ModAPI.Ingame.IMyBeacon)cubeBlock; beacon.RequestEnable( true ); } } };*/ } catch (Exception ex) { Logging.Instance.WriteLine(string.Format("HandleWaypointAdd(): {0}", ex.ToString())); } }
public void BuildCreateWaypointMenu() { CreateWaypointMenu.Clear(); var list = new List<string>(Enum.GetNames(typeof(WaypointTypes))); _placingWaypointType = (WaypointTypes)Enum.Parse(typeof(WaypointTypes), list[0]); for (int i = 0; i < list.Count; i++) { var item = new NativeMenuItem("Create Waypoint of Type: " + list[i]); CreateWaypointMenu.AddItem(item); } CreateWaypointMenu.OnIndexChange += (sender, index) => { _placingWaypointType = (WaypointTypes)Enum.Parse(typeof(WaypointTypes), list[index]); }; CreateWaypointMenu.RefreshIndex(); }
public SerializableWaypoint CreateWaypoint(WaypointTypes type, Vector3 pos, Entity ent) { var wpy = new SerializableWaypoint(); wpy.Type = type; wpy.Position = pos; wpy.Duration = 0; wpy.VehicleSpeed = 20f; wpy.DrivingStyle = 0xC00AB; switch (type) { case WaypointTypes.EnterVehicle: if (ent != null && ent.IsValid() && ent.IsVehicle()) { wpy.VehicleTargetModel = ent.Model.Hash; } break; } if(_mainPed != null) _mainPed.Waypoints.Add(wpy); else _mainActorObjective.Waypoints.Add(wpy); return wpy; }
public void CreateWaypoint(WaypointTypes wpType, Transform target) { if(wpType == WaypointTypes.Follow) { } }
public void CreateWaypoint(WaypointTypes wpType, Vector2 position) { if(wpType == WaypointTypes.Extraction) { GameObject wp = Instantiate(waypointPrefab, position, Quaternion.identity) as GameObject; wp.GetComponent<PointerHUDElement>().targetWP = position; } }
// @author: Craig Broskow, created skeleton IEnumerator RunMovement(WaypointTypes wp) { switch(wp.moveType) { case MovementType.BEZIERCURVE: StartCoroutine(MoveBezierCurve(wp.waypointDuration, wp.point1.transform.position, wp.point2.transform.position, wp.point3.transform.position)); yield return new WaitForSeconds(wp.waypointDuration); break; case MovementType.LOOKANDRETURN: break; case MovementType.STRAIGHTLINE: StartCoroutine(MoveStraightLine(Time.time, wp.waypointDuration, wp.point1.position, wp.point2.position)); yield return new WaitForSeconds(wp.waypointDuration); break; case MovementType.WAIT: yield return new WaitForSeconds(wp.waypointDuration); break; default: Debug.Log ("Invalid movement type!"); break; } // end switch yield return null; }