add and fix a lot
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using LabApi.Events.Handlers;
|
||||
using LabApi.Features;
|
||||
using LabApi.Features.Wrappers;
|
||||
using LabApi.Loader.Features.Plugins;
|
||||
using MEC;
|
||||
using Logger = LabApi.Features.Console.Logger;
|
||||
using Random = System.Random;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
|
||||
namespace CustomItemSpawn;
|
||||
|
||||
public class CustomItemSpawn : Plugin<ItemConfig>
|
||||
{
|
||||
public override string Name => "CustomItemSpawn";
|
||||
public override string Author => "Code002Lover";
|
||||
public override Version Version { get; } = new(1, 0, 0);
|
||||
public override string Description => "Spawns items in a custom location.";
|
||||
public override Version RequiredApiVersion { get; } = new(LabApiProperties.CompiledVersion);
|
||||
|
||||
private static CustomItemSpawn _singleton;
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
_singleton = this;
|
||||
ServerEvents.RoundStarted += OnRoundStart;
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
ServerEvents.RoundStarted -= OnRoundStart;
|
||||
_singleton = null;
|
||||
}
|
||||
|
||||
private static void OnRoundStart()
|
||||
{
|
||||
Timing.CallDelayed(10,SpawnItems);
|
||||
}
|
||||
|
||||
private static void SpawnItems()
|
||||
{
|
||||
Random rng = new();
|
||||
|
||||
foreach (var pickup in from configPair in _singleton.Config!.Items
|
||||
let itemType = configPair.Key
|
||||
let config = configPair.Value
|
||||
where rng.NextDouble() * 100f <= config.Chance
|
||||
select Pickup.Create(itemType, config.Position + new Vector3(0, 1, 0)))
|
||||
{
|
||||
if (pickup == null)
|
||||
{
|
||||
Logger.Error("Could not create pickup.");
|
||||
break;
|
||||
}
|
||||
|
||||
pickup.Spawn();
|
||||
Logger.Debug($"Spawned Pickup: {pickup.Base} @ {pickup.Position}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemConfig
|
||||
{
|
||||
public Dictionary<ItemType, SpecificConfig> Items { get; set; } = new()
|
||||
{
|
||||
{
|
||||
ItemType.GunAK,
|
||||
new SpecificConfig
|
||||
{
|
||||
Position = new Vector3(0, 0, 0),
|
||||
Chance = 100f
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public class SpecificConfig
|
||||
{
|
||||
public Vector3 Position { get; set; }
|
||||
public float Chance { get; set; } = 100f;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<Optimize>true</Optimize>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<Optimize>true</Optimize>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>..\dependencies\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp-firstpass">
|
||||
<HintPath>..\dependencies\Assembly-CSharp-firstpass.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mirror">
|
||||
<HintPath>..\dependencies\Mirror.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Pooling">
|
||||
<HintPath>..\dependencies\Pooling.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>..\dependencies\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Northwood.LabAPI" Version="1.0.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user