Error in define Trait (Solved)

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Error in define Trait (Solved)

Post by Dunkler »

Hello.

I want to change a Trait for a class so that he gains +1% critChance for every second Level he gains Starting at level 1.

onRecomputeStats = function(champion, level)
if level > 0 then
level = champion:getLevel()
champion:addStatModifier("critChance", 1+(level/2) )
end

This script works fine with other stats like healths or energy or strenght. But when i try it with critChance and run the Game i get an error that he doesnt know this Stat.

My Question is..

Did i simply write the script wrong? i tried it with critChance,CritChance but both didnt work.

Or is increasing Critchance not possible on level up?

Or if it is possible is there another way to do it?

Thanks for any help :)
Last edited by Dunkler on Mon Dec 22, 2014 11:14 am, edited 1 time in total.
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Error in define Trait

Post by Dr.Disaster »

Maybe just "critical" or "CriticalChance"?
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Re: Error in define Trait

Post by Dunkler »

same error InvalidStat
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Error in define Trait

Post by Grimfan »

This code is from another thread that gives you an example critical trait:

Code: Select all

defineTrait{
name = "master_daggerman",
uiName = "Dagger Master",
icon = 94,
description = "Dagger master !",

onComputeCritChance = function(self, champion, weapon, attack, attackType)
      if weapon:hasTrait("dagger") or weapon:hasTrait("dagger") then return 10 end
 end
end,
So there is basically no critical stat. It's a modification to your attack instead (based on your traits, etc.)
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Error in define Trait

Post by minmay »

Stats that I know of are cooldown_rate, dexterity, energy_regeneration_rate, exp_rate, food_rate, health, health_regeneration_rate, max_health, max_load, strength, vitality, willpower, energy, max_energy, evasion, protection, resist_poison, resist_shock, resist_cold, resist_fire.
If you want to change critical chance, accuracy, or apply a cooldown multiplier that stacks multiplicatively with others, you want to use onComputeAccuracy, onComputeCritChance and onComputeCooldown.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Re: Error in define Trait

Post by Dunkler »

Hm thank you. That is the answer i was scared about.

So basicly i can only modify the crit chance on an attack but i cant give it directly to the stats and it wont show in the attribute screen.
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Re: Error in define Trait

Post by Dunkler »

Hello again.

I tried this now

onComputeCritChance = function(champion, weapon, attack, attackType, level)
if level > 0 then return 1+(level/2) end
end,

And surprisingly! It does show in the charakter screen!

So everything is fine :D
Post Reply