Set vending stock for items

Hello. Im coding a plugin to set vending stock.
Im trying to set the stock of an item via the function "OnRefreshVendingStock", however it is not working.

Im doing this. 

void OnRefreshVendingStock(NPCVendingMachine machine, Item item)
{
     item.Amount= 100;
}

But its returning "Type `Item' does not contain a definition for `Amount' and no extension method `Amount' of type `Item' could be found. Are you missing an assembly reference?" How can i fix this?

Amount should be lowercase.

When i do that i just get 

Failed to call hook 'OnRefreshVendingStock' on plugin 'Stock v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)                                                                                    at Oxide.Plugins.InfiniteStock.OnRefreshVendingStock (NPCVendingMachine machine, Item item) [0x00012] in <afc6af71258c41e896eb52cad69583f9>:0
at Oxide.Plugins.Stock.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00052] in <afc6af71258c41e896eb52cad69583f9>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <09575a60985045248bcb43b20faeeb99>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <bae5f1223fce49c493b01571c99dce02>:0

Piecemeal remote debugging your plugin is going to be a tedious process.

Are you sure you even need to create a new plugin for this? Multiple plugins exist to alter vending machine stocking behavior, including Custom Vending Setup and Vending In Stock.

I do need a new one, as im altering the stock to "infinite". Vending in stock doesnt do that, just makes it so it wont run out ever. I need to change the amount so you can buy more of the item. Like selling fertilizer for scrap, you can only do 93 at a time. If you have 10000 fertilizer, it will take a while. If i set the stock to 1000000, you wont have to worry about that. 

Custom Vending Setup allows you to increase the stock. You can use that plugin alone to increase the stock to as high as you want, restock as much as you want at once, and restock as often as you want.

For each item in each vending machine, you could set:

Max stock: 10000
Seconds between refills: 0
Refill amount: 10000

but would i have to do that every single wipe? Or could i just put it in a config?

The settings are persisted across wipes.

You would only have to do it once per vending machine per monument. For example, once you do it for a specific vending machine at outpost, every outpost in future wipes/maps will have the same settings. If new monuments are introduced into the game with vending machines (which is extremely rare), you would have to customize those new vending machines at that time. If you use custom maps and want to customize the vending machines provided by those, you would have to do it once for each of those maps.

Yea fair, i just use alot of custom maps. I just wanna be able to hook onto NPCVendingMachine and just set the stock to every one to be max it can go. 

I'll consider adding that sort of functionality into Custom Vending Setup later on.

For now, looking at the OnRefreshVendingStock hook, it doesn't actually pass the item, only the item definition. Also, I'm not really sure what that hook is intended to be used for since it doesn't stock anything, I think it's just related to networking.

A simple design would be:

  • When the plugin loads, find all NPC vending machines, find all items in the vending machine and increase their amount
  • When a purchase is made, find all items in the vending machine and increase their amount (OnVendingTransaction -> NextTick)

Sweet thank you. How can i find all the items? I feel like thats a noob question, but im not really sure how to find the definitions of types. How can i?

Something like this.

private void OnServerInitialized()
{
    foreach (var entity in BaseNetworkable.serverEntities)
    {
        var vendingMachine = entity as NPCVendingMachine;
        if (vendingMachine == null)
            continue;

        RestockItems(vendingMachine);
    }
}

private void OnVendingTransaction(NPCVendingMachine vendingMachine)
{
    NextTick(() =>
    {
        if (vendingMachine != null && !vendingMachine.IsDestroyed)
        {
            RestockItems(vendingMachine);
        }
    });
}

private void RestockItems(NPCVendingMachine vendingMachine)
{
    foreach (var item in vendingMachine.inventory.itemList)
    {
        if (item.amount != 1000000)
        {
            item.amount = 1000000;
            item.MarkDirty();
        }
    }
}

oh uhh. wow. Thank you so much man, youre awesome!!!!