Moar Gamecraft commands!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

76 linhas
2.5KB

  1. using System;
  2. using System.Collections.Generic;
  3. using RobocraftX.GUI.CommandLine;
  4. using RobocraftX.Multiplayer;
  5. using RobocraftX.StateSync;
  6. using RobocraftX.Character;
  7. using Svelto.ECS;
  8. using Unity.Entities;
  9. using uREPL;
  10. using Svelto.Context;
  11. using RobocraftX;
  12. using RobocraftX.Physics;
  13. using GamecraftModdingAPI.Commands;
  14. namespace ExtraCommands.Waypoints
  15. {
  16. [CustomCommand("Waypoints")]
  17. class TeleportWaypointCommandEngine : ICustomCommandEngine
  18. {
  19. private Dictionary<object, float[]> _waypoints = new Dictionary<object, float[]>();
  20. public string Description => "";
  21. public string Name => "Waypoints";
  22. public IEntitiesDB entitiesDB { set; private get; }
  23. public void Ready()
  24. {
  25. CommandRegistrationHelper.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location");
  26. CommandRegistrationHelper.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint");
  27. }
  28. private void CreateWaypointCommand(object name)
  29. {
  30. RigidBodyEntityStruct reference;
  31. if (entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.OnFootGroup, out uint index,
  32. out RigidBodyEntityStruct[] array)
  33. || entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.InPilotSeatGroup, out index,
  34. out array))
  35. reference = array[index];
  36. else
  37. {
  38. Log.Output("Player not found!");
  39. return;
  40. }
  41. _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z };
  42. uREPL.Log.Output("Saved " + name.ToString());
  43. }
  44. private void TeleportToWaypointCommand(object name)
  45. {
  46. if (!_waypoints.ContainsKey(name))
  47. {
  48. uREPL.Log.Error("Waypoint not found");
  49. return;
  50. }
  51. if (entitiesDB.Exists<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.InPilotSeatGroup))
  52. {
  53. Log.Error("Cannot teleport from a pilot seat");
  54. return;
  55. }
  56. float[] loc = _waypoints[name];
  57. uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
  58. }
  59. public void Dispose()
  60. {
  61. CommandRegistrationHelper.Unregister("CreateWaypoint");
  62. CommandRegistrationHelper.Unregister("TeleportPlayerWaypoint");
  63. }
  64. }
  65. }