private static MyCharacter CreateCharacterBase(MatrixD worldMatrix, ref Vector3 velocity, string characterName, string model, Vector3? colorMask, bool AIMode, bool useInventory = true, MyBotDefinition botDefinition = null) { MyCharacter character = new MyCharacter(); MyObjectBuilder_Character objectBuilder = MyCharacter.Random(); objectBuilder.CharacterModel = model ?? objectBuilder.CharacterModel; if (colorMask.HasValue) objectBuilder.ColorMaskHSV = colorMask.Value; objectBuilder.JetpackEnabled = MySession.Static.CreativeMode; objectBuilder.Battery = new MyObjectBuilder_Battery { CurrentCapacity = 1 }; objectBuilder.AIMode = AIMode; objectBuilder.DisplayName = characterName; objectBuilder.LinearVelocity = velocity; objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); character.Init(objectBuilder); MyEntities.RaiseEntityCreated(character); MyEntities.Add(character); System.Diagnostics.Debug.Assert(character.GetInventory() as MyInventory != null, "Null or unexpected inventory type returned!"); if (useInventory) MyWorldGenerator.InitInventoryWithDefaults(character.GetInventory() as MyInventory); else if (botDefinition != null) { // use inventory from bot definition botDefinition.AddItems(character); } //character.PositionComp.SetWorldMatrix(worldMatrix); if (velocity.Length() > 0) { var jetpack = character.JetpackComp; if (jetpack != null) jetpack.EnableDampeners(false, false); } return character; }
public override void SetupCharacter(MyWorldGenerator.Args generatorArgs) { Debug.Assert(MySession.Static.LocalHumanPlayer != null, "Local controller does not exist!"); if (MySession.Static.LocalHumanPlayer == null) return; var characterOb = Sandbox.Game.Entities.Character.MyCharacter.Random(); if (Transform.HasValue && MyPerGameSettings.CharacterStartsOnVoxel) { var transform = Transform.Value; transform.Position = FixPositionToVoxel(transform.Position); characterOb.PositionAndOrientation = transform; } else { characterOb.PositionAndOrientation = Transform; } characterOb.JetpackEnabled = JetpackEnabled; characterOb.DampenersEnabled = DampenersEnabled; if (characterOb.Inventory == null) characterOb.Inventory = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Inventory>(); FillInventoryWithDefaults(characterOb.Inventory, generatorArgs.Scenario); var character = new MyCharacter(); character.Name = "Player"; character.Init(characterOb); MyEntities.RaiseEntityCreated(character); MyEntities.Add(character); this.CreateAndSetPlayerFaction(); MySession.Static.LocalHumanPlayer.SpawnIntoCharacter(character); }