Page 183 of 395

Re: Ask a simple question, get a simple answer

Posted: Thu Jan 26, 2017 8:57 pm
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
		}
	},
}

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 27, 2017 2:53 pm
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?

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 27, 2017 6:16 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 27, 2017 7:19 pm
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

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 27, 2017 7:44 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 28, 2017 2:46 pm
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?

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 28, 2017 3:19 pm
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?

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 28, 2017 5:13 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 28, 2017 6:03 pm
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?

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 28, 2017 6:03 pm
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?