Hi akroma222. Here's one idea that solves a couple of your issues:
Code: Select all
function drakkanMaceEquip(champion, slot)
local skill = champion:getSkillLevel("maces")
local name1 = champion:getName()
if slot == 7 or slot == 8 then
if ( champion:getRace() == "Minotaur" and skill >= 5 ) then
champion:modifyStatCapacity("strength", 5)
champion:modifyStat("strength", 5)
champion:addTrait("tough")
hudPrint(""..name1..":Ahh now... THIS is what I have been looking for!")
else
champion:removeItem(slot)
spawn( "drakkan_minotaur_mace" , party.level , party.x , party.y , party.facing )
playSound("item_drop")
end
end
end
This way, if anyone who isn't a Minotaur with 5 or more skill in maces tries to equip it, they simply can't equip it. No bonuses for holding a mace that you can't actually wield. No penalty for unequipping a mace that never gave you a bonus in the first place. I tried to get a little more fancy and set the mace back as the mouse item, but encountered annoying timing issues. When I used setMouseItem() within the onEquip code, the item never appeared. When I tried setting a very short delay before I spawned a new mace as the mouse item, there was the lingering question of what to do with the old mouse item. The player might have had the mace as the mouse item and clicked on an equipment slot that already contained an item, thus switching those items. If I just spawn a new copy of the old mouse item, it will have a different id, so that might mess up other things in the mod. Note that the code above will also create a new mace with a different id. It would be nice if "return false" worked for onEqiup, but it seems that it does not. Has anyone successfully dealt with this problem before?
As for losing traits. I do think any good solution will involve one or more tables. Here's what I came up with first:
Code: Select all
traitsGained = {}
--Keys are item id's. Values are tables of traits gained.
function drakkanMaceEquip(champion, slot)
local skill = champion:getSkillLevel("maces")
local name1 = champion:getName()
if slot == 7 or slot == 8 then
if ( champion:getRace() == "Minotaur" and skill >= 5 ) then
champion:modifyStatCapacity("strength", 5)
champion:modifyStat("strength", 5)
if not champion:hasTrait("tough") then
champion:addTrait("tough")
local itemId = champion:getItem(slot).id
traitsGained[itemId] = { "tough", }
end
hudPrint(""..name1..":Ahh now... THIS is what I have been looking for!")
else
champion:removeItem(slot)
spawn( "drakkan_minotaur_mace" , party.level , party.x , party.y , party.facing )
playSound("item_drop")
end
end
end
function drakkanMaceUnequip(champion, slot)
local skill = champion:getSkillLevel("maces")
local name1 = champion:getName()
if ( slot == 7 or slot == 8 ) and
( champion:getRace() == "Minotaur" and skill >= 5 ) then
champion:modifyStatCapacity("strength", -5)
champion:modifyStat("strength", -5)
local itemId = champion:getItem(slot).id
local traitsToRemove = traitsGained[itemId]
traitsGained[itemId] = nil
if traitsToRemove then
for _ , trait in ipairs( traitsToRemove ) do
champion:removeTrait( trait )
end
end
hudPrint(""..name1..": Hey, what are you doing? That's my weapon!")
end
end
traitsGained is a table. The keys in this table are item id's. The value associated with each key is a table containing the traits that were gained the last time that item was equipped. By making the value a table instead of just a single string, we retain the option to create weapons that grant multiple traits. This scheme tracks which item gave which trait to which champion, but it still may not be ideal.
For example, if a champion equips two items that each should give "tough" then this scheme will track which item was equipped first and thus actually gave the bonus. If that champion then unequips that first item while keeping the second item equipped, they will lose "tough", which may not be the desired functionality. So now I like your first idea more, track which traits each champion had at the beginning:
Code: Select all
allTraits = { "aggressive" , "agile" , "athletic" , "aura" ,
"cold_resistant" , "evasive" , "fire_resistant" ,
"fist_fighter" , "head_hunter" , "healthy" ,
"lightning_speed" , "natural_armor" , "poison_resistant" ,
"skilled" , "strong_mind" , "tough" }
traitCounts = {}
--Keys are ordinals. Values are tables where:
--Keys are trait names. Values are the count of how many
--times that trait has been applied to that champion.
for i = 1,4 do
local champion = party:getChampion(i)
local currentTraits = {}
for _ , trait in ipairs( allTraits ) do
if champion:hasTrait( trait ) then
currentTraits[trait] = 1
end
end
traitCounts[champion:getOrdinal()] = currentTraits
end
function drakkanMaceEquip(champion, slot)
local ordinal = champion:getOrdinal()
local skill = champion:getSkillLevel("maces")
local name1 = champion:getName()
if slot == 7 or slot == 8 then
if ( champion:getRace() == "Minotaur" and skill >= 5 ) then
champion:modifyStatCapacity("strength", 5)
champion:modifyStat("strength", 5)
local oldCount = traitCounts[ordinal]["tough"] or 0
if oldCount == 0 then
champion:addTrait("tough")
end
traitCounts[ordinal]["tough"] = oldCount + 1
hudPrint(""..name1..":Ahh now... THIS is what I have been looking for!")
else
champion:removeItem(slot)
spawn( "drakkan_minotaur_mace" , party.level , party.x , party.y , party.facing )
playSound("item_drop")
end
end
end
function drakkanMaceUnequip(champion, slot)
local ordinal = champion:getOrdinal()
local skill = champion:getSkillLevel("maces")
local name1 = champion:getName()
if champion:getRace() == "Minotaur" then
if slot == 7 or slot == 8 then
if skill >= 5 then
champion:modifyStatCapacity("strength", -5)
champion:modifyStat("strength", -5)
traitCounts[ordinal]["tough"] = traitCounts[ordinal]["tough"] - 1
if traitCounts[ordinal]["tough"] == 0 then
champion:removeTrait("tough")
end
hudPrint(""..name1..": Hey, what are you doing? That's my weapon!")
end
end
end
end
Then every time an item is equipped that should add a trait, it actually just increments a field within a table within traitCounts . If that field was previously valued at 0 or nil, then we add the trait. When an item is unequipped that should remove a trait, it actually just decrements that same field within that table within traitCounts. If that reduces the new total to 0, then we actually remove the trait.