[UMod] Extended Hooks (0.3.12)

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
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

[UMod] Extended Hooks (0.3.12)

Post by 7Soul »

This is a mod for modders. It adds many new hooks in order to allow for more customization of skills, traits and items

Reference: https://github.com/7Soul/log2_extended_hooks/wiki

How to use:

1 - First you have to be on the new beta branch. On steam, right click the game > Properties > Betas. Add the code "ggllooeegggg" to unlock the secret "nutcracker" beta

2 - Go to "\Documents\Almost Human\legend of grimrock 2". Once the beta is downloaded, you'll see a file named "mods.cfg" and a "Mods" folder

3 - Download mod folder: https://drive.google.com/file/d/1y54ryc ... sp=sharing

4 - Extract the hooks folder into the Mods folder, so it looks like /Mods/hooks

5 - Add the mod to mods.cfg so it looks like this:

Code: Select all

mods = {
	"hooks/hooks_def.lua",
	"hooks/hooks_gui.lua",
	"hooks/hooks_redefines.lua",
	"hooks/hooks_1.lua",
	"hooks/hooks_components.lua",
	"hooks/BombItem.lua",
	"hooks/CastSpell.lua",
	"hooks/ContainerItem.lua",
	"hooks/CraftPotion.lua",
	"hooks/Map.lua",
	"hooks/SurfaceSocket.lua",
}
When using this mod by itself, the default traits, spells and skills won't work. You need to replace the existing definitions with the ones from the mod. For instance, the light weapons skill won't do anything. You need the definition included in the mod that uses the "onComputeDamageMultiplier" function. Similarly, spells now include their power in their definition

Examples:

Enables dual wielding with your free hands:

Code: Select all

onCheckDualWielding = function(champion, weapon1, weapon2, level)
	if level > 0 and not weapon1 and not weapon2 then
		return true
	end
end
Adds pierce to crits

Code: Select all

onComputePierce = function(monster, champion, weapon, attack, projectile, dmg, dmgType, attackType, crit, backstab, level)
	if level > 0 and crit then
		return 20
	end
end,
Makes concentration spells cheaper

Code: Select all

onComputeSpellCost = function(champion, name, cost, skill, level)
	if level > 0 then
		if skill == "concentration" then
			return 0.85
		end
	end
end
Reduces equipped armor's weight by 10%

Code: Select all

onComputeItemWeight = function(champion, equipped, level)
	if level > 0 and equipped then
		return 0.9
	end
end,
Last edited by 7Soul on Sat Nov 26, 2022 3:55 pm, edited 23 times in total.
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: [UMod] Extended Hooks

Post by 7Soul »

Update 0.2:

- fixed bugs
- critMultiplier was missing from weapons other than melee ones
- all shield spells and conditions are no longer hard coded

Fixed Grimrock 2 bugs:
- Potions can now have a custom gfxAtlas
- Reduced Meteor Storm spread, fixing a rare collision issue
- onComputeCooldown now affects spell charges. Parameter "weapon" contains item, parameter "attack" is nil, and parameter "attackType" is "spell"

New champion functions:

Code: Select all

setData(name, value)
addData(name, value)
getData(name)
    Stores values in a table
setCooldown(index, value)
getCooldown(index)
    Directly change a champion's current cooldown
getConditionStacks(name)
    Returns the stack count of a condition
New monster functions:

Code: Select all

setData(name, value)
addData(name, value)
getData(name)
    Stores values in a table
getAIState
    Existed for MonsterGroupComponent but not for MonsterComponen
New trait/skill/equipment hooks:

Code: Select all

onHitTrigger = function(champion, weapon, attack, attackType, dmg, crit, backstab, monster, level)
    Called just before a monster takes damage
    Doesn't return any values
onComputeBuildupTime = function(champion, weapon, buildup, attackType, level)
    Multiplies power attack buildup
    Return number
