Sure that any modder can answer my noob issue
I try to fix die_hard mod but still has a nil exception
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
ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: .../Minetest-staging/bin/../data/moddie_hard/init.lua:13: attempt to call method 'is_empty'
(a nil value)
on inventory ref "inventorylist[ i] :is_empty()"
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 Die Hard Mod
-- Players lose most of their items.
math.randomseed(os.time())
-- You need to roll ONE out of ITEM_LOSE_DICE
local ITEM_LOSE_DICE = 4
minetest.register_on_dieplayer(function(player)
local inventorylist=player:get_inventory():get_list("main")
local i=1
while inventorylist[i]~=nil do
if math.random(1, ITEM_LOSE_DICE) ~= 1 and (not (inventorylist[ i ]:is_empty())) then
print(inventorylist[i]:get_name())
-- local bnumbeg, bnumend=string.find(inventorylist[ i ], '" ')
-- local oldvalue=tonumber(string.sub(inventorylist[ i ], bnumend))
local lostquantum=inventorylist[ i ]:get_count()
lostquantum=math.random(0,(oldvalue*2/3))
-- local newstring=string.sub(inventorylist[ i ], 1, bnumend)
-- newstring=(newstring..tostring(oldvalue))
-- if oldvalue == 0 then
-- inventorylist[ i ]=""
-- else
-- inventorylist[ i ]=newstring
-- end
inventorylist[ i ]:take_item(lostquantum)
end
i=i+1
end
player:get_inventory():set_list("main", inventorylist)
return
end)
print("[die_hard] Loaded!")
Thanks