Lucas Posted June 20, 2015 Share Posted June 20, 2015 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 More sharing options...
KorruptkSwades Posted June 20, 2015 Share Posted June 20, 2015 In game the empty pop bottle is in the main inventory and you just fill her up. Not in players hand... Link to comment Share on other sites More sharing options...
Ryfoxx Posted June 27, 2015 Share Posted June 27, 2015 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 endendHowever, 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 More sharing options...
Ryfoxx Posted June 28, 2015 Share Posted June 28, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now