Jump to content

Monthly Item Spawns


Sparrow

Recommended Posts

So I've got this idea that I'd like to have seasonal item spawns in the world. Using Nolan's awesome Items Spawn of the Ground mod, I want to make a few items that will only appear during certain seasons.

 

For example: In spring months, flowers spawn in meadows. Maybe insects are easier to find. In the deep woods, some seasonal herbs may be easier to find. Etc. In the fall you could have mushrooms to find in the woods, acorns, walnuts and other seasonal produce. And in winter you can't find anything. ;) I think aesthetically it would be cool to see these things, and give more incentive to explore the woods and rural map.

 

The issue is I think I know how to make seasonal item spawns using the code in the hunting mod, which does a season check. I'm trying to brainstorm some ideas, however, to make those items disappear once the season is over.

 

Modders, any ideas?

Link to comment
Share on other sites

Don't know if this would be feasible, but you could try with saving the tiles you spawned your seasonal items in a table (maybe one for each season?) and when the season changes you iterate over the table and remove the items on the ground?

 

This is just a rough idea and might be to cumbersome.

Link to comment
Share on other sites

 

This is entirely untested, not 100% sure if it would work since I've never tried, but...

local function isWrongSeason(itemType)
    --"itemType is a string name of the item to be checked
    -- this function should return true if the item is to be removed, or false.
    -- it should also return false if itemType == nil
    --"
end


local function onLoadSquare(square)
	if square == nil then return end
    local worldItems = square:getWorldObjects() -- "get the inventory"
    local toRemove = { } -- "a table of items in this square we want to remove"
    for index=0, worldItems:size()-1 do
        local item = worldItems:get(index)
        -- "check if the item has a getType function before we attempt to call it."
        -- "pass the type to the isWrongSeason() function above"
        if item.getType and isWrongSeason(item:getType()) then
            -- "insert the item into removal table so we dont modify the number
            -- of items while looping through it."
            table.insert(toRemove, item)
        end
    end
    for _, item in ipairs(toRemove) do
        square:removeWorldObject(item)
    end
end


Events.LoadGridsquare.Add(onLoadSquare)

(I put all the comments in there in " marks to make them easier to read)

 

This is only set to remove items when a square loads, so you may want other events hooked into OnDawn maybe, but then you'd have to figure out what squares to remove items from.

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...