From 8a4bf716002a017de77fe7df301ef8e4aaf00a2e Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Fri, 9 Apr 2021 11:00:49 -0300 Subject: Initial commit --- npc/functions/util.txt | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 npc/functions/util.txt (limited to 'npc/functions/util.txt') diff --git a/npc/functions/util.txt b/npc/functions/util.txt new file mode 100644 index 00000000..cedd4202 --- /dev/null +++ b/npc/functions/util.txt @@ -0,0 +1,102 @@ +// Evol functions. +// Authors: +// Jesusalva +// Reid +// Description: +// Util functions + + +// season_direction({day, month}) +// returns the direction that represents our current season (approximation) +// Note: You may also use WINTER/SPRING/SUMMER/AUTUMN constants for scripts +// where the direction is not important, but the season is. (Readability) +// DOWN: Winter, 21/12 WINTER +// DOWNLEFT: Spring, 20/03 SPRING +// LEFT: Summer, 21/06 SUMMER +// UPLEFT: Autumn, 22/09 AUTUMN + +function script season_direction { + .@current_month = getarg(1, gettime(GETTIME_MONTH)); + + if (.@current_month % 3 == 0) + { + .@current_day = getarg(0, gettime(GETTIME_DAYOFMONTH)); + + switch (.@current_month) + { + case MARCH: .@season_day = 20; break; + case JUNE: .@season_day = 21; break; + case SEPTEMBER: .@season_day = 22; break; + case DECEMBER: .@season_day = 21; break; + default: break; + } + + .@is_after_season_day = .@current_day >= .@season_day ? 0 : -1; + } + + return (.@current_month / 3 + .@is_after_season_day) % 4; +} + +// This is part of Jesusalva script toolkit to make his life easier when writing +// quests. Many of these are actually redundant functions. + +// Four different flavours of setq() to quickly preserve old values +function script setq1 { + // Quest, val1 , val2 , val3 , time + setq getarg(0), getarg(1), getq2(getarg(0)), getq3(getarg(0)), getqtime(getarg(0)); + return; +} + +function script setq2 { + // Quest, val1 , val2 , val3 , time + setq getarg(0), getq(getarg(0)), getarg(1), getq3(getarg(0)), getqtime(getarg(0)); + return; +} + +function script setq3 { + // Quest, val1 , val2 , val3 , time + setq getarg(0), getq(getarg(0)), getq2(getarg(0)), getarg(1), getqtime(getarg(0)); + return; +} + +function script setqtime { + // Quest, val1 , val2 , val3 , time + setq getarg(0), getq(getarg(0)), getq2(getarg(0)), getq3(getarg(0)), getarg(1); + return; +} + +// gettimeparam(GETTIME_X) +// Returns the number of seconds/minutes/hours/days/months/years since 01/01/1970 +// This is for truly daily quests, which doesn't imposes a timed wait in hours +function script gettimeparam { + .@p=getarg(0, GETTIME_MINUTE); + + // Seconds (same as gettimetick(2) - use that instead) + .@t=gettimetick(2); + if (.@p == GETTIME_SECOND) + return .@t; + + // Minutes (default) + .@t=.@t/60; + if (.@p == GETTIME_MINUTE) + return .@t; + + // Hours + .@t=.@t/60; + if (.@p == GETTIME_HOUR) + return .@t; + + // Days + .@t=.@t/24; + if (.@p == GETTIME_DAYOFMONTH) + return .@t; + + // Months (estimative) + .@t=.@t/30; + if (.@p == GETTIME_MONTH) + return .@t; + + // Years (estimative, unused, fallback) + .@t=.@t/12; + return .@t; +} -- cgit v1.2.3-60-g2f50