From 490b3ef02d6420c78f19f5525443bce393252b3e Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Fri, 19 Jul 2019 18:59:20 -0300 Subject: Reintroduce mlearn(), and optimize the code. --- npc/functions/util.txt | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'npc/functions/util.txt') diff --git a/npc/functions/util.txt b/npc/functions/util.txt index 426219bb5..51f366b4b 100644 --- a/npc/functions/util.txt +++ b/npc/functions/util.txt @@ -599,11 +599,9 @@ function script sk_points { } // Returns true if a skill can be leveled up. -// sk_canlvup( item{, cost=1} ) +// sk_canlvup( {cost=1} ) function script sk_canlvup { - return ( - countitem(getarg(0)) && - (MAGIC_PTS+getarg(1,1)) <= sk_maxpoints()); + return ((MAGIC_PTS+getarg(0,1)) <= sk_maxpoints()); } // Level up a skill in 1 level @@ -619,6 +617,34 @@ function script sk_lvup { return; } +// NEW Magic School Learning Interface +// mlearn( skill, MAX_LV, AP cost, item, amount ) +// returns false if cheater +function script mlearn { + .@sk=getarg(0); + .@ff=getarg(1); + .@ap=getarg(2); + .@it=getarg(3); + .@am=getarg(4); + if (getskilllv(.@sk) >= .@ff) { + mesc l("You've reached the maximum level for this skill."), 1; + return true; + } + mesc l("To learn @@ you'll need @@/@@ point(s).", .@sk, .@ap, sk_points()); + mesc l("You'll also need to pay a fee of @@x @@", .@am, getitemlink(.@it)); + next; + if (askyesno() == ASK_NO) + return true; + if (countitem(.@it) < .@am) + return false; + if (!sk_canlvup(.@ap)) + return false; + + delitem .@it, .@am; + sk_lvup(.@sk, .@ap); + return true; +} + /* // Magic School Learning Interface // mlearn( skill, {item 1, amount 1}, {item 2, amount 2}... ) -- cgit v1.2.3-60-g2f50