describing a talent that needs both a stat and a function

If you have a module that you'd like comments on or would like to know how to create your very own module, post here

Moderator: Moderator

Post Reply
Message
Author
Jurriaan
Wyrmic
Posts: 227
Joined: Mon Mar 25, 2013 9:39 am

describing a talent that needs both a stat and a function

#1 Post 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.

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: describing a talent that needs both a stat and a functio

#2 Post by HousePet »

Put a comma after your special={...} bit and add your stat={...} there.
My feedback meter decays into coding. Give me feedback and I make mods.

Jurriaan
Wyrmic
Posts: 227
Joined: Mon Mar 25, 2013 9:39 am

Re: describing a talent that needs both a stat and a functio

#3 Post 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?

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: describing a talent that needs both a stat and a functio

#4 Post 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.
My feedback meter decays into coding. Give me feedback and I make mods.

Jurriaan
Wyrmic
Posts: 227
Joined: Mon Mar 25, 2013 9:39 am

Re: describing a talent that needs both a stat and a functio

#5 Post 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! :lol:

Thanks!

Post Reply