maikerumine wrote:Can a broken mod stuck in a loop cause insane server lag?
Byakuren wrote:the register_on_craft callbacks receive the old craft grid (from before crafting) and the inventory the craft is from. So you should be able to look at the hammer from the old craft grid and insert it back into the inventory with more wear.
You could do something similar to send the hammer to the player's inventory instead, since the callback will receive an ObjectRef to the player as another argument.
Misadventure wrote:Byakuren wrote:the register_on_craft callbacks receive the old craft grid (from before crafting) and the inventory the craft is from. So you should be able to look at the hammer from the old craft grid and insert it back into the inventory with more wear.
You could do something similar to send the hammer to the player's inventory instead, since the callback will receive an ObjectRef to the player as another argument.
From what ive been able to search and find, I can't seem to locate very much information on the register_on_craft.
so I'm still not entirely sure how id go about using this, and what id write for it to function the way im intending. I know this sounds like im asking "hold my hand through the whole process" but i'm doing my best as a young learner to try and wrap my head around this, however the lack of information i'm able to find and piece together makes this troublesome and difficult to do without me asking silly question, such as these where they imply i need my hand held.
Hybrid Dog wrote:e^(-b) = 2*e^(-b*d)-1
e and d are known, b is not 0. How can l shift the equation to get b?
local function getb(d)
return math.log(2*d) / (1 - d)
end
local function geta(b)
return 1/(1-math.exp(-b))
end
local function v(d)
print("d = " .. d)
local b = getb(d)
print("b = " .. b)
local a = geta(b)
print("a = " .. a)
-- col should be 0.5
local col = a*(1-math.exp(-b*d))
print("col = " .. col)
return col
end
for i = 0,10 do
v(i/10)
print("\r")
end
local function geta(b)
return 1/(1-math.exp(-b))
end
local minb = -1002
local maxb = 30001
local function v(d)
local b
io.write("d = " .. d.."\n")
for i = 0,100 do
b = (minb+maxb)/2
io.write("b = " .. b.."; ")
local a = geta(b)
--print("a = " .. a)
local col = a*(1-math.exp(-b*d))
io.write("col = " .. col.."\n")
if math.log(col-0.5)/math.log(10) < -9
or tostring(col) == "nan" then
break
elseif col < 0.5 then
minb = b
else
maxb = b
end
end
end
v(0.8)
local function geta(b)
return 1/(1-math.exp(-b))
end
local function v(d)
local minb = -1002
local maxb = 30001
local b
--io.write("d = " .. d.."\n")
for i = 0,100 do
b = (minb+maxb)/2
--io.write("b = " .. b.."; ")
local a = geta(b)
--print("a = " .. a)
local col = a*(1-math.exp(-b*d))
--io.write("col = " .. col.."\n")
if math.log(col-0.5)/math.log(10) < -9
or tostring(col) == "nan" then
break
elseif col < 0.5 then
minb = b
else
maxb = b
end
end
return b
end
for i = 0,10 do
local d = i/10
io.write("d = " .. d..";"..(" "):rep(5-#tostring(d)).."b = "..v(d).."\n")
end
d = 0; b = 30001
d = 0.1; b = 6.921614307927
d = 0.2; b = 3.2812798977898
d = 0.3; b = 1.8010717819961
d = 0.4; b = 0.82216324127785
d = 0.5; b = 9.4905772130005e-09
d = 0.6; b = -0.82216322934596
d = 0.7; b = -1.8010717700643
d = 0.8; b = -3.2812798929072
d = 0.9; b = -6.9216142889459
d = 1; b = -759.7890625
-- code including much unused
local load_time_start = os.clock()
math.randomseed(os.time()+tonumber(io.popen("date +%N"):read("*all")))
--$ luajit parab.lua | pnmtopng > dsa.png && optipng -o7 -quiet dsa.png
local s = 2^10
local col = 255
local tab = {"P3", s, s, col}
local num = 5
local function info(msg)
os.execute("notify-send '"..msg.."'")
end
local function round(n)
return math.floor(n+0.5)
end
local function gcol(c)
if c == math.huge
or tostring(c) == "-nan" then
c = 0
end
return round(c)%(col+1)
end
local function set(r,g,b)
tab[num] = gcol(r)
tab[num+1] = gcol(g)
tab[num+2] = gcol(b)
num = num+3
end
local sts = {}
local minc, maxc
local function tset(c)
if not minc then
minc = c
maxc = c
end
minc = math.min(c, minc)
maxc = math.max(c, maxc)
table.insert(sts, c)
end
local function geta(b)
return 1/(1-math.exp(-b))
end
local function v(d)
local minb = -1002
local maxb = 30001
local b
--io.write("d = " .. d.."\n")
for i = 0,100 do
b = (minb+maxb)/2
--io.write("b = " .. b.."; ")
local a = geta(b)
--print("a = " .. a)
local col = a*(1-math.exp(-b*d))
--io.write("col = " .. col.."\n")
if math.log(col-0.5)/math.log(10) < -9
or tostring(col) == "nan" then
break
elseif col < 0.5 then
minb = b
else
maxb = b
end
end
return b
end
local function f(x)
return v((x+s/2)/s)*s/100--math.sqrt(math.abs(10000-x*x))
end
local crds = {}
local a,b = -s/2+1, s/2
for x = a,b do
if x == 0 then
for y = a,b do
crds[y] = crds[y] or {}
crds[y][x] = 0.5
end
else
local yf = f(x)
if yf > b then
for y = a,b do
crds[y] = crds[y] or {}
crds[y][x] = 0
end
elseif yf < a then
for y = a,b do
crds[y] = crds[y] or {}
crds[y][x] = 1
end
else
for y = a,math.floor(yf) do
crds[y] = crds[y] or {}
crds[y][x] = 0
end
for y = math.ceil(yf),b do
crds[y] = crds[y] or {}
crds[y][x] = 1
end
local y = math.ceil(yf)
crds[y] = crds[y] or {}
crds[y][x] = math.max(0, math.min(1, y-yf))
end
end
end
-- [[
for y = s/2,-s/2+1,-1 do
for x = 1,s do
x = x-s/2
tset(crds[y][x])
end
end--]]
--[[
for x = 1,s do
x = x-1--s/2
tset(do_ws_func(2, x))
end--]]
--[[
local crn = {x1=0,y1=0, x2=0,y2=0}
local hs = {}
local function seth(x,y)
if not hs[y] then
hs[y] = {}
end
if not hs[y][x] then
hs[y][x] = 1
else
hs[y][x] = hs[y][x]+1
end
crn.x1 = math.min(x, crn.x1)
crn.y1 = math.min(y, crn.y1)
crn.x2 = math.max(x, crn.x2)
crn.y2 = math.max(y, crn.y2)
end
local function geth(x,y)
if not hs[y] then
return 0
end
return hs[y][x] or 0
end
local cx = 0
local cy = 0
local dirs = {
{1,0},
{0,1},
{-1,0},
{0,-1},
}
local dif = maxc-minc
for i = 1,#sts do
local v = sts[i]
v = (v-minc)/dif
sts[i] = v
-- [ [
v = v*255
v = v*math.pi
set(v,v,v)-- ] ]
seth(cx,cy)
--info(round(v*3)+1)
--local dir = (v*300)%1
local dir = (round(v*math.pi*100))%4+1
local ndir = dirs[dir]
cx = cx+ndir[1]
cy = cy+ndir[2]
end
crn.x1 = crn.x1-5
crn.y1 = crn.y1-5
crn.x2 = crn.x2+5
crn.y2 = crn.y2+5
local s = {crn.x2-crn.x1, crn.y2-crn.y1}
tab[2] = s[1]+1
tab[3] = s[2]+1
maxc = 0
for y,xs in pairs(hs) do
for _,h in pairs(xs) do
maxc = math.max(maxc, h)
end
end
for y = crn.y1,crn.y2 do
for x = crn.x1,crn.x2 do
local c = 0
local v = hs[y]
if v then
c = hs[y][x] or 0
end
c = c*255/maxc
--c = c%2*255
set(c,c,c)
end
end--]]
local dif = maxc-minc
for i = 1,#sts do
local v = sts[i]
v = (v-minc)/dif
--sts[i] = v
-- [[
v = v*255
--v = v*math.pi
set(v,v,v)--]]
--[[
seth(cx,cy)
--info(round(v*3)+1)
--local dir = (v*300)%1
local dir = (round(v*math.pi*100))%4+1
local ndir = dirs[dir]
cx = cx+ndir[1]
cy = cy+ndir[2]--]]
end
info("fi")
print(table.concat(tab, " "))
local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "fertig nach ca. "..time.."s"
if time > 0.05 then
info(msg)
end
minetest.register_abm({
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local fuellist = inv:get_list("fuel")
{ <userdata 1> }
userdata:get_name()
Byakuren wrote:They are a list of ItemStack. You can find the methods available in the mod API doc.
get_list(listname): return full list
2016-03-17 10:44:46: ERROR[main]: Failed to load and run script from
2016-03-17 10:44:46: ERROR[main]: D:\FlipShare Data\mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua:
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: Name unified_inventory:bag_small does not follow naming conventions: "modname:" or ":" prefix required
2016-03-17 10:44:46: ERROR[main]: stack traceback:
2016-03-17 10:44:46: ERROR[main]: [C]: in function 'error'
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: in function 'check_modname_prefix'
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:98: in function 'register_item'
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:216: in function 'really_register_tool'
2016-03-17 10:44:46: ERROR[main]: ...t-0.4.13\bin\..\mods\Technic\technic_worldgen/crafts.lua:162: in function 'register_tool'
2016-03-17 10:44:46: ERROR[main]: ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory/bags.lua:173: in main chunk
2016-03-17 10:44:46: ERROR[main]: [C]: in function 'dofile'
2016-03-17 10:44:46: ERROR[main]: ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua:63: in main chunk
2016-03-17 10:44:46: ERROR[main]: ======= END OF ERROR FROM LUA ========
2016-03-17 10:44:46: ERROR[main]: Server: Failed to load and run D:\FlipShare Data\mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua
2016-03-17 10:44:46: ERROR[main]: ModError: ModError: Failed to load and run D:\FlipShare Data\mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua
2016-03-17 10:44:46: ERROR[main]: Error from Lua:
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: Name unified_inventory:bag_small does not follow naming conventions: "modname:" or ":" prefix required
2016-03-17 10:44:46: ERROR[main]: stack traceback:
2016-03-17 10:44:46: ERROR[main]: [C]: in function 'error'
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:60: in function 'check_modname_prefix'
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:98: in function 'register_item'
2016-03-17 10:44:46: ERROR[main]: ...Data\mt\minetest-0.4.13\bin\..\builtin\game\register.lua:216: in function 'really_register_tool'
2016-03-17 10:44:46: ERROR[main]: ...t-0.4.13\bin\..\mods\Technic\technic_worldgen/crafts.lua:162: in function 'register_tool'
2016-03-17 10:44:46: ERROR[main]: ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory/bags.lua:173: in main chunk
2016-03-17 10:44:46: ERROR[main]: [C]: in function 'dofile'
2016-03-17 10:44:46: ERROR[main]: ...mt\minetest-0.4.13\bin\..\mods\unifiedinventory\init.lua:63: in main chunk
2016-03-17 10:44:46: ERROR[main]: Check debug.txt for details.
minetest.register_decoration()
minetest.register_tool("headphones:1headphones", {
description = "Headphones Test Song",
inventory_image = "testh.bmp",
on_use = function()
minetest.sound_play("test")
end,
})
MineYoshi wrote:Exactly how i can stop this function with other use?Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_tool("headphones:1headphones", {
description = "Headphones Test Song",
inventory_image = "testh.bmp",
on_use = function()
minetest.sound_play("test")
end,
})
I mean i click one time, plays the sound, i click other time, the song plays again with the other.
I want to do this, i click one time, plays the sound, i click again and the stops the sound, how i do that?
--Put a global var here
sound = 'no'
minetest.register_tool("headphones:1headphones", {
description = "Headphones Test Song",
inventory_image = "testh.bmp",
on_use = function()
if sound == 'no' then
sound = minetest.sound_play("test") --keep the "reference" of the sound
else
minestes.sound_stop(sound)
sound = 'no'
end
end,
})
Users browsing this forum: No registered users and 4 guests