Class Trait script. Easier solution?

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

Class Trait script. Easier solution?

Post by Dunkler »

Hello Everyone

I want to make a class script that gives attribute points at different level. In this example +1 Str every 3 levels and +1 vitality every 4 levels

Code: Select all

        onRecomputeStats = function(champion, level)
		if level > 0 then
			level = champion:getLevel()			
			champion:addStatModifier("max_health", 22 + (level-1) * 12)
			champion:addStatModifier("max_energy", 10 + (level-1) * 5)
                  if level > 2 then
                     level = champion:getLevel()
                     champion:addStatModifier("strength",1) 
                  if level > 3 then
                     level = champion:getLevel()
                     champion:addStatModifier("vitality",1) 
                  if level > 5 then
                     level = champion:getLevel()
                     champion:addStatModifier("strength",1)
                  if level > 7 then
                     level = champion:getLevel()
                     champion:addStatModifier("vitality",1)
                  if level > 8 then
                     level = champion:getLevel()
                     champion:addStatModifier("strength",1)
                  if level > 11 then
                     level = champion:getLevel()
                     champion:addStatModifier("strength",1)
                     champion:addStatModifier("vitality",1)
                  if level > 14 then
                     level = champion:getLevel()
                     champion:addStatModifier("strength",1)
                  if level > 15 then
                     level = champion:getLevel()
                     champion:addStatModifier("vitality",1)
                  if level > 17 then
                     level = champion:getLevel()
                     champion:addStatModifier("strength",1)
                          end
                        end
                      end
                    end
                  end
                end
              end
            end      
          end
	end,
It works with this script, but it makes it very long in my opinion. Is there an easier Solution?

I also did something like champion:addStatModifier("strength",(level/3)) Problem here is that the game will show something like Strenght 12,333333333 at level 1 which is very bad :)
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Class Trait script. Easier solution?

Post by Zo Kath Ra »

Dunkler wrote:Hello Everyone
I also did something like champion:addStatModifier("strength",(level/3)) Problem here is that the game will show something like Strenght 12,333333333 at level 1 which is very bad :)
The scripting reference says that you can use the "math" module:
http://www.grimrock.net/modding/scripting-reference/

So you can use "math.floor" to round down level/3:
http://lua-users.org/wiki/MathLibraryTutorial
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Re: Class Trait script. Easier solution?

Post by Dunkler »

Thank you!

How exactly would you use math.floor in my script?
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Class Trait script. Easier solution?

Post by Zo Kath Ra »

Dunkler wrote:Thank you!

How exactly would you use math.floor in my script?
champion:addStatModifier("strength", math.floor(level/3))
Post Reply