Page 1 of 1
describing a talent that needs both a stat and a function
Posted: Tue Dec 12, 2017 9:07 pm
by Jurriaan
Simple talents have
Code: Select all
racial_req2 = {
stat = { str=function(level) return 20 + (level-1) * 2 end },
level = function(level) return 6 + (level-1) end,
}
...
newTalent{
shortname = x
name = y
type = z
require = racial_req2,
i want to have a talent that doesn't depend on a stat (nor on a talent, which is described in the guide in the post above).
I've tested that this works
Code: Select all
require = { special={desc="After level 4, you can only study further when not wearing armour on your body and your feet", fct=function(self) return ((self.getTalentLevel(t) <= 4) or (self.GetTalentLevel(t) > 4 and not self:getInven("BODY") and not self:getInven("FEET"))) end} },
but, how can I combine this with a stat requirement? I can't find any example in the source.
Re: describing a talent that needs both a stat and a functio
Posted: Tue Dec 12, 2017 10:57 pm
by HousePet
Put a comma after your special={...} bit and add your stat={...} there.
Re: describing a talent that needs both a stat and a functio
Posted: Wed Dec 13, 2017 5:27 pm
by Jurriaan
unfortunately,
Code: Select all
racial_req1 = {
stat = { str=function(level) return 12 + (level-1) * 5 end },
level = function(level) return 0 + (level-1) end,
}
...
require = { special={desc="After level 4, you can only study further when not wearing armour on your body and your feet", fct=function(self) return ((self.getTalentLevel(t) <= 4) or (self.GetTalentLevel(t) > 4 and not self:getInven("BODY") and not self:getInven("FEET"))) end}, racial_req1 },
does not show any strength needs on the screen. Did I understand you incorrectly?
On looking at ActorTalents.lua, I see
Code: Select all
function _M:canLearnTalent(t, offset, ignore_special)
-- Check prerequisites
if rawget(t, "require") then
local req = t.require
if type(req) == "function" then req = req(self, t) end
local tlev = self:getTalentLevelRaw(t) + (offset or 1)
-- Obviously this requires the ActorStats interface
if req.stat then
for s, v in pairs(req.stat) do
v = util.getval(v, tlev)
if self:getStat(s) < v then return nil, "not enough stat: "..s:upper() end
end
end
if req.level then
if self.level < util.getval(req.level, tlev) then
return nil, "not enough levels"
end
end
if req.special and not ignore_special then
if not req.special.fct(self, t, offset) then
return nil, req.special.desc
end
end
if req.talent then
for _, tid in ipairs(req.talent) do
if type(tid) == "table" then
if type(tid[2]) == "boolean" and tid[2] == false then
if self:knowTalent(tid[1]) then return nil, "missing dependency" end
else
if self:getTalentLevelRaw(tid[1]) < tid[2] then return nil, "missing dependency" end
end
else
if not self:knowTalent(tid) then return nil, "missing dependency" end
end
end
end
end
really nothing that iterates over multiple entries after require. Should I conclude this just can't be done?
Re: describing a talent that needs both a stat and a functio
Posted: Wed Dec 13, 2017 11:28 pm
by HousePet
Since most talents already have both a stat and level requirement, I'd say there really is something that the iterates over multiple requirements.
I suspect your code isn't working because you have require = { special = {...}, { stat = ... , level = ... } }.
The code isn't expecting a table inside the requirements table.
Re: describing a talent that needs both a stat and a functio
Posted: Thu Dec 14, 2017 2:55 pm
by Jurriaan
Right!
Code: Select all
require = { special={desc="After level 4, you can only study further when not wearing armour on your body and your feet", fct=function(self) return ((self.getTalentLevel(t) <= 4) or (self.GetTalentLevel(t) > 4 and not self:getInven("BODY") and not self:getInven("FEET"))) end}, stat = { str = function(level) return 12 + (level-1) * 5 end }, level = function(level) return 0 + (level-1) end },
works!
Thanks!