Adding skill traits in correct game order

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
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Adding skill traits in correct game order

Post by akroma222 »

Hey All,

Q - is there a way to track / mimic / replicate the correct ordering grimrock uses to add skill traits to a champion that have been added simultaneously

I have a custom traits menu and my system can correctly track and display traits as they are displayed without the custom menu
- except - when skill traits from more than 1 skill are added simultaneously

What results is my custom menu displaying some traits out of order - noticeable when hovering over them and getting an incorrect vanilla tooltip (mouse hovering over Reach trait and getting the air mastery tooltip)
SpoilerShow
Image
If the player adds more than one skill trait while in the skills menu but one at a time (spend points, accept, get 1 trait, spend more points, accept, get another trait) - this works fine

In my testing, I actually added all skill traits simultaneously, but spent the points in skills in both forward and reverse priority ordering, then accepted them all together. Neither test provided any useful insight into ordering....
I suspect the game may use a pairs function not ipairs - so correct tracking abovementioned would not be possible??

If not possible my options I can see are creating custom tooltips for the traits menu (which I hadnt intended but can script) - OR - asking the players nicely to avoid adding multiple skill traits simultaneously

Any ideas or suggestions??
Akroma :)
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Adding skill traits in correct game order

Post by Isaac »

I've never delved into this aspect before, so forgive possibly the naive question, but is there some reason not to update the table used by your menu on every frame? (so that it's always accurate)
Last edited by Isaac on Sat Jul 18, 2020 6:03 am, edited 2 times in total.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Adding skill traits in correct game order

Post by minmay »

Unfortunately, the order in which skills are trained when you click "Apply" on the skill screen is undefined. It can be different every time. Your guess of pairs was correct.

However, you can work around this particular problem by removing the traits yourself, then immediately re-adding them in an order that you do know.
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
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Adding skill traits in correct game order

Post by Isaac »

This would be updating the table, yes? ;) (...though not every frame).
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Adding skill traits in correct game order

Post by akroma222 »

Thankyou both! :D
Impossible with pairs, thanks minmay for confirming that
So - ill add a simple function to remove and re-add the traits

Isaac, at the moment the functions for displaying the custom traits is called from the onDrawTraits hook
Is every frame called from this hook enough do you think?
I had considered running the updateChampionTraits func every frame from an independent timer, not sure if Id need to if the purpose of this is just to display traits correctly in traits menu

EDIT: actually Id need only call the add / re add func once when the skills menu Apply button is pressed :idea:
Last edited by akroma222 on Sat Jul 18, 2020 7:39 am, edited 1 time in total.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Adding skill traits in correct game order

Post by akroma222 »

SpoilerShow

Code: Select all

function updateTraitOrder(ord)
	local c = party.party:getChampion(ord)
	for k,v in pairs(displayedChampTraitsTab[ord]) do
		if k and v and c:hasTrait(v) then
			c:removeTrait(v)
		end
	end
	for k,v in ipairs(displayedChampTraitsTab[ord]) do
		if k and v and not c:hasTrait(v) then
			c:addTrait(v)
		end
	end
end
Thank you both again, this func works perfectly (called from onDrawTraits hook) and solves my issue 8-)
Post Reply