EquipmentItemComponent can set skills higher than 5

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

EquipmentItemComponent can set skills higher than 5

Post by minmay »

An especially unadventurous modder might think that skills can only be level 0, 1, 2, 3, 4, or 5.

Most modders have probably noticed that by using Champion:trainSkill(), you can set skill levels to any value between -inf and 5, but not above 5.

We can do slightly better. EquipmentItemComponent has a "skillModifiers" field that nobody else seems to have noticed, probably because it doesn't have a getter and setter in the scripting interface. It's pretty self-explanatory:

Code: Select all

{
	class = "EquipmentItem",
	protection = 5,
	skillModifiers={
		light_weapons=5,
		armors=3,
		critical=5000,
	},
},
While wearing this item, your Light Weapons skill is effectively increased by 5, your Armor skill by 3, and your Critical skill by 5000. These bonuses do not respect the 5 cap.

Do, however, be careful of the following:
- Champion:trainSkill() will fail to change the skill level altogether if the new skill level it would reach is over 5, so you can't train a skill down from 500 to 499 without going through the intermediate steps of removing the item(s) and re-equipping them etc.
- the skills tab only displays the integer part of skill level between 0 and 5, so skills under 0 display as 0 and skills over 5 display as 5 and a skill of 2.8 displays as 2.
- skill modifiers do not give the traits for the new skill level. Skill traits are only checked when trainSkill() is called. So you should call Champion:trainSkill(skill,0) after equipping the item. (If you want the skill modifier to not give traits at all, you're SOL because the traits will be given if the champion just puts a single point into that skill while the item is equipped. If you want the skill modifier to remove the traits when removed, you have to implement that manually).

The only reasons this could ever be useful are the builtin light_weapons, heavy_weapons, missile_weapons, throwing, firearms, and magic skills since you can't cleanly recreate their effects using the scripting interface. Other than that it would be better to use your own skill system.

P.S. Races and classes can also have a "skills" table in their definition that works similarly, like this:

Code: Select all

defineRace{
	name = "human",
	uiName = "Human",
	inventoryBackground = "assets/textures/gui/inventory_backgrounds/human_$sex.tga",
	skills = {alchemy=3,dodge=2}
}
but it's buggy and it does respect the 5 cap so it's not actually useful.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: EquipmentItemComponent can set skills higher than 5

Post by akroma222 »

That is pretty handy - ish :!:
Thankyou for sharing minmay!!
minmay wrote:An especially unadventurous modder might think that skills can only be level 0, 1, 2, 3, 4, or 5.
Most modders have probably noticed that by using Champion:trainSkill(), you can set skill levels to any value between -inf and 5, but not above 5.
Other than that it would be better to use your own skill system.
If folks are going about their own skill system - this can help keep track of skills levels 'theoretically' raised above the 5 cap
(eg- if your at Dodge lvl 4, equip item raising Dodge +2. Skill caps at 5, removing the item then robs you of 1 level in Dodge)
viewtopic.php?f=22&t=9024&p=88389&hilit ... ger#p88389
Post Reply