Sweet! Thanks for the replies. I used minetest.register_globalstep( function(dtime) ) and so far have got it working for meat in the player's inventory.
I'm not sure how items that are laying around the environment are handled. I'm thinking I can get them in a list as an InvRef with minetest.get_inventory(location) but I'm not sure what to pass as the location. I see an example of {type="detached", name="creative"}which looks promising, but I'm not sure what options I have for passing as the parameters. I'm going to experiment with it tomorrow if I can't find any more documentation.
Also, for locating all the containers (chests and such) is there a function or constant that will give me the size of the map that I can use for figuring out the minp and maxp parameters for find_nodes_in_area(minp, maxp, nodenames)?
Thanks again!
Here's what I've got so far:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local rotting_timer = 0
minetest.register_globalstep( function(dtime)
rotting_timer = rotting_timer + dtime
if rotting_timer >= 720 then
--Rot Droped Meat
--If it's in the watter (due to drowned cattle) then raise the chance of it rotting
-- local litter = minetest.get_inventory({type="detached", name="creative"})
-- if not litter:is_empty("main") then
--
-- end
--Rot Harvested Meat
for _,player in ipairs(minetest.get_connected_players()) do
local who = player:get_player_name()
local stuff = player:get_inventory()
for i=1,32 do -- TODO: MAKE GENERIC
local item = stuff:get_stack("main", i)
if item:get_name() == "mobs:meat_raw" then
-- for j=1,item:get_count() do --TODO: Rot partial stacks
if math.random(1,100) > 66 then -- about 1/3 chance
item:replace({name = "my_mobs:meat_rotten", count = item:get_count(), wear=0, metadata=""})
stuff:set_stack("main", i, item)
minetest.chat_send_player(who, "Something in your inventory is starting to smell bad!") -- TODO: Change or have multiple strings to choose from randomly
end -- if by random chance
-- end -- for each item in stack [j]
end -- if is meat
end -- for each (32) inventory slot [i]
end -- for each player
--Rot Stored Meat [Except in refridgerator with addon]
--WORKING:
-- find_nodes_in_area(minp, maxp, nodenames) -> list of positions
-- ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
-- minetest.env:get_nodemeta(pos):get_inventory() -> InvRef
rotting_timer = 0 --reset the timer
end -- timer
end)