Page 1 of 1

learn trait if the champion is a ratling

Posted: Mon Mar 30, 2015 8:23 pm
by bongobeat
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.
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,
}
the tome:
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,
		},
	},
}

Re: learn trait if the champion is a ratling

Posted: Mon Mar 30, 2015 8:39 pm
by minmay
check champion:getRace() or champion:hasTrait("ratling") in the onUseItem hook

requiredRace is only for character creation screen, it won't do anything to prevent you from adding the trait to the champion manually through champion:addTrait()

Re: learn trait if the champion is a ratling

Posted: Tue Mar 31, 2015 11:11 pm
by bongobeat
thanks,

this one work:
SpoilerShow

Code: Select all

		{
			class = "UsableItem",
			sound = "level_up",
			onUseItem = function(self, champion)
				if  champion:hasTrait("ratling") then
					hudPrint(champion:getName().." learned the Drake Egg Hunter ability.")
					champion:addTrait("egg_hunter")
				else 				
					hudPrint(champion:getName().." is not a Ratling and can't learn this.")
				return false
				end
			end,
		},
pls can you check if this can't generate an error?

Re: learn trait if the champion is a ratling

Posted: Tue Mar 31, 2015 11:23 pm
by minmay
Yep, that's exactly what it should look like.

Re: learn trait if the champion is a ratling

Posted: Wed Apr 01, 2015 8:15 pm
by bongobeat
arigato!