1. Tell me what is best to use when I want to put an object in the crate

    The idea is when I use hook "OnLootEntity" the right thing falls out to me when I open the drawer, but the problem here is that I can open this box many times and the object will drop out to me a lot
    Code:
    private void OnLootEntity(BasePlayer player, BaseEntity entity)
            {
                if (!_config.RandomDrop)
                    return;            if (entity.name.Contains("crate_tools") || entity.name.Contains("crate_basic") || entity.name.Contains("crate_normal") || entity.name.Contains("crate_elite") || entity.name.Contains("supply_drop") || entity.name.Contains("codelockedhackablecrate"))
                {
                    if ((Random.Range(0f, 100f) < _config.ChanceOfDrop))
                    {
                        var item = CreateSupply();                    var container = entity.GetComponent<StorageContainer>();
                        item.MoveToContainer(container.inventory);
                    }
                }
            }
    The idea is when I use hook "OnEntitySpawned" the necessary thing will appear immediately in the boxes that just appeared, but then I understand it is necessary to get the plugin correctly unloaded, because these items will remain even when unloading the plugin this is the first and second thing that this item will appear only in the newly appeared crate
    Code:
    private void OnEntitySpawned(BaseNetworkable entity)
            {
                if (!_config.RandomDrop)
                    return;            if (entity.name.Contains("crate_tools") || entity.name.Contains("crate_basic") || entity.name.Contains("crate_normal") || entity.name.Contains("crate_elite") || entity.name.Contains("supply_drop") || entity.name.Contains("codelockedhackablecrate"))
                {
                    if ((Random.Range(0f, 100f) < _config.ChanceOfDrop))
                    {
                        var item = CreateSupply();                    var container = entity.GetComponent<StorageContainer>();
                        item.MoveToContainer(container.inventory);
                    }
                }
            }
    [DOUBLEPOST=1530492915][/DOUBLEPOST]thanks for the ideas in advance
     
  2. Hi,
    I think I understand what you mean; Sounds like you would need to keep a record of crates that should have the item in them, and a record of crates that have already given out the item.

    That way, when the plugin reloads, you can tidy up and have all these items removed.

    I don't know if there's a specific hook for when an item is moved or taken but, if not, you could use "OnLootEntityEnd" to check if the item has been removed, I guess, and then add that crate to your second list to prevent the item being added agin next time around.
     
  3. Thanks for the thought! I was able to do via the hook OnEntitySpawned.
    I'm made a couple of methods of repopulation loot.