Page 1 of 1

Level comparing script

Posted: Tue Dec 10, 2013 12:29 pm
by LocalFire
So I want to compare the levels of two characters and grant exp to the one with the lower level until they are the same.

I've tried to do it like this, with the character with ordinal 1 (the starting character) having the lvl of a second character checked when they join the party.

I want to get it so it loops granting exp until they are the same lvl

Code: Select all

if champion:getOrdinal(1):getLevel()==champion:getOrdinal(2):getLevel() then
hudPrint("same Level")

else

champion:getOrdinal(2)
:gainExp(1000)
return

end
end
Thanks for any help in advance

Re: Level comparing script

Posted: Tue Dec 10, 2013 12:50 pm
by Leki
It's easy script and the only way to learn how to do is just to try harder by yourself to find solution :twisted:
Hint: Don't use gainExp, but use Champion:levelUp() until they are the same level.
Champion Scripting reference: http://www.grimrock.net/modding/scripting-reference/

Re: Level comparing script

Posted: Tue Dec 10, 2013 1:08 pm
by LocalFire
Thanks for the hint heres an update on how this is going

so I have a SE called OrdinalScript with this function

Code: Select all

function getChampionWithOrdinal(ordinal)
  for i=1,4 do
    if ( party:getChampion(i):getOrdinal() == ordinal ) 
 then     return party:getChampion(i);
    end
  end

  return nil;
end
which is called by this function:

Code: Select all

function LvlComp()

if  OrdinalScript.getChampionWithOrdinal(1):getLevel()== OrdinalScript.getChampionWithOrdinal(2):getLevel() then
hudPrint("same Level")

else

OrdinalScript.getChampionWithOrdinal(2)
:levelUp()
return

end
end
so that works! but it only works in as much as one level up, if the first character is lvl 3 or higher it won't keep leveling them up, I thought the return bit would loop the script back until it got the same level or that something else?

Re: Level comparing script

Posted: Tue Dec 10, 2013 2:05 pm
by Leki
Hint No.2 (key word "until" as you wrote in first post): http://lua.gts-stolberg.de/en/schleifen.php :twisted:

Re: Level comparing script

Posted: Tue Dec 10, 2013 10:14 pm
by LocalFire
Awesome it now works perfectly

Code: Select all

function LvlComp()


repeat

OrdinalScript.getChampionWithOrdinal(2)
:levelUp()

until  OrdinalScript.getChampionWithOrdinal(1):getLevel()== OrdinalScript.getChampionWithOrdinal(2):getLevel() 


end 
thanks for the hints :)