Ask a simple question, get a simple answer

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!
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Same deal. If you add the hook to an object definition, then all objects of that type have the hook.

Code: Select all

defineObject{
	name = "Yorick_skull",
	baseObject = "skull",
	components = {
		{
			class = "Item",
			uiName = "Skull of Yorick the jester",
			traits = { "skull" },
			gfxIndex = 31,
			weight = 1.0,
			onEquipItem = function(self, champion, slot)
					hudPrint(champion:getName()..": Alas, poor Yorick!")
				end
		}
	},
}
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

So I tested the item and I have the hook trigger everywhere but when I equip the item via portrait.

Since items in inventory count as equiped, any way to trigger the hook when we put it in the portrait?
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

There is a way to do it with one of the party onDraw hooks, but it's probably not worth it. Is this item a cursed object, or just something you need to know they have?

The item could employ an onUnequipItem hook that triggers when they try to pick it up or move it from within inventory. Alternatively, a party onPickUpItem hook could identify the item and run code when they lift it off of the map.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

If you want it to trigger only hen equipped in a specific slot, you could compare its current slot to the slot where you want it to be.

Code: Select all

ItemSlot.Weapon = 1 	
ItemSlot.OffHand = 2 	
ItemSlot.Head = 3 	
ItemSlot.Chest = 4 	
ItemSlot.Legs = 5 	
ItemSlot.Feet = 6 	
ItemSlot.Cloak = 7 	
ItemSlot.Necklace = 8 	
ItemSlot.Gloves = 9 	
ItemSlot.Bracers = 10 	
ItemSlot.Weapon2 = 11 	
ItemSlot.OffHand2 = 12 	
ItemSlot.BackpackFirst = 13 	
ItemSlot.BackpackLast = 32
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

zimberzimber wrote:If you want it to trigger only hen equipped in a specific slot, you could compare its current slot to the slot where you want it to be.
The main problem mentioned is the strange case that onEquipItem hooks only trigger when the item is dropped in the attack panel hands, or in an inventory slot. They don't trigger if the item is dropped on the portrait or the health & energy bars. I had to deal with this in one of my own projects several months back. An onDrawAttackPanel hook will theoretically give you the mouse location, and the numbers to catch the left click when the mouse is over the attack panel, but seems overkill, akin to using [expensive] dynamite to remove an ant hill. There must be a better way to do it; or not need to.

**The portrait locations are different for different screen resolutions.
CrEaToXx
Posts: 25
Joined: Thu Jan 19, 2017 9:58 pm

Re: Ask a simple question, get a simple answer

Post by CrEaToXx »

Hey guys,

so far I'm making good progress on my race pack mod. But there's another problem I'm encountering when trying to add 1 extra skill point as racial trait. Unfortunately I did not find any source code related to the "skilled" trait as well, neither in the .lua's nor here in the forums. When using code like this...

Code: Select all

onRecomputeStats = function(champion, level)
		if level > 0 then	
			champion:addStatModifier("strength", 3)
			champion:addStatModifier("dexterity", -1)
			champion:addStatModifier("willpower", -2)
                        if champion:getRace() == "customRace" and champion:getSkillPoints() < 3 then
                               champion:setSkillPoints(3)
                        else
                                champion:setSkillPoints(2)
                        end
		end
	end,
...there are the following problems:

1. skill points for custom race gets set to 3, but doesn't return to 2 when selecting another race
2. I need to add this code to all races in order to get them set back to 2 skill points
3. once in game, the skill points are still set to 3(respectively 2), and won't deduct when skill points are given to the champion

Is there even a way to allow for more skill points based on racial traits? I'm aware you can easily do this for character classes. Not allowing this for races confuses me?
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

Post by kelly1111 »

Quick Qestion: Has anyone ever converted the scripts for the "bouncing chakram" from grimrock 1, and if so, are they willing to share their code?
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

1. skill points for custom race gets set to 3, but doesn't return to 2 when selecting another race
This happens because of champion:getSkillPoints() < 3. Since 3 is not smaller than 3, the checker returns false and doesn't go on.
3. once in game, the skill points are still set to 3(respectively 2), and won't deduct when skill points are given to the champion
onRecomputeStats is called every frame, so the champion to whom this applies will have their skill points set to 2 or 3 every frame.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
THOM
Posts: 1267
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

kelly1111 wrote:Quick Qestion: Has anyone ever converted the scripts for the "bouncing chakram" from grimrock 1, and if so, are they willing to share their code?
I have never encountered a converted version. And AFAIK the code of it was never bug free.

But maybe someone did a new version secretly?
Last edited by THOM on Sat Jan 28, 2017 8:11 pm, edited 1 time in total.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
CrEaToXx
Posts: 25
Joined: Thu Jan 19, 2017 9:58 pm

Re: Ask a simple question, get a simple answer

Post by CrEaToXx »

onRecomputeStats is called every frame, so the champion to whom this applies will have their skill points set to 2 or 3 every frame.
Then why doesn't this happen for stats as well?
Post Reply