I'm building a plugin to allow admins to drop weapon spawns by dropping weapons on the ground and then I'm trying to implement a respawn system so that after a weapon is picked up, that weapon will respawn after a certain amount of time. And the respawn is where I'm having issues. Here's where I'm at code-wise (just a sample with a 3 second respawn for testing):
private object OnItemPickup(Item item, BasePlayer player)
{
var weapon = item.GetHeldEntity() as BaseProjectile;
if (weapon == null)
{
return;
}
timer.Once(3, () =>
{
ItemExtensions.Clone(item).Spawn();
});
return null;
}private static class ItemExtensions
{
public static BaseEntity Clone(Item item)
{
var droppedEntity = item.GetHeldEntity() ?? item.GetWorldEntity();
if (droppedEntity == null)
{
return null;
}
return
GameManager.server
.CreateEntity
(
droppedEntity.PrefabName,
droppedEntity.transform.position,
droppedEntity.transform.rotation
);
}
}The problem is that the item that spawns isn't able to be picked up. I know I'm close to getting it, but this is the blocker I can't seem to get around. Any help would be much appreciated.