Skill Listeners - LaughingLeader-DOS2-Mods/LeaderLib GitHub Wiki

Skill Listeners

LeaderLib provides an easy way to listen for skills being used.

---@alias LeaderLibSkillListenerDataType string|'"boolean"'|'"StatEntrySkillData"'|'"HitData"'|'"ProjectileHitData"'|'"SkillEventData"'

---@alias LeaderLibSkillListenerCallback fun(skill:string, char:string, state:SKILL_STATE, data:SkillEventData|HitData|ProjectileHitData|StatEntrySkillData|boolean, dataType:LeaderLibSkillListenerDataType)

---Registers a function to call when skill events fire for a skill or table of skills.
---@param skill string|string[]
---@param callback LeaderLibSkillListenerCallback
---@see SkillEventData#ForEach
---@see HitData#Success
---@see ProjectileHitData#Projectile

Skill State

Each time a skill enters a "state", it will call the function registered to the skill. The various skill states are:

State Description SkillData Type
SKILL_STATE.PREPARE When the skill is preparing. StatEntrySkillData
SKILL_STATE.CANCEL When preparing is stopped without casting. StatEntrySkillData
SKILL_STATE.USED After CharacterUsedSkill, but before SkillCast. Has all the targeted objects, if any. SkillEventData
SKILL_STATE.CAST When the skill has been cast, after SkillCast. Has all the targeted objects, if any. SkillEventData
SKILL_STATE.HIT When the skill hit an object during NRD_OnHit. HitData
SKILL_STATE.PROJECTILEHIT When a projectile skill has hit something, such as the ground or a target. This fires during the extender's 'ProjectileHit' event. ProjectileHitData
SKILL_STATE.LEARNED When the skill is learned (added, but not necessarily memorized). learned:boolean
SKILL_STATE.MEMORIZED When the skill is memorized. boolean
SKILL_STATE.UNMEMORIZED When the skill is unmemorized. boolean

Thanks to states, one function can be used for every step of a skill.

Example Usage

SkillConfiguration.AimedShot = {
	BonusStatuses = {"LLWEAPONEX_FIREARM_AIMEDSHOT_CRITICAL", "LLWEAPONEX_FIREARM_AIMEDSHOT_ACCURACY"},
	CriticalRequrementStatuses = {"MARKED"},
}

RegisterSkillListener("Projectile_LLWEAPONEX_Rifle_AimedShot", function(skill, char, state, data)
	if state == SKILL_STATE.USED then
		GameHelpers.Status.Apply(char, "LLWEAPONEX_FIREARM_AIMEDSHOT_ACCURACY", 6.0, false, char)
		local shouldCriticalHit = false
		data:ForEach(function(target)
			if GameHelpers.Status.IsActive(target, SkillConfiguration.AimedShot.CriticalRequrementStatuses) then
				shouldCriticalHit = true
			end
		end, data.TargetMode.Objects)
		if shouldCriticalHit then
			GameHelpers.Status.Apply(char, "LLWEAPONEX_FIREARM_AIMEDSHOT_CRITICAL", 6.0, true, char)
		end
	elseif state == SKILL_STATE.CAST then
		Timer.StartObjectTimer("LLWEAPONEX_Rifle_AimedShot_ClearBonuses", char, 1500)
	elseif state == SKILL_STATE.HIT then
		Timer.Cancel("LLWEAPONEX_Rifle_AimedShot_ClearBonuses", char)
		GameHelpers.Status.Remove(char, SkillConfiguration.AimedShot.BonusStatuses)
	end
end)

Timer.RegisterListener("LLWEAPONEX_Rifle_AimedShot_ClearBonuses", function(timerName, uuid)
	GameHelpers.Status.Remove(uuid, SkillConfiguration.AimedShot.BonusStatuses)
end)
⚠️ **GitHub.com Fallback** ⚠️