diff --git a/ModExamples/18CustomItemService/18CustomItemService.csproj b/ModExamples/18CustomItemService/18CustomItemService.csproj new file mode 100644 index 00000000..3a793a15 --- /dev/null +++ b/ModExamples/18CustomItemService/18CustomItemService.csproj @@ -0,0 +1,32 @@ + + + + net9.0 + _18CustomItemService + enable + enable + Library + + + + + + ..\TempReferences\Core.dll + false + false + false + + + ..\TempReferences\SptCommon.dll + false + false + false + + + ..\TempReferences\SptDependencyInjection.dll + false + false + false + + + diff --git a/ModExamples/18CustomItemService/CustomItemServiceExample.cs b/ModExamples/18CustomItemService/CustomItemServiceExample.cs new file mode 100644 index 00000000..2412d264 --- /dev/null +++ b/ModExamples/18CustomItemService/CustomItemServiceExample.cs @@ -0,0 +1,117 @@ +using Core.Models.Eft.Common.Tables; +using Core.Models.External; +using Core.Models.Logging; +using Core.Models.Spt.Mod; +using Core.Models.Utils; +using Core.Servers; +using Core.Services.Mod; + +namespace _18CustomItemService; + +public class CustomItemServiceExample : IPostDBLoadMod, IPostSptLoadMod +{ + private readonly CustomItemService _customItemService; + private readonly ISptLogger _logger; + private readonly DatabaseServer _databaseServer; + + public CustomItemServiceExample( + CustomItemService customItemService, + ISptLogger logger, + DatabaseServer databaseServer + ) + { + _customItemService = customItemService; + _logger = logger; + _databaseServer = databaseServer; + } + + public void PostDBLoad() + { + //Example of adding new item by cloning an existing item using `createCloneDetails` + var exampleCloneItem = new NewItemFromCloneDetails + { + ItemTplToClone = ItemTpl.SHOTGUN_MP18_762X54R_SINGLESHOT_RIFLE, + // ParentId refers to the Node item the gun will be under, you can check it in https://db.sp-tarkov.com/search + ParentId = "5447b6094bdc2dc3278b4567", + // The new id of our cloned item - MUST be a valid mongo id, search online for mongo id generators + NewId = "677eed5f2e040616bc7246b6", + // Flea price of item + FleaPriceRoubles = 50000, + // Price of item in handbook + HandbookPriceRoubles = 42500, + // Handbook Parent Id refers to the category the gun will be under + HandbookParentId = "5b5f78e986f77447ed5636b1", + //you see those side box tab thing that only select gun under specific icon? Handbook parent can be found in Spt_Data\Server\database\templates. + Locales = new Dictionary + { + { + "en", new LocaleDetails + { + Name = "MP-18 12g", + ShortName = "Custom MP18", + Description = "A custom MP18 chambered in 12G" + } + } + }, + OverrideProperties = new Props + { + Chambers = + [ + new Slot + { + Name = "patron_in_weapon_000", + Id = "61f7c9e189e6fb1a5e3ea791", + Parent = "CustomMP18", + Props = new SlotProps + { + Filters = + [ + new SlotFilter + { + Filter = + [ + "560d5e524bdc2d25448b4571", + "5d6e6772a4b936088465b17c", + "5d6e67fba4b9361bc73bc779", + "5d6e6806a4b936088465b17e", + "5d6e68dea4b9361bcc29e659", + "5d6e6911a4b9361bd5780d52", + "5c0d591486f7744c505b416f", + "58820d1224597753c90aeb13", + "5d6e68c4a4b9361b93413f79", + "5d6e68a8a4b9360b6c0d54e2", + "5d6e68e6a4b9361c140bcfe0", + "5d6e6869a4b9361c140bcfde", + "5d6e68b3a4b9361bca7e50b5", + "5d6e6891a4b9361bd473feea", + "5d6e689ca4b9361bc8618956", + "5d6e68d1a4b93622fe60e845" + ] + } + ] + }, + Required = false, + MergeSlotWithChildren = false, + Proto = "55d4af244bdc2d962f8b4571" + } + ] + }, + }; + + _customItemService.CreateItemFromClone(exampleCloneItem); // Send our data to the function that creates our item + } + + // Optional - check if our item is in the server or not + public void PostSptLoad() + { + var items = _databaseServer.GetTables().Templates.Items; + + if (items.TryGetValue("677eed5f2e040616bc7246b6", out var item)) + { + _logger.LogWithColor("Item exists in DB", LogTextColor.Red, LogBackgroundColor.Yellow); + return; + } + + _logger.LogWithColor("Item was not found in DB", LogTextColor.Red, LogBackgroundColor.Yellow); + } +} diff --git a/ModExamples/ModExamples.sln b/ModExamples/ModExamples.sln index b4f6f8a4..7475d4c6 100644 --- a/ModExamples/ModExamples.sln +++ b/ModExamples/ModExamples.sln @@ -33,6 +33,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "14AfterDBLoadHook", "14Afte EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "15HttpListenerExample", "15HttpListenerExample\15HttpListenerExample.csproj", "{15F2B434-439E-498E-9B85-B7BBC2F4AFA4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18CustomItemService", "18CustomItemService\18CustomItemService.csproj", "{ADE10F29-58D6-4C13-B217-7C737DFB413A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -99,6 +101,10 @@ Global {15F2B434-439E-498E-9B85-B7BBC2F4AFA4}.Debug|Any CPU.Build.0 = Debug|Any CPU {15F2B434-439E-498E-9B85-B7BBC2F4AFA4}.Release|Any CPU.ActiveCfg = Release|Any CPU {15F2B434-439E-498E-9B85-B7BBC2F4AFA4}.Release|Any CPU.Build.0 = Release|Any CPU + {ADE10F29-58D6-4C13-B217-7C737DFB413A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADE10F29-58D6-4C13-B217-7C737DFB413A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADE10F29-58D6-4C13-B217-7C737DFB413A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADE10F29-58D6-4C13-B217-7C737DFB413A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE