Champion:trainSkill Component Bug on Party Creation

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
User avatar
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Champion:trainSkill Component Bug on Party Creation

Post by David Ward »

Hi guys. I'm trying to figure out how NOT to make the Champion:trainSkill(name, times) component fill up a skill with all 5 skill points, even if "times" is only set to 1, on the party creation screen.

This is the code I have right now for a class that should start with 1 on "armors" skill, and 1 on "shields" skill:

Code: Select all

defineTrait{
	name = "knight",
	uiName = "Knight",
	icon = 97,
	description = "As a knight you believe that good preparation is the key to triumph in combat. You are specialized in wielding armor and using the shield.",
	gameEffect = [[
	- Health 60 (+10 per level), Energy 30 (+3 per level)
	- Weight of equipped armor is reduced by 50%.
	- Add +1 to both your Armor and Shields skills at start.]],
	onRecomputeStats = function(champion, level)
		if level > 0 then
			level = champion:getLevel()
			champion:addStatModifier("max_health", 60 + (level-1) * 10)
			champion:addStatModifier("max_energy", 30 + (level-1) * 3)
			champion:trainSkill("armors",1)
			champion:trainSkill("shields",1)
		end
	end,
}
For some reason, as soon as I choose the "knight" class, it shoots those two skills up to 5 points. Not sure why, or how to fix it. Any help would be much appreciated, thank you.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Champion:trainSkill Component Bug on Party Creation

Post by minmay »

onRecomputeStats is called every frame (or something close to every frame). So your code is increasing those skills by 1 every frame. It is completely inappropriate to put that sort of thing in an onRecomputeStats hook.
Instead, when the game actually starts, you should check for that trait and train those skills if the champion has it.
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
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Re: Champion:trainSkill Component Bug on Party Creation

Post by David Ward »

I see. Still learning this! Thank you.
Instead, when the game actually starts, you should check for that trait and train those skills if the champion has it.
We're trying to make it so that a particular class gets its skills added automatically (like "armors" and "shields" for the knight), plus give the player the option to add 2 more skill points. Still working on that.

Is there also a way to set a skill level for a skill to 0? Or at least reduce a skill level?

For example:

Code: Select all

			champion:trainSkill("lgt_weapons", -1)
Would that work when called, reducing the lgt_weapons skill by 1?
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Champion:trainSkill Component Bug on Party Creation

Post by Azel »

This should cover your needs, I think:
viewtopic.php?f=22&t=9024
User avatar
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Re: Champion:trainSkill Component Bug on Party Creation

Post by David Ward »

Looks awesome, Azel. Checking into it now. Thanks for the reference.
Post Reply