Skip to content

Commit

Permalink
Merge pull request #483 from sailro/spawn
Browse files Browse the repository at this point in the history
Add spawn command
  • Loading branch information
sailro authored Apr 14, 2024
2 parents 8446497 + be79452 commit 3b16d88
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
56 changes: 56 additions & 0 deletions Features/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Comfort.Common;
using EFT.CameraControl;
using EFT.Interactive;
using EFT.InventoryLogic;
using EFT.Trainer.Configuration;
Expand Down Expand Up @@ -447,6 +449,7 @@ private void RegisterCommands()
CreateCommand("load", () => LoadSettings());
CreateCommand("save", SaveSettings);

CreateCommand("spawn", $"(?<{ValueGroup}>.+)", SpawnItem);
CreateCommand("template", $"(?<{ValueGroup}>.+)", FindTemplates);

// Load default configuration
Expand Down Expand Up @@ -496,6 +499,59 @@ private void FindTemplates(Match match)
AddConsoleLog($"found {templates.Length.ToString().Cyan()} template(s)");
}

private void SpawnItem(Match match)
{
var matchGroup = match.Groups[ValueGroup];
if (matchGroup is not { Success: true })
return;

var player = GameState.Current?.LocalPlayer;
if (player == null)
return;

var search = matchGroup.Value;
var templates = FindTemplates(search).ToArray();

switch (templates.Length)
{
case 0:
AddConsoleLog("No template found!");
return;
case > 1:
{
foreach (var template in templates)
AddConsoleLog($"{template._id}: {template.ShortNameLocalizationKey.Localized().Green()} [{template.NameLocalizationKey.Localized()}]");

AddConsoleLog($"found {templates.Length.ToString().Cyan()} templates, be more specific");
return;
}
}

var tpl = templates[0];
var poolManager = Singleton<PoolManager>.Instance;

poolManager.LoadBundlesAndCreatePools(PoolManager.PoolsCategory.Raid, PoolManager.AssemblyType.Online, [..tpl.AllResources], JobPriority.Immediate).ContinueWith(delegate
{
var itemFactory = Singleton<ItemFactory>.Instance;
var item = itemFactory.CreateItem(MongoID.Generate(), tpl._id, null);
if (item == null)
{
AddConsoleLog("Failed to create item!");
return Task.CompletedTask;
}

_ = new TraderControllerClass(item, item.Id, item.ShortName);
var go = poolManager.CreateLootPrefab(item, ECameraType.Default);

go.SetActive(value: true);
var lootItem = Singleton<GameWorld>.Instance.CreateLootWithRigidbody(go, item, item.ShortName, Singleton<GameWorld>.Instance, randomRotation: false, null, out _);
lootItem.transform.SetPositionAndRotation(player.Transform.position + player.Transform.forward * 2f + player.Transform.up * 0.5f, player.Transform.rotation);
lootItem.LastOwner = player;

return Task.CompletedTask;
});
}

private void SetupWindowCoordinates()
{
bool needfix = false;
Expand Down
3 changes: 3 additions & 0 deletions NLog.EFT.Trainer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<Reference Include="ItemTemplate.Types">
<HintPath>$(EFTManagedPath)\ItemTemplate.Types.dll</HintPath>
</Reference>
<Reference Include="DissonanceVoip">
<HintPath>$(EFTManagedPath)\DissonanceVoip.dll</HintPath>
</Reference>
<Reference Include="0Harmony">
<HintPath>Installer\Resources\0Harmony.dll</HintPath>
</Reference>
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ This trainer hooks into the command system, so you can easily setup features usi
| radar | `on` or `off` | `off` | Show/Hide radar |
| save | | | Save settings to `trainer.ini` |
| savetl | `[filename]` | | Save current tracklist to file |
| spawn | `[name]` | | Spawn object in front of player |
| stamina | `on` or `off` | `off` | Enable/Disable unlimited stamina |
| stash | `on` or `off` | `off` | Show/Hide stashes |
| status | | | Show status of all features |
| template | `name` | | Search for templates by short/name |
| template | `[name]` | | Search for templates by short/name |
| thermal | `on` or `off` | `off` | Enable/Disable thermal vision |
| track | `[name]` or `*` | | Track all items matching `name` |
| track | `[name]` `<color>` | | Ex: track `roler` `red` |
Expand Down

0 comments on commit 3b16d88

Please sign in to comment.