robin wrote:Description: When a player dies, he rolls for every item. If the roll succeed he keeps his item, otherwise the item is removed or the amount dramatically decreased.
Code: data/mods/die/init.luaYour 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 Mod
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)
This works only with the suggested patch in the Development Section.
09:39:22: ACTION[ServerThread]: redcrab damaged by 43 hp at (-10.462,5.579,-14.641)
09:39:22: INFO[ServerThread]: Server::HandlePlayerHP(): Player redcrab dies
09:39:22: INFO[ServerThread]: Deprecated: inventory_get_list
09:39:22: ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: ...jects/Minetest-staging/bin/../data/mods/die/init.lua:16: bad argument #2 to 'random' (interval is empty)
09:39:22: ERROR[ServerThread]: stack traceback:
In thread b67ffb70:
/home/xxx/Projects/Minetest-staging/src/server.cpp:115: virtual void* ServerThread::Thread(): Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD b67ffb70:
#0 virtual void* ServerThread::Thread()
(Leftover data: #1 void Server::Receive())
(Leftover data: #2 void Server::ProcessData(irr::u8*, irr::u32, irr::u16))
(Leftover data: #3 RemoteClient* Server::getClient(irr::u16))
(Leftover data: #4 void BlockEmergeQueue::addBlock(irr::u16, v3s16, irr::u8))
DEBUG STACK FOR THREAD b74786d0:
#0 int main(int, char**)
#1 void dedicated_server_loop(Server&, bool&)
(Leftover data: #2 void Server::step(float))
unknown wrote:but I do not see any differences in your first post code... ? where is the fix ?
oldvalue=math.random(0,(oldvalue/3)-1)
oldvalue=math.random(0,(oldvalue/3))
robin wrote:Thanks redcrab. It was a wrong interval for math.random given. it should work now.
Thanks Jeija. You're right I looked up inventory handling from your mod and copied the code with some small modifications.
redcrab wrote:robin wrote:Thanks redcrab. It was a wrong interval for math.random given. it should work now.
Thanks Jeija. You're right I looked up inventory handling from your mod and copied the code with some small modifications.
Sorry but same issue, I compare and the file is identical as before ... where is the fix ?
robin wrote:Argh. Somehow the patch did not make it into git. I'm sorry. It should work now.
hijera wrote:cool mod... But what it could be better if things will be dropped on death place, like in MC.
redcrab wrote:hijera wrote:cool mod... But what it could be better if things will be dropped on death place, like in MC.
+1
rinoux wrote:redcrab wrote:hijera wrote:cool mod... But what it could be better if things will be dropped on death place, like in MC.
+1
+1 ... =2
Users browsing this forum: No registered users and 27 guests