onComputePowerAttackCost = function(champion, weapon, cost, attackType, level)
    Multiplies power attack energy cost
    Return number
onCheckWound = function(champion, wound, action, actionName, actionType, level)
    Overrides a wound that would prevent an action (eg a hand wound preventing an attack or head wound preventing casting)
    action - attack component. In the case of a spell, it's "spell"
    actionName - name of attack or name of spell
    actionType - type of attack or skill of spell
    Return true to ignore wound
onComputeCooldown 
    (added to equipmentItem)
   
New misc functions:

Code: Select all

SurfaceComponent:removeItem(item)
SocketComponent:removeItem(item)
    Removes item from surface/socket component and triggers "onRemoveItem"
New potion crafting update:

- The game will check for items with the "herb" trait and define those as the crafting herbs
- Herbs are ordered by icon index. So the herb with the lowers icon number is "1" for the recipe, etc
- The crafting UI shows the icons for your custom herbs
- Potions can now have custom icons

Image
Last edited by 7Soul on Wed Apr 14, 2021 9:48 pm, edited 1 time in total.
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: [UMod] Extended Hooks

Post by 7Soul »

Quick update 0.3.1:

- Added onComputeSpellCritChance
- The last thrown weapon now properly triggers any EquipmentItem functions attached to it

Quickfix 0.3.2:

- Fixed a crash when a spell isn't used by a champion
- Removed a debug message
- Fixed a serialization error message

Update 0.3.4:

- Fixed a save game crash
- Fixed a crash when throwing bombs

Update 0.3.5:

- Fixed some issues with projectiles keeping track of the weapon that created them

Update 0.3.7:

- Fixed a crash involving crits with ranged attacks

Update 0.3.8:

- Fixed a crash with taking drowning damage

Update 0.3.8b:

- Fixed a crash where the onComputeAccuracy hook on equipmentItem had the wrong order of parameters
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: [UMod] Extended Hooks (0.3.9)

Post by 7Soul »

0.3.9 Changelog

Bugfixes
- Fixed crash related to monsters hitting other monsters with projectiles
- Fixed crash related to firing a projectile then removing the weapon
- Fixed Condition onStart hook having no reference to the condition power or stack count

New trait/skill/equipment hook
- onLevelUp(): triggers after a level up, and is used by the Mutation trait
- onUseItem(): triggers when an item is used, the Farmer's exp gain is now triggered this way

New character class definition parameters
- skillsAvailable: a list of skill names, used if you want certain classes to only learn certain skills (like in LoG1)
- skillPointsPerLevel: number of points gained per level (default: 1)

New UsableItemComponent parameter
- racialFood: for preferred foods bonus

New skill definition parameters
- requirements: a table with levels as keys and text as values. Used to display text between traits in the skill tooltips
- maxLevel: max skill level for the skill, must be greater or equal to 5. For anything over 5, the skill level will be displayed as a number instead of the little squares with pegs in them
- pointsCost: a number which dictate how many skill points are needed to level this skill up. A table can be used to get different values at different levels
- new hook: onCheckRestrictions = function(champion, skill, level)
- - use 'return false' to add a requirement to the skill. The requirement text will appear red if this requirement isn't met by the character
Example:Show

Code: Select all

defineSkill{
    name = "alchemy",
    uiName = "Alchemy",
    priority = 10,
    icon = 20,
    description = "A higher skill level in Alchemy allows you to brew a wider range of potions. To craft potions you also need herbs and a Mortar and Pestle.",
    skillTraits = { 
        [2] = "You brew stronger healing and energy potions.",
        [10] = "When you craft bombs you get three bombs instead of one."
    },
    requirements = {
        [10] = "Requires Earth Magic level 1.", -- doesn't need to match trait level, this '10' could be any number
    },
    traits = { [2] = "improved_alchemy", [10] = "bomb_expert" },
    maxLevel = 10,
    pointsCost = {1,1,1,1,2,1,1,1,1,1}, -- skill level 5 will require 2 points
    onCheckRestrictions = function(champion, skill, level)
        if level == 10 and champion:getSkillLevel("earth_magic") <= 0 then 
            return false
        end
    end
}

