structure and die_hard mod
This commit is contained in:
commit
e106f7e82e
30
mods/die_hard/init.lua
Normal file
30
mods/die_hard/init.lua
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user