Hi! I've just noticed your mod and checked it for possible compatibility issues with my Maps mod. It doesn't seem to interfere with it, but while browsing your code I've noticed some things you could improve:
-
Prefixing your setting names with "this_mod_" doesn't seem to be safe. The prefix looks like a placeholder from a tutorial, so it's not unlikely that another mod may use the same prefix. In the worst case, your setting may overwrite (or be overwritten by) another mod using the same name. I'd suggest using the name of your mod instead: "Hidden_Loot_" or even "Hidden_Loot-".
-
You should localize your random messages, or everybody will get the hard-coded messages in English! Add this to local.cfg:
[Hidden_Loot-random_messages]
crate=You notice an old crate within the rubble.
chest=You find a chest underneath the broken entity.
and change your definition of random_message in control.lua to this:
local random_message = {
{'Hidden_Loot-random_messages.crate'},
{'Hidden_Loot-random_messages.chest'},
}
Then players will get the message in their own locale, if available. (You never know, somebody may provide a translation.) Of course, you may choose other names for the category (the part in square brackets in local.cfg) or the strings (that I've named "crate" and "chest"), I've just made those up for my example.
- Did you know that some events can be filtered?
on_player_mined_entity
is one of them. If you register the event withscript.on_event(defines.events.on_player_mined_entity, on_player_mined_entity, {
{filter = "type", type = "tree"},
{filter = "type", type = "simple-entity", mode = "or"}, -- "mode" is optional, filters are ORed per default
})
you can skip the check for valid_types[entity.type]
in the function on_player_mined_entity()
. Using event filters is more efficient than your check in Lua as you will only see this event if any of the filters matches the entity type.