Jump to content

How can I fill a bottle with water while the player is keeping it in his hand?


Lucas

Recommended Posts

How can I fill a bottle with water while the player is keeping it in his hand? I started to write code for first hand, but I have no idea how to add slowly water into a bottle or even how to add a small value of water to empty or not fully empty bottle. Can I get an advice?

 

local weapon = player:getPrimaryHandItem();local weapons = player:getSecondaryHandItem();if weapon then	    local wtype = weapon:getType();    	if wtype ~= "PopBottleEmpty" then			return;		endif wtype == "PopBottleEmpty" and player:isOutside() and RainManager.isRaining() then-- slowly fill the bottle with water
Link to comment
Share on other sites

I believe you need to modify the waterAmount of the bottle, but I'm just a beginner to modding. Maybe something like this?

local weapon = player:getPrimaryHandItem();local weapons = player:getSecondaryHandItem();if weapon then    local wtype = weapon:getType();    if wtype ~= "PopBottleEmpty" then        return;    elseif wtype == "PopBottleEmpty" and player:isOutside() and RainManager.isRaining() then        weapon.waterAmount=weapon.waterAmount+1    endend

However, I think it might fill up too much. Assuming you're running it every tick, you can either use an RNG to determine when to fill it up, or fill it up every X seconds via a timer.

Link to comment
Share on other sites

Okay, I've got it. Maybe. I think.

function fillBottle()    local weapon = player:getPrimaryHandItem();    local weapons = player:getSecondaryHandItem();    if weapon then        local wtype = weapon:getType();        if player:isOutside() and RainManager:isRaining() then            if wtype == "WaterPopBottle" then                weapon:setUses(weapon:getUses()+1); -- Adds a use, I think            elseif wtype == "PopBottleEmpty" then                local container = weapon:getContainer();                weapon:getContainer():Remove(weapon); -- Removes empty bottle                local bottle = container:AddItem("Base.WaterPopBottle"); -- and fills it                bottle:setUses(1);             end        end    end    if weapons then -- repeat it again for the second weapon        local wtype = weapons:getType();        if player:isOutside() and RainManager:isRaining() then            if wtype == "WaterPopBottle" then                weapons:setUses(weapons:getUses()+1);            elseif wtype == "PopBottleEmpty" then                local container = weapons:getContainer();                weapons:getContainer():Remove(weapons); -- Removes empty bottle                local bottle = container:AddItem("Base.WaterPopBottle"); -- and fills it                bottle:setUses(1);            end        end    endendEvent.OnPlayerUpdate.Add(fillBottle); 

However, I'm not exactly sure if this will work. I'll try it, though.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...