A Minetest mod Framework for defining and using skills.
UNLICENSE License
#About This is a modification(mod) for MineTest that creates a character skill framework. Being a framework, this mod's intended audience are modders and game makers. Its primary purpose is to provide an easy to use yet highly configurable skill system that tracks both experience and levels for registered skills. This mod does not define any skills and is useless on its own.
Usage: SkillsFramework.function_name(arguments)
Name | Arguments | Returns | Description |
---|---|---|---|
show_formspec | player | none | Shows a formspec for graphical skill interaction. |
register_skill | data_table | none | Adds a new skill definition to the skill system. |
attach_skillset | set_id | none | Creates and attaches a new skill set to the given identifier. |
remove_skillset | set_id | none | Deletes a skill set. |
append_skills | set_id, skill or list | bool | Adds a single skill or list of skills to the indicated skill set. returns false if skill is already added |
set_level | set_id, skill, level | none | Allows setting the level of a skill in a skill set. |
add_level | set_id, skill, level | none | Adds the given amount to the level. |
get_level | set_id, skill | int | Return the level of specified skill. |
get_next_level_cost | set_id, skill | int | Returns the cost of the next level be it in experience or progression points. |
set_experience | set_id, skill, experience | none | Sets the specified skill's experience. |
add_experience | set_id, skill, experience | none | Adds the given amount to the skill. |
get_experience | set_id, skill | int | Returns the specified skill's experience. |
Data for this mod is saved to the world folder in a file called by default "skill_sets" (no extention). However, the file it saves to can be changed see configuration options below.
Settings are Located in settings.lua. They have all capitalized names with underscore spacing and are prefixed with "SkillsFramework.". (I.e. SkillsFramework.HIDE_ZERO_SKILLS)
Skills must be registered during Minetest's registration period. This is done with the SkillsFramework.define_skill(data_table) function. A skill is then defined with some basic control values and information.
The data table can have the fields listed below. Required means there is no default and the registration fails without it. Table keys need to match the names below exactly.
Example use of define_skill.
SkillsFramework.define\_skill({"mod":"thediggingmod"
,"name":"Digging"
,"cost_func":function(level) return 400*level end
,"group":"Landscaping"
,"max": 20
,"min": 1
,"on_levelup":dig_levelup_func})
###Level Cost Function Examples Here are two cost_func examples. The first example makes every level cost 100. The second example increases the cost linearly (i.e. level 3 costs 300).
function(level) return 100 end
function(level) return 100*level end
Here is an example function that help explain the usefulness of the on_levelup function. Here I assume that the skills digging and mining are defined and that digging is given to the player from the start while mining must be learned. We could give the player the mining skill once he has reached a certain digging level by defining the digging skill with the following on_levelup function :
digging_definition["on_levelup"] = function(set_id, level)
if level == 3 then
Skillsframework.append_skills(set_id, "thediggingmod:Mining"
end
end
Skillsets are collections of skills that are attached to unique identifiers (the player's name for example).
This makes skillsets flexible enough to describe the skills of either an individual or a group. For example a skill set can be created and preinitialized for "level one skeletons" allowing any of level one skeleton to use those skills. Of course when using it for a group the modder should not add experience to skills on each use otherwise the entire group will gain levels from actions each individual does.
Use the SkillsFramework.attach_skillset(set_id, skills) to create a skillset connected to an entity.
Actions use skills. The definition of an action is upto the modder and needs to be implemented in code. The common places for this code would be in the callbacks for the following 3 types of functions:
Of course, an action could be implemented just about anywhere. Even during global tick.
For implementing actions, SkillFramework provides various getter and setter functions. The getters are useful in testing against skills. The setters are useful for preinitializing skill sets or rewarding player's actions.
SkillsFramework.get_next_level_cost(set_id, skill)
SkillsFramework.get_level(set_id, skill)
SkillsFramework.set_level(set_id, skill, level)
SkillsFramework.add_level(set_id, skill, level)
SkillsFramework.get_experience(set_id, skill)
SkillsFramework.set_experience(set_id, skill, experience)
SkillsFramework.add_experience(set_id, skill, experience)
Examples
--Threshold test
if SF.get_level("singleplayer", "Combat Knowledge") >= level then
--allow player into arena
end
--Randomized success test
success = SF.get_level("singleplayer", "Smithing") >= rand_num
--Margin of success
margin = (rand_num - SF.get_level) / 10
--Increment experience
SF.add_experience(singleplayer, "Woodcutting", 60)
--Increment level setting exp to 0
SF.add_level(singleplayer, "Digging", 1)
SF.set_experience(singleplayer, "Digging", 0)
However, some skills should not be available to all entities. You may want certain skills to be associated with a class and/or have to be learned. In this case skills can be added using the append_skill function. If a skill is already in the skillset the function will do nothing.
All feedback and bug reports are welcome. Open a new GitHub issue for bugs or post them and your feedback on the mod's forum topic. Most pull requests will be accepted once they have been reviewed.
In order of importance.
Ongoing: Add user error prevention code (sanity checks).
Improve skill formspec.
Optional "show last used skills on HUD".
Better handling of old skill sets when:
Way to see another player's skills for admins and maybe other players.
Think about implementing multiple skill systems (like originally intended) in a clean way or decide to just make each skill system a separate mod. Alternate: have different skillsystems as seprate mods that depend on skillsframwork