Page 1 of 1

Error in trait, please help

Posted: Mon May 18, 2015 10:15 pm
by Drakkan
can somebody please fix what is wrong with my script ? It crash game when I right-click on empty hand of any champion

mod_assets/scripts/drakkantraits.lua:189: attempt to index local 'weapon' (a nil value)
stack traceback:
mod_assets/scripts/drakkantraits.lua:189: in function 'onComputeCooldown'
[string "MeleeAttack.lua"]: in function 'start'
[string "Champion.lua"]: in function 'attack'
[string "AttackPanel.lua"]: in function 'select'
[string "AttackPanel.lua"]: in function 'drawItemSlot'
[string "AttackPanel.lua"]: in function 'updateAttackButtons'
[string "AttackPanel.lua"]: in function 'update'
[string "AttackPanel.lua"]: in function 'update'
[string "Gui.lua"]: in function 'draw'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk



defineTrait{
name = "grandmaster_sword",
uiName = "Sword slasher",
icon = 3,
description = "Any sword attack is 20% faster.",
onComputeCooldown = function(champion, weapon, attack, attackType, level)
if weapon:hasTrait("sword") or weapon:hasTrait("sword") then return 0.833 --row 189
end
end,
}

Re: Error in trait, please help

Posted: Mon May 18, 2015 10:25 pm
by alois
Try with "if weapon and weapon:hasTrait("sword")" etc...

Alois :)

Re: Error in trait, please help

Posted: Mon Jun 15, 2015 2:17 am
by akroma222
Pretty sure it should be...
SpoilerShow

Code: Select all

defineTrait{
name = "grandmaster_sword",
uiName = "Sword slasher",
icon = 3,
description = "Any sword attack is 20% faster.",
onComputeCooldown = function(champion, weapon, attack, attackType, level)
          if level > 0 then
                        if weapon and  weapon:hasTrait("sword") then 
                                       return 0.833 
                        end
           end
end,
}
(not tested) - remember to check level > 0 and then weapon ~= nil (or just 'if weapon then)
If you dont check these the game can crash at the party creation screen while picking traits

Re: Error in trait, please help

Posted: Mon Jun 15, 2015 12:51 pm
by Dunkler
Do cooldown buffs stack?

I mean if you have different traits that grant a bonus to cooldown..do they stack or do they multiply? How does it work?

Re: Error in trait, please help

Posted: Mon Jun 15, 2015 5:57 pm
by minmay
onComputeCooldown stacks multiplicatively and doesn't work on spell casts. cooldown_rate increases or decreases are added together before applying, instead of applying separately, and do work on spell casts.

Re: Error in trait, please help

Posted: Mon Jun 15, 2015 9:18 pm
by Dunkler
Thank you!