FB_BEN_EN = {};
FB_BEN_EN.bebidacontextmenu = function(_player, context, worldobjects)
    local player = getSpecificPlayer(_player);
    local object = worldobjects[1];
    local objType = nil;
    
    if object:getContainer() then
        objType = object:getContainer():getType():gsub("vending", "");
    end

    if not (objType == "pop") then return end

    if not ((SandboxVars.ElecShutModifier > -1 and GameTime:getInstance():getNightsSurvived() < SandboxVars.ElecShutModifier) or object:getSquare():haveElectricity()) then
        player:Say("No power");
        return;
    end

    function fix(object)
        object:getModData().FB_BEN_EN_isEmpty = nil;
    end
    local objectData = object:getModData();
    if (objectData.FB_BEN_EN_isEmpty==nil) then
        if(ZombRand(180)==1) then 
            objectData.FB_BEN_EN_isEmpty=true;
            object:transmitModData();
        end
    end
    if (objectData.FB_BEN_EN_isEmpty==true) then
        player:Say("The machine is empty");
        return
    end

    if not player:getInventory():contains("Money") then return end
    if objType ~= nil then
        context:addOption("Buy NRG Energy Drink", player, FB_BEN_EN.comprar_be, object);
    end
end

FB_BEN_EN.comprar_be = function(player, object)
    luautils.walkAdj(player, object:getSquare(), false);
    player:faceThisObject(object);

    local objType = object:getContainer():getType():gsub("vending", "");
    player:getInventory():RemoveOneOf("Base.Money");
    player:playSound("VendingSound");

    local items = {"FB_BEN_EN.NRG"};
    object:getContainer():AddItem(items[ZombRand(#items)+1]);
    local objectData = object:getModData();
    
    if(ZombRand(180)==1) then 
        objectData.FB_BEN_EN_isEmpty=true;
        object:transmitModData();
    end
end

Events.OnPreFillWorldObjectContextMenu.Add(FB_BEN_EN.bebidacontextmenu);