commit e106f7e82ec94ac947106b46e73fb4c781ed4f88 Author: Robin Kuck Date: Fri Jan 6 13:18:33 2012 +0100 structure and die_hard mod diff --git a/mods/die_hard/init.lua b/mods/die_hard/init.lua new file mode 100644 index 0000000..fda5a8e --- /dev/null +++ b/mods/die_hard/init.lua @@ -0,0 +1,30 @@ +-- 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:inventory_get_list("main") + local i=1 + while inventorylist[i]~=nil do + if math.random(1, ITEM_LOSE_DICE) ~= 1 and (inventorylist[i]~="") then + print(inventorylist[i]) + local bnumbeg, bnumend=string.find(inventorylist[i], '" ') + local oldvalue=tonumber(string.sub(inventorylist[i], bnumend)) + oldvalue=math.random(0,(oldvalue/3)-1) + local newstring=string.sub(inventorylist[i], 1, bnumend) + newstring=(newstring..tostring(oldvalue)) + if oldvalue == 0 then + inventorylist[i]="" + else + inventorylist[i]=newstring + end + end + i=i+1 + end + player:inventory_set_list("main", inventorylist) + return +end)