Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main.lua #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ HISTORY:
2019-12-25 - v1.1.1 - No code changes, added spells/tr-v19.12.json

]]---------------------------------------------------------------------

local skillIdCACHE, skillNameCACHE, skillProgressCACHE, skillProgressDeltaCACHE = nil
-- Paths to config and data files
local dataPath = 'custom/__data_mbsp.json'
local configPath = 'custom/__config_mbsp.json'
Expand Down Expand Up @@ -232,7 +232,7 @@ local getSkillThatsChanged = function(pid)
local oldProgress = Players[pid].data.skills[skillName].progress
local newProgress = tes3mp.GetSkillProgress(pid, skillId)

if oldProgress < newProgress then
if oldProgress+0.1 < newProgress then
return skillId, skillName, oldProgress, (newProgress - oldProgress)
end

Expand Down Expand Up @@ -389,7 +389,7 @@ local runRefundMagicka = function(pid, skillId, baseSpellCost)
end

local runAwardProgress = function(pid, spellCost, skillId, skillName, skillProgress, skillProgressDelta)
local extraProgress = math.ceil(spellCost / config['spellCostDivisor'] * skillProgressDelta) - skillProgressDelta
local extraProgress = spellCost / config['spellCostDivisor'] * skillProgressDelta - skillProgressDelta

dbg('PID #' .. pid .. ' is owed ' .. extraProgress .. ' more progress for spell cost ' .. spellCost)

Expand All @@ -408,11 +408,19 @@ end

customEventHooks.registerValidator('OnPlayerSkill', function(eventStatus, pid)
local skillId, skillName, skillProgress, skillProgressDelta = getSkillThatsChanged(pid)
skillIdCACHE, skillNameCACHE, skillProgressCACHE, skillProgressDeltaCACHE = skillId, skillName, skillProgress, skillProgressDelta
if skillId == nil then return end
if skillName == nil then return end
if skillProgress == nil then return end
if skillProgressDelta == nil then return end
end)

customEventHooks.registerHandler('OnPlayerSkill', function(eventStatus, pid)
local skillId, skillName, skillProgress, skillProgressDelta = skillIdCACHE, skillNameCACHE, skillProgressCACHE, skillProgressDeltaCACHE
if skillId == nil then return end
if skillName == nil then return end
if skillProgress == nil then return end
if skillProgressDelta == nil then return end
local selectedSpellId = Players[pid].data.miscellaneous.selectedSpell
local selectedSpellCost = getSpellCost(selectedSpellId)

Expand Down