learn trait if the champion is a ratling
Posted: Mon Mar 30, 2015 8:23 pm
Ave master of the scripts:
how to apply a trait, learned by a tome, only for a ratling?
I've done a new trait, based on the head hunter trait: the champion had to learn it by using a tome, then it should increase the dexterity, but only if the champion is a ratling, while carrying special eggs:
the following trait works for any race, despit the requiredRace is ratling.
the tome:
how to apply a trait, learned by a tome, only for a ratling?
I've done a new trait, based on the head hunter trait: the champion had to learn it by using a tome, then it should increase the dexterity, but only if the champion is a ratling, while carrying special eggs:
the following trait works for any race, despit the requiredRace is ratling.
SpoilerShow
Code: Select all
defineTrait{
name = "egg_hunter",
uiName = "Drake Egg Hunter",
icon = 45,
charGen = true,
requiredRace = "ratling",
description = "Dexterity +1 for each Egg carried.",
onRecomputeStats = function(champion, level)
if level > 0 then
-- count skulls
local eggs = 0
for i=1,ItemSlot.MaxSlots do
local item = champion:getItem(i)
if item then
if item:hasTrait("drake_egg") then
eggs = eggs + 1
else
local container = item.go.containeritem
if container then
local capacity = container:getCapacity()
for j=1,capacity do
local item2 = container:getItem(j)
if item2 and item2:hasTrait("drake_egg") then
eggs = eggs + 1
end
end
end
end
end
end
champion:addStatModifier("dexterity", eggs)
end
end,
}
SpoilerShow
Code: Select all
defineObject{
name = "tome_drake_egg",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/tome.fbx",
},
{
class = "Item",
uiName = "Tome of the Egg Hunter",
description = "A thick tome that thoroughly describes the diet and excercises of the Ratlings of Nex. It teaches the reader, if it is a ratling, the Drake Egg Hunter ability.",
gfxIndex = 30,
weight = 1.0,
gameEffect = "gain dexterity +1 for each Drake Egg carryed.",
traits = { "tome" },
},
{
class = "UsableItem",
sound = "level_up",
onUseItem = function(self, champion)
hudPrint(champion:getName().." learned the Drake Egg Hunter ability.")
champion:addTrait("egg_hunter")
return true
end,
},
},
}