Added support for custom components from other UMods
Use

Code: Select all

local oldDungeonLoadInitFile = Dungeon.loadInitFile
function Dungeon:loadInitFile()
	oldDungeonLoadInitFile(self)
	dungeon = self
	self:addCustomComponents(YourComponent)
end
And your component will be updated along with this mod's custom components

Added new components

SlideComponent
- Moves object left and right when clicked
ExampleShow

Code: Select all

defineObject{
	name = "pushable_ladder",
	baseObject = "ladder",
	components = {
		{
			class = "Slide",
		},
		{
			class = "Controller",
			onIncrement = function(self)
				self.go.slide:pushRight()
			end,
			onDecrement = function(self)
				self.go.slide:pushLeft()
			end,
		},
		{
			class = "WallObstacle",
			name = "obstacle",
		},
		{
			class = "Clickable",
			name = "clickRight",
			offset = vec(0.6, 1.4, -1.2),
			size = vec(0.7, 1.2, 0.1),
			maxDistance = 0,
			onClick = function(self)
				if party.facing == self.go.facing then
					self.go.slide:push((party.facing+1)%4)
				end
			end,
		},
		{
			class = "Clickable",
			name = "clickLeft",
			offset = vec(-0.6, 1.4, -1.2),
			size = vec(0.7, 1.2, 0.1),
			maxDistance = 0,
			onClick = function(self)
				if party.facing == self.go.facing then
					self.go.slide:push((party.facing-1)%4)
				end
			end,
		},
	},
	editorIcon = 248,
	automapIcon = 140,
	tags = { "level_design" },
}
WallObstacleComponent
- Acts like an invisible wall, blocking movement, projectiles and attacks between two tiles
ExampleShow

Code: Select all

defineObject{
	name = "wall_blocker",
	components = {
		{
			class = "WallObstacle",
		},
		{
			class = "Controller",
			onActivate = function(self)
				self.go.obstacle:enable()
			end,
			onDeactivate = function(self)
				self.go.obstacle:disable()
			end,
			onToggle = function(self)
				if self.go.obstacle:isEnabled() then
					self.go.obstacle:disable()
				else
					self.go.obstacle:enable()
				end
			end,
		},
	},
	tags = { "scripting" },
	placement = "wall",
	editorIcon = 96,
}
New component functions

SurfaceComponent and SocketComponent
- getItemByIndex(index): Returns an item component from this surface/socket
- dropItem(item, bool): Causes the surface/socket to drop an item on the floor. Triggers onRemoveItem hook if 'bool' is true
ExampleShow

Code: Select all

function drop()
	-- Drops all surface items on the floor
	local surface = pedestal_1.surface
	while surface:getItemByIndex() do
		local item = surface:getItemByIndex()
		if item then
			surface:dropItem(item, surface:count() == 1) -- triggers onRemoveItem when the last item is dropped
		end
	end
end
ContainerComponent

New properties:
- slots: number of slots that fit in the window (16, 9, 4 or 1)
- gfx: custom texture to be used as a background
- closeButton: where to put the close button {x,y,width,height}. Defaul: {x = 207, y = 15, width = 40, height = 40}
- customSlots: used to place slots in custom positions (slots number is still used to determine where they can go). Uses a table of x and y indexes. Ex: When "slots=9", {0,0} places a slot in the first position. {2,2} places a slot in the last position
- customSlotGfx: causes the Gui to draw slot squares graphics. If "true" it'll use a default slot texture, or you can set to your own texture

New hooks:
onCalculateWeight = function(self, weight, item, champion)
-- Returns the new weight of the item

onAcceptItem = function(self, item, champion)
-- If it returns false, the item can't be placed in the container

