Advertisement
Guest User

[FUNCTIONS]Syreldar's quest functions

a guest
Jan 18th, 2020
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.64 KB | None | 0 0
  1. --[[
  2.     A function you can use to resend a letter right after
  3.     terminating the dialogue of the same quest without bugging out the window.
  4. ]]
  5. resend_letter = function(name)
  6.     makequestbutton(name);
  7.     q.set_title(name);
  8.     q.start();
  9. end -- function
  10.  
  11. --[[
  12.     Returns:
  13.         true, if the 'num' is an integer number,
  14.         else, false;
  15. ]]
  16. IsIntegerNumber = function(num)
  17.     return num == math.floor(num);
  18. end -- function
  19.  
  20. --[[
  21.     Returns:
  22.         true, if the 'num' integer number is Odd,
  23.         else, false.
  24. ]]
  25. IsOdd = function(num)
  26.     if (IsIntegerNumber(num)) then
  27.         return math.mod(int, 2) == 0;
  28.     end -- if
  29.  
  30.     return false;
  31. end -- function
  32.  
  33. --[[
  34.     Returns:
  35.         A random element from inside the 'table_ex' table.
  36. ]]
  37. table_get_random_item = function(table_ex)
  38.     return table_ex[math.random(table.getn(table_ex))];
  39. end -- function
  40.  
  41. --[[
  42.     Returns:
  43.         true if the 'table_ex' table_ex contains an argument which index keyword is 'keyword',
  44.         else, false.
  45.     Example:
  46.         local table = {
  47.             ["lul"] = 1,
  48.             ["asd"] = 2,
  49.             ["xd"] = 3
  50.         };
  51.         table_contains_keyword(table, "xd"); -> returns true.
  52.         table_contains_keyword(table, "nup"); -> returns false.
  53. ]]
  54. table_contains_keyword = function(table_ex, keyword)
  55.     return table_ex[keyword] ~= nil;
  56. end -- function
  57.  
  58. --[[
  59.     Returns:
  60.         true, if the 'table_ex' table contains the 'element' element.
  61. ]]
  62. table_is_in = function(table_ex, element)
  63.     for _, item in ipairs(table_ex) do
  64.         if (item == element) then
  65.             return true;
  66.         end -- if
  67.     end -- for
  68.  
  69.     return false;
  70. end -- function
  71.  
  72. --[[
  73.     Gets:
  74.         The index of the table containing the specified element.
  75.  
  76.     Example:
  77.         local table = {
  78.             [1] = 5,
  79.             [2] = 7,
  80.             [3] = 9
  81.         };
  82.  
  83.         table_get_element_index(table, 5); -> returns 1.
  84.         table_get_element_index(table, 9); -> returns 3.
  85.         table_get_element_index(table, 11); -> returns nil.
  86. ]]
  87. table_get_element_index = function(table_ex, element)
  88.     for index, item in ipairs(table_ex) do
  89.         if (item == element) then
  90.             return index;
  91.         end -- if
  92.     end -- for
  93.  
  94.     return -1;
  95. end -- function
  96.  
  97. --[[
  98.     Returns:
  99.         true, if any subarray of the specified table_ex contains a specified keyword inside it,
  100.         else false.
  101.     Example:
  102.         local table = {
  103.             [1] = {["lul"] = 4},
  104.             [2] = {["asd"] = 5},
  105.             [3] = {["xd"] = 6},
  106.         };
  107.         table_is_any_subarray_containing_keyword(table, "xd"); -> returns true.
  108.         table_is_any_subarray_containing_keyword(table, "nup"); -> returns false.
  109. ]]
  110. table_is_any_subarray_containing_keyword = function(array, keyword)
  111.     for _, subarray in ipairs(array) do
  112.         if (subarray[keyword] ~= nil) then
  113.             return true;
  114.         end -- if
  115.     end -- for
  116.  
  117.     return false;
  118. end -- function
  119.  
  120. --[[
  121.     Gets:
  122.         The index of the table_ex containing the specified keyword.
  123.     Example:
  124.         local table = {
  125.             [1] = {["lul"] = 4},
  126.             [2] = {["asd"] = 5},
  127.             [3] = {["xd"] = 6},
  128.         };
  129.         table_get_keyword_index(table, "xd"); -> returns 3.
  130.         table_get_keyword_index(table, "lul"); -> returns 1.
  131.         table_get_keyword_index(table, "nup"); -> returns nil.
  132. ]]
  133. table_get_subarray_keyword_index = function(array, keyword)
  134.     for index, subarray in ipairs(array) do
  135.         if (subarray[keyword] ~= nil) then
  136.             return index;
  137.         end -- if
  138.     end -- for
  139.  
  140.     return -1;
  141. end -- function
  142.  
  143. --[[
  144.     Returns:
  145.         The totally randomized and shuffled version of a table.
  146.         Example:
  147.                 local table_ex = {
  148.                     [1] = "lol",
  149.                     [2] = "asd",
  150.                     [3] = "xd",
  151.                     [4] = "lmao",
  152.                     [5] = "rofl"
  153.                 };
  154.                 table_shuffle(table_ex) -> returns {
  155.                     [1] = "asd",
  156.                     [2] = "lmao",
  157.                     [3] = "xd",
  158.                     [4] = "rofl",
  159.                     [5] = "lol"
  160.                 };
  161.     Since it is random, some values may be the same as before.
  162. ]]
  163. table_shuffle = function(table_ex)
  164.     for i = table.getn(table_ex), 2, -1 do
  165.         local random_element = math.random(i);
  166.         table_ex[i], table_ex[random_element] = table_ex[random_element], table_ex[i];
  167.     end -- for
  168.    
  169.     return table_ex;
  170. end -- function
  171.  
  172. --[[
  173.     Returns:
  174.         The number of days a 'value' number of seconds represents.
  175. ]]
  176. time_day_to_sec = function(value)
  177.     return time_hour_to_sec(24) * value;
  178. end -- function
  179.  
  180. --[[
  181.     Returns:
  182.         The number of weeks a 'value' number of seconds represents.
  183. ]]
  184. time_week_to_sec = function(value)
  185.     return time_day_to_sec(7) * value;
  186. end -- function
  187.  
  188. --[[
  189.     Returns:
  190.         The number of 28-day months a 'value' number of seconds represents.
  191. ]]
  192. time_month_to_sec_28_days = function(value)
  193.     return time_day_to_sec(28) * value;
  194. end -- function
  195.  
  196. --[[
  197.     Returns:
  198.         The number of 30-day months a 'value' number of seconds represents.
  199. ]]
  200. time_month_to_sec_30_days = function(value)
  201.     return time_day_to_sec(30) * value;
  202. end -- function
  203.  
  204. --[[
  205.     Returns:
  206.         The number of 31-day months a 'value' number of seconds represents.
  207. ]]
  208. time_month_to_sec_31_days = function(value)
  209.     return time_day_to_sec(31) * value;
  210. end -- function
  211.  
  212. --[[
  213.     Returns:
  214.         The time format in years, months, days, hours, minutes and seconds of a 'sec'
  215.         amount of time (in seconds) to format.
  216.     Example:
  217.         get_time_format(52165786) => returns "1 year, 7 months, 25 days, 11 hours, 17 minutes and 34 seconds".
  218. ]]
  219. get_time_format = function(sec)
  220.     local final_str = "";
  221.     local string_type = "";
  222.  
  223.     local epoch = {["hour"] = 1, ["day"] = 1, ["month"] = 1, ["year"] = 1970};
  224.     local time_formats = {
  225.         {["date"] = os.date('%Y', sec)-epoch["year"],  ["plural"] = "years",   ["singular"] = "year"},
  226.         {["date"] = os.date('%m', sec)-epoch["month"], ["plural"] = "months",  ["singular"] = "month"},
  227.         {["date"] = os.date('%d', sec)-epoch["day"],   ["plural"] = "days",    ["singular"] = "day"},
  228.         {["date"] = os.date('%H', sec)-epoch["hour"],  ["plural"] = "hours",   ["singular"] = "hour"},
  229.         {["date"] = os.date('%M', sec),                ["plural"] = "minutes", ["singular"] = "minute"},
  230.         {["date"] = os.date('%S', sec),                ["plural"] = "seconds", ["singular"] = "second"},
  231.     };
  232.  
  233.     for index, format in ipairs(time_formats) do
  234.         local date_length = tonumber(format["date"]);
  235.         if (date_length > 0) then
  236.             if (date_length > 1) then
  237.                 string_type = format["plural"];
  238.             else
  239.                 string_type = format["singular"];
  240.             end -- if/else
  241.            
  242.             local conjunction = index < table.getn(time_formats) and ", " or " and ";
  243.             if (final_str ~= "") then
  244.                 final_str = string.format("%s%s%d %s", final_str, conjunction, date_length, string_type);
  245.             else
  246.                 final_str = string.format("%d %s", date_length, string_type);
  247.             end -- if/else
  248.         end -- if
  249.     end -- for
  250.  
  251.     return final_str;
  252. end -- function
  253.  
  254. --[[
  255.     Executes:
  256.         The conversion of the 'int' integer number into a string representing that number in Roman form
  257.         Example: 1 = I, 10 = X.
  258. ]]
  259. IntToRomanStr = function(int)
  260.     if (int == 0 or not IsIntegerNumber(int)) then
  261.         return "0";
  262.     end -- if
  263.    
  264.     local str = "";
  265.     local table_ex = {
  266.         [1] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
  267.         [10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
  268.         [100] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
  269.         [1000] = {"", "M", "MM", "MMM", "MMMM", "MMMMM"}
  270.     };
  271.    
  272.     for i = 3, 0, -1 do
  273.         local index = math.pow(10, i);
  274.         local subindex = math.floor(int / index);
  275.  
  276.         str = string.format("%s%s", str, table_ex[index][subindex+1]);
  277.         int = int - subindex * index;
  278.     end -- for
  279.    
  280.     return str;
  281. end -- function
  282.  
  283. --[[
  284.     Executes:
  285.         A complete dungeon clear of the monsters and regens.
  286. ]]
  287. clear_dungeon = function()
  288.     d.clear_regen()
  289.     d.kill_all();
  290.     d.kill_all(); -- In case there are resurrecting monsters.
  291. end -- function
  292.  
  293. --[[
  294.     Returns:
  295.         The pids of every single member inside the party.
  296. ]]
  297. party_get_member_pids = function()
  298.     local pids = {party.get_member_pids()};
  299.     return pids;
  300. end -- function
  301.  
  302. --[[
  303.     Returns:
  304.         The number of members inside the party.
  305. ]]
  306. party_get_member_count = function()
  307.     local pids = {party.get_member_pids()};
  308.     return table.getn(pids);
  309. end -- function
  310.  
  311. --[[
  312.     Returns:
  313.         The map index of the first instance of the dungeon of the map which index is 'map_index'.
  314. ]]
  315. ToDungeonIndex = function(map_index)
  316.     return map_index * 10000;
  317. end -- function
  318.  
  319. --[[
  320.     Returns:
  321.         true, if the player is in the specified map which index is 'map_index'.
  322. ]]
  323. InMap = function(map_index)
  324.     return pc.get_map_index() == map_index;
  325. end -- function
  326.  
  327. --[[
  328.     Returns:
  329.         true, if the player is inside a dungeon instance of the map which index is 'map_index',
  330.         else, false.
  331. ]]
  332. InDungeon = function(map_index)
  333.     local pc_index = pc.get_map_index();
  334.     return
  335.         pc.in_dungeon() and
  336.         pc_index >= ToDungeonIndex(map_index) and
  337.         pc_index < ToDungeonIndex(map_index+1);
  338. end -- function
  339.  
  340. --[[
  341.     Returns:
  342.         The factorial of a number 'num'.
  343. ]]
  344. factorial = function(num)
  345.     local result = 1;
  346.     for i = num, 2, -1 do
  347.         result = result * i;
  348.     end -- for
  349.    
  350.     return result;
  351. end -- function
  352.  
  353. GetColor = function(color_name)
  354.     local data = {
  355.         ["aliceblue"] = {240, 248, 255},      ["antiquewhite"] = {250, 235, 215},     ["aqua"] = {0, 255, 255},                   ["aquamarine"] = {127, 255, 212},
  356.         ["azure"] = {240, 255, 255},          ["beige"] = {245, 245, 220},            ["bisque"] = {255, 228, 196},               ["black"] = {0, 0, 0},
  357.         ["blanchedalmond"] = {255, 235, 205}, ["blue"] = {0, 0, 255},                 ["blueviolet"] = {138, 43, 226},            ["brown"] = {165, 42, 42},
  358.         ["burlywood"] = {222, 184, 135},      ["cadetblue"] = {95, 158, 160},         ["chartreuse"] = {127, 255, 0},             ["chocolate"] = {210, 105, 30},
  359.         ["coral"] = {255, 127, 80},           ["cornflowerblue"] = {100, 149, 237},   ["cornsilk"] = {255, 248, 220},             ["crimson"] = {220, 20, 60},
  360.         ["cyan"] = {0, 255, 255},             ["darkblue"] = {0, 0, 139},             ["darkcyan"] = {0, 139, 139},               ["darkgoldenrod"] = {184, 134, 11},
  361.         ["darkgray"] = {169, 169, 169},       ["darkgreen"] = {0, 100, 0},            ["darkkhaki"] = {189, 183, 107},            ["darkmagenta"] = {139, 0, 139},
  362.         ["darkolivegreen"] = {85, 107, 47},   ["darkorange"] = {255, 140, 0},         ["darkorchid"] = {153, 50, 204},            ["darkred"] = {139, 0, 0},
  363.         ["darksalmon"] = {233, 150, 122},     ["darkseagreen"] = {143, 188, 139},     ["darkslateblue"] = {72, 61, 139},          ["darkslategray"] = {47, 79, 79},
  364.         ["darkturquoise"] = {0, 206, 209},    ["darkviolet"] = {148, 0, 211},         ["deeppink"] = {255, 20, 147},              ["deepskyblue"] = {0, 191, 255},
  365.         ["dimgray"] = {105, 105, 105},        ["dodgerblue"] = {30, 144, 255},        ["firebrick"] = {178, 34, 34},              ["floralwhite"] = {255, 250, 240},
  366.         ["forestgreen"] = {34, 139, 34},      ["fuchsia"] = {255, 0, 255},            ["gainsboro"] = {220, 220, 220},            ["ghostwhite"] = {248, 248, 255},
  367.         ["gold"] = {255, 215, 0},             ["goldenrod"] = {218, 165, 32},         ["gray"] = {128, 128, 128},                 ["green"] = {0, 128, 0},
  368.         ["greenyellow"] = {173, 255, 47},     ["honeydew"] = {240, 255, 240},         ["hotpink"] = {255, 105, 180},              ["indianred"] = {205, 92, 92},
  369.         ["indigo"] = {75, 0, 130},            ["ivory"] = {255, 255, 240},            ["khaki"] = {240, 230, 140},                ["lavender"] = {230, 230, 250},
  370.         ["lavenderblush"] = {255, 240, 245},  ["lawngreen"] = {124, 252, 0},          ["lemonchiffon"] = {255, 250, 205},         ["lightblue"] = {173, 216, 230},
  371.         ["lightcoral"] = {240, 128, 128},     ["lightcyan"] = {224, 255, 255},        ["lightgoldenrodyellow"] = {250, 250, 210}, ["lightgray"] = {211, 211, 211},
  372.         ["lightgreen"] = {144, 238, 144},     ["lightpink"] = {255, 182, 193},        ["lightsalmon"] = {255, 160, 122},          ["lightseagreen"] = {32, 178, 170},
  373.         ["lightskyblue"] = {135, 206, 250},   ["lightslategray"] = {119, 136, 153},   ["lightsteelblue"] = {176, 196, 222},       ["lightyellow"] = {255, 255, 224},
  374.         ["lime"] = {0, 255, 0},               ["limegreen"] = {50, 205, 50},          ["linen"] = {250, 240, 230},                ["magenta"] = {255, 0, 255},
  375.         ["maroon"] = {128, 0, 0},             ["mediumaquamarine"] = {102, 205, 170}, ["mediumblue"] = {0, 0, 205},               ["mediumorchid"] = {186, 85, 211},
  376.         ["mediumpurple"] = {147, 112, 219},   ["mediumseagreen"] = {60, 179, 113},    ["mediumslateblue"] = {123, 104, 238},      ["mediumspringgreen"] = {0, 250, 154},
  377.         ["mediumturquoise"] = {72, 209, 204}, ["mediumvioletred"] = {199, 21, 133},   ["midnightblue"] = {25, 25, 112},           ["mintcream"] = {245, 255, 250},
  378.         ["mistyrose"] = {255, 228, 225},      ["moccasin"] = {255, 228, 181},         ["navajowhite"] = {255, 222, 173},          ["navy"] = {0, 0, 128},
  379.         ["oldlace"] = {253, 245, 230},        ["olive"] = {128, 128, 0},              ["olivedrab"] = {107, 142, 35},             ["orange"] = {255, 165, 0},
  380.         ["orangered"] = {255, 69, 0},         ["orchid"] = {218, 112, 214},           ["palegoldenrod"] = {238, 232, 170},        ["palegreen"] = {152, 251, 152},
  381.         ["paleturquoise"] = {175, 238, 238},  ["palevioletred"] = {219, 112, 147},    ["papayawhip"] = {255, 239, 213},           ["peachpuff"] = {255, 218, 185},
  382.         ["peru"] = {205, 133, 63},            ["pink"] = {255, 192, 203},             ["plum"] = {221, 160, 221},                 ["powderblue"] = {176, 224, 230},
  383.         ["purple"] = {128, 0, 128},           ["red"] = {255, 0, 0},                  ["rosybrown"] = {188, 143, 143},            ["royalblue"] = {65, 105, 225},
  384.         ["saddlebrown"] = {139, 69, 19},      ["salmon"] = {250, 128, 114},           ["sandybrown"] = {244, 164, 96},            ["seagreen"] = {46, 139, 87},
  385.         ["seashell"] = {255, 245, 238},       ["sienna"] = {160, 82, 45},             ["silver"] = {192, 192, 192},               ["skyblue"] = {135, 206, 235},
  386.         ["slateblue"] = {106, 90, 205},       ["slategray"] = {112, 128, 144},        ["snow"] = {255, 250, 250},                 ["springgreen"] = {0, 255, 127},
  387.         ["steelblue"] = {70, 130, 180},       ["tan"] = {210, 180, 140},              ["teal"] = {0, 128, 128},                   ["thistle"] = {216, 191, 216},
  388.         ["tomato"] = {255, 99, 71},           ["turquoise"] = {64, 224, 208},         ["violet"] = {238, 130, 238},               ["wheat"] = {245, 222, 179},
  389.         ["white"] = {255, 255, 255},          ["whitesmoke"] = {245, 245, 245},       ["yellow"] = {255, 255, 0},                 ["yellowgreen"] = {154, 205, 50}
  390.     };
  391.  
  392.     return data[color_name];
  393. end -- function
  394.  
  395. --[[
  396.     Returns:
  397.         A normal say with a different color, the color gets chosen via GetColor() function
  398.         Example: color_say("red", "The sun is burning my skin!").
  399. ]]
  400. color_say = function(color, text)
  401.     local rgb = GetColor(color);
  402.     local r, g, b = rgb[1], rgb[2], rgb[3];
  403.    
  404.     say(color256(r, g, b)..text..color256(200, 200, 200))
  405. end -- function
  406.  
  407. --[[
  408.     Returns:
  409.         The decimal version of 'bin' binary number.
  410. ]]
  411. BinToNum = function(bin)
  412.     bin = string.reverse(bin);
  413.     local sum = 0
  414.  
  415.     for i = 1, string.len(bin) do
  416.         num = tonumber(string.sub(bin, i, i));
  417.         sum = sum + num * math.pow(2, i - 1);
  418.     end -- for
  419.    
  420.     return sum;
  421. end -- function
  422.  
  423. --[[
  424.     Returns:
  425.         The binary version of 'num' decimal number.
  426. ]]
  427. NumToBin = function(num)
  428.     if (not IsIntegerNumber(num) or num < 0) then
  429.         return 0;
  430.     end -- if
  431.  
  432.     local bits = {};
  433.     while num > 0 do
  434.         rest = math.mod(num, 2);
  435.         table.insert(bits, rest);
  436.         num = (num - rest) / 2;
  437.     end -- while
  438.    
  439.     return table.concat(bits);
  440. end -- function
  441.  
  442. --[[
  443.     Useful Dungeon functions.
  444.    
  445.     Refrain from using these inside a timer.
  446.     Will lead to crashes due to pc instance being called while not existing.
  447. ]]
  448.  
  449. GetPartyMapIndex = function()
  450.     return party.getf("map_index");
  451. end -- function
  452.  
  453. IsPartyInDungeon = function()
  454.     return d.find(GetPartyMapIndex());
  455. end -- function
  456.  
  457. GetPartyDungeonFloor = function()
  458.     return d.getf_from_map_index("dungeon_floor", GetPartyMapIndex());
  459. end -- function
  460.  
  461. IsSamePartyLeaderDungeon = function()
  462.     return d.getf_from_map_index("party_leader_pid", GetPartyMapIndex()) == party.get_leader_pid();
  463. end -- function
  464.  
  465. SetPartyMapIndex = function()
  466.     party.setf("map_index", d.get_map_index());
  467. end -- function
  468.  
  469. SetPartyLeaderPid = function()
  470.     d.setf("party_leader_pid", party.get_leader_pid());
  471. end -- function
  472.  
  473. IncreaseDungeonFloor = function()
  474.     d.setf("dungeon_floor", d.getf("dungeon_floor")+1);
  475. end -- function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement