From e9c90337a6057b66faad6759ff418e8a5f162cfe Mon Sep 17 00:00:00 2001 From: gumi Date: Sun, 20 Aug 2017 11:34:59 -0400 Subject: reorganize the framework functions --- npc/functions/main.txt | 65 ++++++++++++++++-------------------------------- npc/functions/math.txt | 40 +++++++++++++++++++++++++++++ npc/functions/string.txt | 9 +++++++ 3 files changed, 70 insertions(+), 44 deletions(-) create mode 100644 npc/functions/math.txt (limited to 'npc/functions') diff --git a/npc/functions/main.txt b/npc/functions/main.txt index ffac13bd..f3fca9b4 100644 --- a/npc/functions/main.txt +++ b/npc/functions/main.txt @@ -50,10 +50,6 @@ function script adddefaultskills { return; } -function script str { - return "" + getarg(0); -} - function script addremovemapmask { setmapmask getarg(0), (getmapmask(getarg(0)) | (getarg(1) + getarg(2))) ^ getarg(2); return; @@ -145,11 +141,6 @@ function script npcdebug { return; } -function script abs { - .@n = getarg(0); - return .@n >= 0 ? .@n : -.@n; -} - function script askyesno { return select (menuaction(l("Yes")), menuaction(l("No"))); @@ -178,51 +169,37 @@ function script compareandsetq { // 1 = npctalk // 2 = message function script npctalkonce { - if ((.@current_time = gettimetick(2)) < Repeat_NPC_lock) + if (getarg(2, 0) == 0) { - return false; + if (now() <= @misc_NPC_lock) + { + @misc_NPC_lock = now() + getarg(1, 1); + return false; + } + npctalk3(getarg(0)); } - Repeat_NPC_lock = .@current_time + getarg(1,1); - - if (getarg(2,0) == 0) - { - npctalk3 getarg(0); - } - else if (getarg(2,0) == 1) + else if (getarg(2, 0) == 1) { - npctalk getarg(0); + if (now() <= .talk_lock) + { + .talk_lock = now() + getarg(1, 1); + return false; + } + npctalk(getarg(0)); } - else if (getarg(2,0) == 2) + else if (getarg(2, 0) == 2) { - message strcharinfo(0), getarg(0); + if (now() <= @misc_NPC_lock) + { + @misc_NPC_lock = now() + getarg(1, 1); + return false; + } + message(strcharinfo(0), getarg(0)); } return true; } -// A somehow of BaseLevel * logn (BaseLevel * alpha). -// alpha = multiplicator factor. -// min = minimum result value. -function script lognbaselvl { - .@alpha = getarg(0, 1); - .@min = getarg(1, 1); - .@ret = 0; - .@pc_level = BaseLevel * .@alpha; - - while (.@pc_level >>= 1) - { - ++.@ret; - } - .@ret *= BaseLevel; - - if (.@ret <= .@min) - { - .@ret = .@min; - } - - return .@ret; -} - function script getquestlink { return "[@@q" + getarg(0) + "|@@]"; } diff --git a/npc/functions/math.txt b/npc/functions/math.txt new file mode 100644 index 00000000..004125c7 --- /dev/null +++ b/npc/functions/math.txt @@ -0,0 +1,40 @@ +// Evol functions. +// Authors: +// 4144 +// Reid +// Description: +// Math functions + + +// abs() +// returns the absolute value of the passed integer + +function script abs { + .@n = getarg(0); + return .@n >= 0 ? .@n : -.@n; +} + + + +// lognbaselvl({{, }}) +// returns BaseLevel * logn (BaseLevel * alpha). + +function script lognbaselvl { + .@alpha = getarg(0, 1); + .@min = getarg(1, 1); + .@ret = 0; + .@pc_level = BaseLevel * .@alpha; + + while (.@pc_level >>= 1) + { + ++.@ret; + } + .@ret *= BaseLevel; + + if (.@ret <= .@min) + { + .@ret = .@min; + } + + return .@ret; +} diff --git a/npc/functions/string.txt b/npc/functions/string.txt index 782179d5..efeaf476 100644 --- a/npc/functions/string.txt +++ b/npc/functions/string.txt @@ -2,6 +2,15 @@ // ** does not require PCRE +// str() +// returns whatever is passed, converted to string + +function script str { + return "" + getarg(0); +} + + + // startswith("", "") // returns true if begins with -- cgit v1.2.3-70-g09d2