onOpen = function(self, champion)
-- If it returns false, the container cannot be opened
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: [UMod] Extended Hooks (0.3.9)

Post by 7Soul »

0.3.9b Changelog Download link
- Accidentally broke "getItem" method for socket component
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: [UMod] Extended Hooks (0.3.9)

Post by Isaac »

When (if ever) will it be possible to use these for the various non-Steam editions? :(
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: [UMod] Extended Hooks (0.3.10)

Post by 7Soul »

Update 0.3.10 https://drive.google.com/file/d/12vWQL5 ... sp=sharing

============== 0.3.10 Changelog ==============

- Added trait hooks:
onComputeConditionDuration = function(condition, champion, name, beneficial, harmful, transformation)
onComputeConditionPower = function(condition, champion, name, beneficial, harmful, transformation)
onPerformAddedDamage = function(champion, weapon, attack, attackType, damageType, level)

- Added equipment hooks:
onComputeConditionDuration = function(self, condition, champion, name, beneficial, harmful, transformation)
onComputeConditionPower = function(self, condition, champion, name, beneficial, harmful, transformation)
onPerformAddedDamage = function(self, champion, weapon, attack, attackType, damageType)

- Hooks change:
onComputeItemStats(equipmentItem, champion, slot, level)
Changed to:
onComputeItemStats(equipmentItem, champion, slot, statName, statValue, level)
Can now be used to return a new value for the stat being checked

onComputeChampionAttackDamage
First return value = false now causes damage number to not be displayed (previously it did nothing)

- Added equipment hooks that already existed as trait hooks:
onComputeToHit = function(self, monster, champion, weapon, attack, attackType, damageType, toHit)
onLevelUp = function(self, champion)
onUseItem = function(self, champion, item)
onComputeItemStats = function(self, champion, slot, statName, statValue)

- Item change:
The effect on the Fire Gauntlets is no longer hardcoded. It uses the onPerformAddedDamage and onComputeChampionAttackDamage hooks

Bugfixes:
- Fixed an issue with the Mutation trait
- Fixed a display error with exp boost items

Edit:
The mod now has a reference wiki: https://github.com/7Soul/log2_extended_hooks/wiki
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: [UMod] Extended Hooks (0.3.11)

Post by 7Soul »

0.3.11 update: https://drive.google.com/file/d/1Fws6UD ... sp=sharing

============== 0.3.11 Changelog ==============

- Added equipment hooks that already existed as trait hooks:
onComputeDamageMultiplier(self, champion, weapon, attack, attackType)
onComputeDualWieldingModifier(self, champion, weapon, attack, attackType)
onCastSpell(self, champion, name, cost, skill)
onDataDurationEnds(self, champion, name, value)

- New trait/skill/equipment hooks:
onCastSpell(champion, name, cost, skill, level)
onDataDurationEnds(champion, name, value, level)

- New champion functions:
setDataDuration(name, value, duration)
getDataDuration(name)
getDamageWithWeapon(itemComponent)

- Bugfixes:
- Fixed an issue with onComputeConditionDuration and onComputeConditionPower on equipmentItem
- Fixed an issue with onRecomputeStats
- Fixed an inconsistency with onComputeDamageModifier, minDamageMod and maxDamageMod on items
- Fixed instances of min damage being higher than max damage
- onComputeDamageTaken is now consistent across all instances, calculating the new damage only after all hooks are checked
- Fixed an issue with recalculating final Health and Energy
- Fixed a particle crash when starting custom dungeons

- Added new stat: Threat
- Champion stat = threat_rate, Equipment stat = threat
- Can be either -1, 0 or 1. Enemies will prioritize the highest threat target 25% of the time

- Misc changes:
- For resists and health/energy regen, when multiple stats are equal, the item description will summarize them. Eg: "Fire and Cold Resist +10"
- Food consumption text is now clearer, saying "higher" or "lower" consumption
- Same with EXP gain
- Armor proficiency text always appears at the end
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
Post Reply