From 3b8d2b2e8c08527f804d60c8f2b82bbc7f13e494 Mon Sep 17 00:00:00 2001 From: Mihail Date: Wed, 31 Jul 2024 16:11:50 +0400 Subject: [PATCH 1/8] Add files via upload --- res/modules/internal/math.lua | 11 ++++++ res/modules/internal/string.lua | 65 +++++++++++++++++++++++++++++++++ res/modules/internal/table.lua | 17 +++++++++ 3 files changed, 93 insertions(+) create mode 100644 res/modules/internal/math.lua create mode 100644 res/modules/internal/string.lua create mode 100644 res/modules/internal/table.lua diff --git a/res/modules/internal/math.lua b/res/modules/internal/math.lua new file mode 100644 index 00000000..6637a5cc --- /dev/null +++ b/res/modules/internal/math.lua @@ -0,0 +1,11 @@ +function math.Rand( low, high ) + return low + (high - low) * math.random() +end + +function math.Clamp( _in, low, high ) + return math.min(math.max( _in, low ), high) +end + +function math.Lerp(frac, from, to) + return from + (to - from) * frac +end \ No newline at end of file diff --git a/res/modules/internal/string.lua b/res/modules/internal/string.lua new file mode 100644 index 00000000..944ce0a0 --- /dev/null +++ b/res/modules/internal/string.lua @@ -0,0 +1,65 @@ +function string.FormattedTime(seconds, format ) -- from gmod + if not seconds then seconds = 0 end + + local hours = math.floor(seconds / 3600) + local minutes = math.floor((seconds / 60) % 60) + local millisecs = (seconds - math.floor(seconds)) * 100 + seconds = math.floor(seconds % 60) + + if format then + return string.format(format, minutes, seconds, millisecs) + else + return {h = hours, m = minutes, s = seconds, ms = millisecs} + end +end + +function string.Left(str, num) return string.sub(str, 1, num) end +function string.Right(str, num) return string.sub(str, -num) end + +function string.Replace(str, tofind, toreplace) + local tbl = string.Explode(tofind, str) + if (tbl[1]) then return table.concat(tbl, toreplace) end + return str +end + +local totable = string.ToTable +local string_sub = string.sub +local string_find = string.find +local string_len = string.len +function string.Explode(separator, str, withpattern) + if (separator == "") then return totable(str) end + if (withpattern == nil) then withpattern = false end + + local ret = {} + local current_pos = 1 + + for i = 1, string_len(str) do + local start_pos, end_pos = string_find(str, separator, current_pos, not withpattern) + if (not start_pos) then break end + ret[i] = string_sub(str, current_pos, start_pos - 1) + current_pos = end_pos + 1 + end + + ret[#ret + 1] = string_sub(str, current_pos) + + return ret +end + +function string.Split( str, delimiter ) + return string.Explode( delimiter, str ) +end + +function string.Trim(s, char) + if char then char = string.PatternSafe(char) else char = "%s" end + return string.match(s, "^" .. char .. "*(.-)" .. char .. "*$") or s +end + +function string.TrimRight(s, char) + if char then char = string.PatternSafe(char) else char = "%s" end + return string.match(s, "^(.-)" .. char .. "*$") or s +end + +function string.TrimLeft(s, char) + if char then char = string.PatternSafe(char) else char = "%s" end + return string.match(s, "^" .. char .. "*(.+)$") or s +end \ No newline at end of file diff --git a/res/modules/internal/table.lua b/res/modules/internal/table.lua new file mode 100644 index 00000000..3dc0ee39 --- /dev/null +++ b/res/modules/internal/table.lua @@ -0,0 +1,17 @@ +function table.Copy(t) + local newT = {} + for k, v in pairs(t) do + newT[k] = v + end + return newT +end + +function table.Random(t) + local randomT = {} + for k, v in pairs(t) do randomT[#randomT + 1] = {k, v} end + + local var = randomT[math.random(1, #randomT)] + local key, value = var[1], var[2] + + return value, key +end \ No newline at end of file From 4502a1206ea88b80224b8b77540da7c2cf356531 Mon Sep 17 00:00:00 2001 From: Mihail Date: Wed, 31 Jul 2024 16:12:49 +0400 Subject: [PATCH 2/8] added some libraries --- res/scripts/stdlib.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index d634104d..ee2596c0 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -21,7 +21,7 @@ function parse_path(path) end package = { - loaded={} + loaded = {} } local __cached_scripts = {} @@ -279,13 +279,19 @@ entities.get_all = function(uids) for k,v in pairs(stdcomp.get_all()) do values[k] = v end - return values + return values else return stdcomp.get_all(uids) end end -math.randomseed(time.uptime()*1536227939) +------------------ sekta helpers + +require("core:internal/math") +require("core:internal/string") +require("core:internal/table") + +math.randomseed(time.uptime() * 1536227939) -- --------- Deprecated functions ------ -- block_index = block.index From e05b9bff5d5c75437b0c656a6b11ab7aaf45a2fa Mon Sep 17 00:00:00 2001 From: Mihail Date: Wed, 31 Jul 2024 16:18:29 +0400 Subject: [PATCH 3/8] Update stdcmd.lua --- res/scripts/stdcmd.lua | 90 ++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 55 deletions(-) diff --git a/res/scripts/stdcmd.lua b/res/scripts/stdcmd.lua index 1933ae03..18c010c3 100644 --- a/res/scripts/stdcmd.lua +++ b/res/scripts/stdcmd.lua @@ -1,13 +1,13 @@ local SEPARATOR = "________________" -SEPARATOR = SEPARATOR..SEPARATOR..SEPARATOR +SEPARATOR = SEPARATOR .. SEPARATOR .. SEPARATOR function build_scheme(command) - local str = command.name.." " + local str = command.name .. " " for i,arg in ipairs(command.args) do if arg.optional then - str = str.."["..arg.name.."] " + str = str .. "[" .. arg.name .. "] " else - str = str.."<"..arg.name.."> " + str = str .. "<" .. arg.name .. "> " end end return str @@ -16,7 +16,7 @@ end console.add_command( "clear", "Clears the console", - function () + function() local document = Document.new("core:console") document.log.text = "" end @@ -25,8 +25,7 @@ console.add_command( console.add_command( "help name:str=''", "Show help infomation for the specified command", - function (args, kwargs) - + function(args, kwargs) local name = args[1] if #name == 0 then @@ -35,10 +34,10 @@ console.add_command( local str = "Available commands:" for i,k in ipairs(commands) do - str = str.."\n "..build_scheme(console.get_command_info(k)) + str = str .. "\n " .. build_scheme(console.get_command_info(k)) end - return str.."\nuse 'help '" + return str .. "\nuse 'help '" end @@ -49,25 +48,24 @@ console.add_command( end local where = ":" - local str = SEPARATOR.."\n"..command.description.."\n"..name.." " + local str = SEPARATOR .. "\n" .. command.description .. "\n" .. name .. " " for _, arg in ipairs(command.args) do - where = where.."\n "..arg.name.." - "..arg.type + where = where .. "\n " .. arg.name .. " - " .. arg.type if arg.optional then - str = str.."["..arg.name.."] " - where = where.." (optional)" + str = str .. "[" .. arg.name .. "] " + where = where .. " (optional)" else - str = str.."<"..arg.name.."> " + str = str .. "<" .. arg.name .. "> " end end if #command.args > 0 then - str = str.."\nwhere"..where + str = str .. "\nwhere" .. where end - return str.."\n"..SEPARATOR - + return str .. "\n" .. SEPARATOR end ) @@ -75,43 +73,24 @@ console.add_command( "time.uptime", "Get time elapsed since the engine started", function() - local uptime = time.uptime() - local years = math.floor(uptime / 31536000) - local days = math.floor((uptime % 31536000) / 86400) % 365 - local hours = math.floor((uptime % 86400) / 3600) % 24 - local minutes = math.floor((uptime % 3600) / 60) % 60 - local seconds = math.floor(uptime % 60) - local formatted_uptime = "" - if years > 0 then - formatted_uptime = formatted_uptime .. years .. "y " - end - if days > 0 or years > 0 then - formatted_uptime = formatted_uptime .. days .. "d " - end - if hours > 0 or days > 0 or years > 0 then - formatted_uptime = formatted_uptime .. hours .. "h " - end - if minutes > 0 or hours > 0 or days > 0 or years > 0 then - formatted_uptime = formatted_uptime .. minutes .. "m " - end - if seconds > 0 or minutes > 0 or hours > 0 or days > 0 or years > 0 then - formatted_uptime = formatted_uptime .. seconds .. "s" - end + local t = string.FormattedTime(uptime) - return uptime .. " (" .. formatted_uptime .. ")" + formatted_uptime = t.h .. "h " .. t.m .. "m " .. t.s .. "s" + + return formatted_uptime .. " (" .. uptime .. "s)" end ) console.add_command( "tp entity:sel=$entity.id x:num~pos.x y:num~pos.y z:num~pos.z", "Teleport entity", - function (args, kwargs) + function(args, kwargs) local eid, x, y, z = unpack(args) local entity = entities.get(eid) - if entity ~= nil then + if entity then entity.transform:set_pos({x, y, z}) end end @@ -119,53 +98,54 @@ console.add_command( console.add_command( "echo value:str", "Print value to the console", - function (args, kwargs) + function(args, kwargs) return args[1] end ) console.add_command( "time.set value:num", "Set day time [0..1] where 0 is midnight, 0.5 is noon", - function (args, kwargs) - return world.set_day_time(args[1]) + function(args, kwargs) + world.set_day_time(args[1]) + return "Time set to " .. args[1] end ) console.add_command( "blocks.fill id:str x:num~pos.x y:num~pos.y z:num~pos.z w:int h:int d:int", "Fill specified zone with blocks", - function (args, kwargs) + function(args, kwargs) local name, x, y, z, w, h, d = unpack(args) local id = block.index(name) - for ly=0,h-1 do - for lz=0,d-1 do - for lx=0,w-1 do - block.set(x+lx, y+ly, z+lz, id) + for ly = 0, h - 1 do + for lz = 0, d - 1 do + for lx = 0, w - 1 do + block.set(x + lx, y + ly, z + lz, id) end end end - return tostring(w*h*d).." blocks set" + return tostring(w * h * d) .. " blocks set" end ) console.add_command( "player.respawn player:sel=$obj.id", "Respawn player entity", - function (args, kwargs) + function(args, kwargs) local eid = entities.spawn("base:player", {player.get_pos(args[1])}):get_uid() player.set_entity(args[1], eid) - return "spawned new player entity #"..tostring(eid) + return "spawned new player entity #" .. tostring(eid) end ) console.add_command( "entity.despawn entity:sel=$entity.selected", "Despawn entity", - function (args, kwargs) + function(args, kwargs) local eid = args[1] local entity = entities.get(eid) if entity ~= nil then entity:despawn() - return "despawned entity #"..tostring(eid) + return "despawned entity #" .. tostring(eid) end end ) From 987d6b6d3ff6aa04b10b3c82e78b2e28a9f5e43c Mon Sep 17 00:00:00 2001 From: sekta Date: Wed, 31 Jul 2024 17:14:17 +0400 Subject: [PATCH 4/8] . --- res/layouts/console.xml.lua | 4 ++-- res/scripts/stdcmd.lua | 17 ++++++++++++++++- res/scripts/stdlib.lua | 12 +++--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/res/layouts/console.xml.lua b/res/layouts/console.xml.lua index e23ce357..819ac1fd 100644 --- a/res/layouts/console.xml.lua +++ b/res/layouts/console.xml.lua @@ -45,8 +45,8 @@ function submit(text) setup_variables() document.log.caret = -1 - local status, result = pcall(function() return console.execute(text) end) - if result ~= nil then + local status, result = pcall(console.execute, text) + if result then console.log(result) end document.prompt.text = "" diff --git a/res/scripts/stdcmd.lua b/res/scripts/stdcmd.lua index 18c010c3..95ba2639 100644 --- a/res/scripts/stdcmd.lua +++ b/res/scripts/stdcmd.lua @@ -69,6 +69,21 @@ console.add_command( end ) +local function FormattedTime(seconds, format ) -- from gmod + if not seconds then seconds = 0 end + + local hours = math.floor(seconds / 3600) + local minutes = math.floor((seconds / 60) % 60) + local millisecs = (seconds - math.floor(seconds)) * 100 + seconds = math.floor(seconds % 60) + + if format then + return string.format(format, minutes, seconds, millisecs) + else + return {h = hours, m = minutes, s = seconds, ms = millisecs} + end +end + console.add_command( "time.uptime", "Get time elapsed since the engine started", @@ -76,7 +91,7 @@ console.add_command( local uptime = time.uptime() local formatted_uptime = "" - local t = string.FormattedTime(uptime) + local t = FormattedTime(uptime) formatted_uptime = t.h .. "h " .. t.m .. "m " .. t.s .. "s" diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index ee2596c0..d634104d 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -21,7 +21,7 @@ function parse_path(path) end package = { - loaded = {} + loaded={} } local __cached_scripts = {} @@ -279,19 +279,13 @@ entities.get_all = function(uids) for k,v in pairs(stdcomp.get_all()) do values[k] = v end - return values + return values else return stdcomp.get_all(uids) end end ------------------- sekta helpers - -require("core:internal/math") -require("core:internal/string") -require("core:internal/table") - -math.randomseed(time.uptime() * 1536227939) +math.randomseed(time.uptime()*1536227939) -- --------- Deprecated functions ------ -- block_index = block.index From f9c3ec66be5d79e654781d3fa661daa0565223b1 Mon Sep 17 00:00:00 2001 From: sekta Date: Wed, 31 Jul 2024 17:30:39 +0400 Subject: [PATCH 5/8] modified math, table and string in one file --- res/scripts/stdcmd.lua | 17 +---- res/scripts/stdlib.lua | 141 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 16 deletions(-) diff --git a/res/scripts/stdcmd.lua b/res/scripts/stdcmd.lua index 95ba2639..61dccba8 100644 --- a/res/scripts/stdcmd.lua +++ b/res/scripts/stdcmd.lua @@ -69,21 +69,6 @@ console.add_command( end ) -local function FormattedTime(seconds, format ) -- from gmod - if not seconds then seconds = 0 end - - local hours = math.floor(seconds / 3600) - local minutes = math.floor((seconds / 60) % 60) - local millisecs = (seconds - math.floor(seconds)) * 100 - seconds = math.floor(seconds % 60) - - if format then - return string.format(format, minutes, seconds, millisecs) - else - return {h = hours, m = minutes, s = seconds, ms = millisecs} - end -end - console.add_command( "time.uptime", "Get time elapsed since the engine started", @@ -91,7 +76,7 @@ console.add_command( local uptime = time.uptime() local formatted_uptime = "" - local t = FormattedTime(uptime) + local t = string.formatted_time(uptime) formatted_uptime = t.h .. "h " .. t.m .. "m " .. t.s .. "s" diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index d634104d..5895ca06 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -305,6 +305,147 @@ set_block_rotation = block.set_rotation get_block_user_bits = block.get_user_bits set_block_user_bits = block.set_user_bits +---------------------------------------------- + +function math.clamp(_in, low, high) + return math.min(math.max(_in, low), high) +end + +function math.rand(low, high) + return low + (high - low) * math.random() +end + +---------------------------------------------- + +function table.copy(t) + local copied = {} + + for k, v in pairs(t) do + copied[k] = v + end + + return copied +end + +function table.count(t) + local count = 0 + + for k, v in pairs(t) do + count = count + 1 + end + + return count +end + +function table.random(t) + return t[math.random(1, #t)] +end + +---------------------------------------------- + +local pattern_escape_replacements = { + ["("] = "%(", + [")"] = "%)", + ["."] = "%.", + ["%"] = "%%", + ["+"] = "%+", + ["-"] = "%-", + ["*"] = "%*", + ["?"] = "%?", + ["["] = "%[", + ["]"] = "%]", + ["^"] = "%^", + ["$"] = "%$", + ["\0"] = "%z" +} + +function string.pattern_safe(str) + return string.gsub(str, ".", pattern_escape_replacements) +end + +--local totable = string.ToTable +local string_sub = string.sub +local string_find = string.find +local string_len = string.len +function string.explode(separator, str, withpattern) + --if (separator == "") then return totable(str) end + if (withpattern == nil) then withpattern = false end + + local ret = {} + local current_pos = 1 + + for i = 1, string_len(str) do + local start_pos, end_pos = string_find(str, separator, current_pos, not withpattern) + if (not start_pos) then break end + ret[i] = string_sub(str, current_pos, start_pos - 1) + current_pos = end_pos + 1 + end + + ret[#ret + 1] = string_sub(str, current_pos) + + return ret +end + +function string.split(str, delimiter) + return string.explode(delimiter, str) +end + +function string.formatted_time(seconds, format) + if (not seconds) then seconds = 0 end + local hours = math.floor(seconds / 3600) + local minutes = math.floor((seconds / 60) % 60) + local millisecs = (seconds - math.floor(seconds)) * 100 + seconds = math.floor(seconds % 60) + + if (format) then + return string.format(format, minutes, seconds, millisecs) + else + return { h = hours, m = minutes, s = seconds, ms = millisecs } + end +end + +function string.replace(str, tofind, toreplace) + local tbl = string.Explode(tofind, str) + if (tbl[1]) then return table.concat(tbl, toreplace) end + return str +end + +function string.trim(s, char) + if char then char = string.pattern_safe(char) else char = "%s" end + return string.match(s, "^" .. char .. "*(.-)" .. char .. "*$") or s +end + +function string.trim_right(s, char) + if char then char = string.pattern_safe(char) else char = "%s" end + return string.match(s, "^(.-)" .. char .. "*$") or s +end + +function string.trim_left(s, char) + if char then char = string.pattern_safe(char) else char = "%s" end + return string.match(s, "^" .. char .. "*(.+)$") or s +end + +local meta = getmetatable("") + +function meta:__index(key) + local val = string[key] + if (val ~= nil) then + return val + elseif (tonumber(key)) then + return string.sub(self, key, key) + end +end + +function string.starts_with(str, start) + return string.sub(str, 1, string.len(start)) == start +end + +function string.ends_with(str, endStr) + return endStr == "" or string.sub(str, -string.len(endStr)) == endStr +end + +---------------------------------------------- + function load_script(path, nocache) on_deprecated_call("load_script") return __load_script(path, nocache) From 871f9a4880e10a752cf4897dc7573b072cc4c076 Mon Sep 17 00:00:00 2001 From: sekta Date: Wed, 31 Jul 2024 17:32:20 +0400 Subject: [PATCH 6/8] removed trash --- res/modules/internal/math.lua | 11 ------ res/modules/internal/string.lua | 65 --------------------------------- res/modules/internal/table.lua | 17 --------- 3 files changed, 93 deletions(-) delete mode 100644 res/modules/internal/math.lua delete mode 100644 res/modules/internal/string.lua delete mode 100644 res/modules/internal/table.lua diff --git a/res/modules/internal/math.lua b/res/modules/internal/math.lua deleted file mode 100644 index 6637a5cc..00000000 --- a/res/modules/internal/math.lua +++ /dev/null @@ -1,11 +0,0 @@ -function math.Rand( low, high ) - return low + (high - low) * math.random() -end - -function math.Clamp( _in, low, high ) - return math.min(math.max( _in, low ), high) -end - -function math.Lerp(frac, from, to) - return from + (to - from) * frac -end \ No newline at end of file diff --git a/res/modules/internal/string.lua b/res/modules/internal/string.lua deleted file mode 100644 index 944ce0a0..00000000 --- a/res/modules/internal/string.lua +++ /dev/null @@ -1,65 +0,0 @@ -function string.FormattedTime(seconds, format ) -- from gmod - if not seconds then seconds = 0 end - - local hours = math.floor(seconds / 3600) - local minutes = math.floor((seconds / 60) % 60) - local millisecs = (seconds - math.floor(seconds)) * 100 - seconds = math.floor(seconds % 60) - - if format then - return string.format(format, minutes, seconds, millisecs) - else - return {h = hours, m = minutes, s = seconds, ms = millisecs} - end -end - -function string.Left(str, num) return string.sub(str, 1, num) end -function string.Right(str, num) return string.sub(str, -num) end - -function string.Replace(str, tofind, toreplace) - local tbl = string.Explode(tofind, str) - if (tbl[1]) then return table.concat(tbl, toreplace) end - return str -end - -local totable = string.ToTable -local string_sub = string.sub -local string_find = string.find -local string_len = string.len -function string.Explode(separator, str, withpattern) - if (separator == "") then return totable(str) end - if (withpattern == nil) then withpattern = false end - - local ret = {} - local current_pos = 1 - - for i = 1, string_len(str) do - local start_pos, end_pos = string_find(str, separator, current_pos, not withpattern) - if (not start_pos) then break end - ret[i] = string_sub(str, current_pos, start_pos - 1) - current_pos = end_pos + 1 - end - - ret[#ret + 1] = string_sub(str, current_pos) - - return ret -end - -function string.Split( str, delimiter ) - return string.Explode( delimiter, str ) -end - -function string.Trim(s, char) - if char then char = string.PatternSafe(char) else char = "%s" end - return string.match(s, "^" .. char .. "*(.-)" .. char .. "*$") or s -end - -function string.TrimRight(s, char) - if char then char = string.PatternSafe(char) else char = "%s" end - return string.match(s, "^(.-)" .. char .. "*$") or s -end - -function string.TrimLeft(s, char) - if char then char = string.PatternSafe(char) else char = "%s" end - return string.match(s, "^" .. char .. "*(.+)$") or s -end \ No newline at end of file diff --git a/res/modules/internal/table.lua b/res/modules/internal/table.lua deleted file mode 100644 index 3dc0ee39..00000000 --- a/res/modules/internal/table.lua +++ /dev/null @@ -1,17 +0,0 @@ -function table.Copy(t) - local newT = {} - for k, v in pairs(t) do - newT[k] = v - end - return newT -end - -function table.Random(t) - local randomT = {} - for k, v in pairs(t) do randomT[#randomT + 1] = {k, v} end - - local var = randomT[math.random(1, #randomT)] - local key, value = var[1], var[2] - - return value, key -end \ No newline at end of file From 509db9790d174db2dca6b90f1130e812773f9457 Mon Sep 17 00:00:00 2001 From: sekta Date: Wed, 31 Jul 2024 17:44:25 +0400 Subject: [PATCH 7/8] srakotan --- res/scripts/stdcmd.lua | 17 +---------------- res/scripts/stdlib.lua | 38 ++++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/res/scripts/stdcmd.lua b/res/scripts/stdcmd.lua index 95ba2639..61dccba8 100644 --- a/res/scripts/stdcmd.lua +++ b/res/scripts/stdcmd.lua @@ -69,21 +69,6 @@ console.add_command( end ) -local function FormattedTime(seconds, format ) -- from gmod - if not seconds then seconds = 0 end - - local hours = math.floor(seconds / 3600) - local minutes = math.floor((seconds / 60) % 60) - local millisecs = (seconds - math.floor(seconds)) * 100 - seconds = math.floor(seconds % 60) - - if format then - return string.format(format, minutes, seconds, millisecs) - else - return {h = hours, m = minutes, s = seconds, ms = millisecs} - end -end - console.add_command( "time.uptime", "Get time elapsed since the engine started", @@ -91,7 +76,7 @@ console.add_command( local uptime = time.uptime() local formatted_uptime = "" - local t = FormattedTime(uptime) + local t = string.formatted_time(uptime) formatted_uptime = t.h .. "h " .. t.m .. "m " .. t.s .. "s" diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 5895ca06..60f9d2dd 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -285,25 +285,7 @@ entities.get_all = function(uids) end end -math.randomseed(time.uptime()*1536227939) - --- --------- Deprecated functions ------ -- -block_index = block.index -block_name = block.name -blocks_count = block.defs_count -is_solid_at = block.is_solid_at -is_replaceable_at = block.is_replaceable_at -set_block = block.set -get_block = block.get -get_block_X = block.get_X -get_block_Y = block.get_Y -get_block_Z = block.get_Z -get_block_states = block.get_states -set_block_states = block.set_states -get_block_rotation = block.get_rotation -set_block_rotation = block.set_rotation -get_block_user_bits = block.get_user_bits -set_block_user_bits = block.set_user_bits +math.randomseed(time.uptime() * 1536227939) ---------------------------------------------- @@ -444,7 +426,23 @@ function string.ends_with(str, endStr) return endStr == "" or string.sub(str, -string.len(endStr)) == endStr end ----------------------------------------------- +-- --------- Deprecated functions ------ -- +block_index = block.index +block_name = block.name +blocks_count = block.defs_count +is_solid_at = block.is_solid_at +is_replaceable_at = block.is_replaceable_at +set_block = block.set +get_block = block.get +get_block_X = block.get_X +get_block_Y = block.get_Y +get_block_Z = block.get_Z +get_block_states = block.get_states +set_block_states = block.set_states +get_block_rotation = block.get_rotation +set_block_rotation = block.set_rotation +get_block_user_bits = block.get_user_bits +set_block_user_bits = block.set_user_bits function load_script(path, nocache) on_deprecated_call("load_script") From 4894d4cf429314ab0548d8ff1517b3695f10dcc3 Mon Sep 17 00:00:00 2001 From: sekta Date: Wed, 31 Jul 2024 18:03:23 +0400 Subject: [PATCH 8/8] 1000 ms in 1 sec --- res/scripts/stdlib.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 60f9d2dd..fb8c080c 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -309,7 +309,7 @@ function table.copy(t) return copied end -function table.count(t) +function table.count_pairs(t) local count = 0 for k, v in pairs(t) do @@ -376,7 +376,7 @@ function string.formatted_time(seconds, format) if (not seconds) then seconds = 0 end local hours = math.floor(seconds / 3600) local minutes = math.floor((seconds / 60) % 60) - local millisecs = (seconds - math.floor(seconds)) * 100 + local millisecs = (seconds - math.floor(seconds)) * 1000 seconds = math.floor(seconds % 60) if (format) then