Jeb Posted October 31, 2013 Share Posted October 31, 2013 I'd like to make a new item—specifically a gallon of water. Obviously no one, at least in a survival situation, would down a gallon of water at once. Is it possible to make such an item drink the water more slowly, say everytime the game would normally drink water, it would only use 1/6 or 1/8 of the amount? Ah it is not that easy you see. It will require some more or less extensive lua to make the ammo drainable. I'm working on making "drinks" drainables and I had to write a custom function for drinking.I guess it would be the same for the ammo. Not sure what files you would have to change to make it work though. From another thread, and I expect RoboMat will likely see this thread, so I'm asking him too. In what mod would I find this function, and more importantly, does this function you describe do what I'm describing? Link to comment Share on other sites More sharing options...
Jeb Posted October 31, 2013 Author Share Posted October 31, 2013 I'd like the process to be automatic, in that the game will drink from the gallon jug just as it does from the water bottles. Looking through the items list though, I see a possible solution in the bottles of wine, whereas they start as full, then go to empty, then finally to full. Would it be possible to make this a five or six step process, where the gallon would deplete up to 6 times before being empty, then back to full when refilled? Link to comment Share on other sites More sharing options...
RobertJohnson Posted October 31, 2013 Share Posted October 31, 2013 Hello, Mmh, if I understand well (French inside...), you want your big water thingy to be empty slowly. Well, if it's a drinable item, pretty easy, the max delta of a Drainable is 1, so you just have to change the UseDelta option, everytime you drink automatically from a drinable, or everytime you use it (function :Use()), we withdraw the UseDelta from the remaining Delta. So if you put something like UseDelta = 0.01, it's gonna be pretty slow to deplete Link to comment Share on other sites More sharing options...
Jeb Posted October 31, 2013 Author Share Posted October 31, 2013 I noticed that delta part, and was curious if that was its function, but I wasn't entirely certain. Thanks for the answer.For the most part, my question has been answered. I have one more in line with this though, so I'll leave it unanswered until this question gets answered. My item looks like this (the UseDelta is merely a placeholder which I'll balance later; and obviously the weight of the full jug needs to be balanced as well): item waterjugFull { IsWaterSource = TRUE, Weight = 8, CanStoreWater = TRUE, Type = Drainable, UseWhileEquipped = FALSE, UseDelta = 0.1, DisplayName = Water bottle, ReplaceOnDeplete = WaterjugEmpty, ReplaceOnUseOn = WaterSource-WaterBottleFull, Icon = WaterBottle_Full, } item waterjugEmpty { IsWaterSource = TRUE, Weight = 0.0, CanStoreWater = TRUE, Type = Drainable, UseWhileEquipped = FALSE, UseDelta = 0.1, DisplayName = Water bottle, ReplaceOnDeplete = WaterjugEmpty, ReplaceOnUseOn = WaterSource-WaterBottleFull, Icon = WaterBottle_Full, }How would I utilize ReplaceOnUseOn properly in this situation? Link to comment Share on other sites More sharing options...
RoboMat Posted October 31, 2013 Share Posted October 31, 2013 I think I had the basics of the code almost finished ... the reason I stopped was, that I had to hardcode most of the item's variables (IIRC) and that was a bit too time consuming. I will see if I can find the code later on Link to comment Share on other sites More sharing options...
Jeb Posted October 31, 2013 Author Share Posted October 31, 2013 I'd appreciate that RoboMat. Regarding my current Water Jug, this is the item: item WaterJugFull { IsWaterSource = TRUE, Weight = 3, CanStoreWater = TRUE, Type = Drainable, UseWhileEquipped = FALSE, UseDelta = 0.2, DisplayName = Water Jug (Full), ReplaceOnDeplete = WaterJugHalf, Icon = WaterJug, } item WaterJugHalf { IsWaterSource = TRUE, Weight = 1.5, CanStoreWater = TRUE, Type = Drainable, UseWhileEquipped = FALSE, UseDelta = 0.2, DisplayName = Water Jug (Half), ReplaceOnDeplete = WaterJugEmpty, Icon = WaterJug, } item WaterJugEmpty { IsWaterSource = TRUE, Weight = 0.0, CanStoreWater = TRUE, Type = Drainable, UseWhileEquipped = FALSE, UseDelta = 0, DisplayName = Water Jug (Empty), ReplaceOnDeplete = WaterJugEmpty, Icon = WaterJug, }I can't drink from it, at any time, even when I'm thirsty. I can fill it though if I pour it out. Any ideas? Link to comment Share on other sites More sharing options...
RoboMat Posted October 31, 2013 Share Posted October 31, 2013 Ugly, probably half-broken code -- =============================================================================-- -- by RoboMat-- -- Created: 28.08.13 - 13:30-- =============================================================================require'TimedActions/ISBaseTimedAction';TADrinkBooze = ISBaseTimedAction:derive("TADrinkBooze");-- -------------------------------------------------- Functions-- ----------------------------------------------------- The condition which tells the timed action if it-- is still valid.--function TADrinkBooze:isValid() return self.character:getInventory():contains(self.drink);endfunction TADrinkBooze:update() self.drink:setJobDelta(self:getJobDelta());end----- Stops the Timed Action.--function TADrinkBooze:stop() ISBaseTimedAction.stop(self); self.drink:setJobDelta(0.0);end----- Starts the Timed Action.--function TADrinkBooze:start() self.drink:setJobType("Drinking"); self.drink:setJobDelta(0.0);end----- Is called when the time has passed.--function TADrinkBooze:perform() bottle = self.drink; bottle:setJobDelta(0.0); -- Update delta bottle:setUsedDelta(bottle:getUsedDelta() - bottle:getUseDelta()); -- Check if bottle has been drained if (bottle:getUsedDelta() - bottle:getUseDelta()) <= 0 then -- Replace it with empty item bottle:Use(); end -- remove Timed Action from stack ISBaseTimedAction.perform(self);end----- Constructor--function TADrinkBooze:new(_character, _drink, _time) local o = {} setmetatable(o, self) self.__index = self o.character = _character; o.drink = _drink; o.stopOnWalk = false; o.stopOnRun = false; o.maxTime = _time; return oend-- =============================================================================-- THERE WILL BE BOOZE-- by RoboMat-- -- Created: 22.08.13 - 12:00-- =============================================================================require'Mods/Util/Utility';require'TimedActions/ISTimedActionQueue';-- -------------------------------------------------- Global variables-- ------------------------------------------------UIDrinkBooze = {};-- -------------------------------------------------- Functions-- ----------------------------------------------------- Creates a context menu entry when the player selects-- an inventory container (e.g. hiking bag).-- @param _player-- @param _context-- @param _items--function UIDrinkBooze.createMenu(_player, _context, _clickedItems) local module = "ThereWillBeBooze"; local player = getSpecificPlayer(_player); local drink; local stack; for _, item in ipairs(_clickedItems) do -- Do we have a single item? if instanceof(item, "InventoryItem") and instanceof(item, "Drainable") then -- Check if the item is part of our mod. if item:getModule() == module and not item:isWaterSource() then print("Booze it is"); drink = item; break; end elseif #_clickedItems > 1 then return; elseif type(item) == "table" then print("Clicked on stack"); stack = item; -- we have multiple items in one stack end end if drink and math.floor(drink:getUsedDelta() / drink:getUseDelta()) > 0 then _context:addOption("Drink " .. drink:getName(), _items, UIDrinkBooze.onDrinkBooze, player, drink); end -- Adds context menu entries for multiple bags. if stack then -- We start to iterate at the second index to jump over the dummy -- item that is contained in the item-table. for i = 2, #stack.items do local item = stack.items[i]; if instanceof(item, "InventoryItem") and instanceof(item, "Drainable") then if item:getModule() == module and not item:isWaterSource() and math.floor(item:getUsedDelta() / item:getUseDelta()) > 0 then _context:addOption("Drink " .. item:getName(), _items, UIDrinkBooze.onDrinkBooze, player, item); end end end endend----- Creates the timed action which empties the bag.-- @param _items-- @param _player-- @param _itemsInContainer-- @param _bag-- @param _container--function UIDrinkBooze.onDrinkBooze(_items, _player, _drink) ISTimedActionQueue.add(TADrinkBooze:new(_player, _drink, 50));end-- -------------------------------------------------- Game Hooks-- ------------------------------------------------Events.OnPreFillInventoryObjectContextMenu.Add(UIDrinkBooze.createMenu);IIRC it worked 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