Page 1 of 1

[MOD] Lose Items on Death

PostPosted: Thu Jan 05, 2012 16:17
by robin
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.

Latest master branch from 20120106 is required.

Code
https://github.com/basicinside/dev-minetest/tree/master/mods/die_hard

Download ZIP
Download TAR.GZ

Updates
Fix: Wrong Interval due to rounding. Thanks redcrab.

PostPosted: Thu Jan 05, 2012 17:28
by Hackeridze
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.lua
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 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.

Very good idea! This will make players think twice before going to death)

Waiting for adding patch in upstream.

PostPosted: Thu Jan 05, 2012 17:47
by Calinou
Love it! Should be added in official game IMO.

PostPosted: Thu Jan 05, 2012 18:05
by sfan5
+2

PostPosted: Fri Jan 06, 2012 08:00
by Jeija
+1
Lol some code is from the bow&arrow mod :D! You can use it of course.

PostPosted: Fri Jan 06, 2012 08:18
by redcrab
+1
Death is now somethething else that only a "teleport to spawn location"
Should be part of default mods

PostPosted: Fri Jan 06, 2012 08:42
by redcrab
failed to execute on latest git (06/01/2012)
"/data/mods/die/init.lua:16: bad argument #2 to 'random' (interval 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
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))

PostPosted: Fri Jan 06, 2012 11:43
by robin
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.

PostPosted: Fri Jan 06, 2012 18:36
by Hackeridze
die_hard added into RTMMP

PostPosted: Fri Jan 06, 2012 22:21
by robin
unknown wrote:but I do not see any differences in your first post code... ? where is the fix ?


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
oldvalue=math.random(0,(oldvalue/3)-1)

changed to
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
oldvalue=math.random(0,(oldvalue/3))

PostPosted: Fri Jan 06, 2012 23:05
by redcrab
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 ?

PostPosted: Fri Jan 06, 2012 23:13
by Hackeridze
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 ?

You can get fixed version from RTMMP. Maybe robin just forgot to git push.

PostPosted: Fri Jan 06, 2012 23:14
by robin
Argh. Somehow the patch did not make it into git. I'm sorry. It should work now.

PostPosted: Fri Jan 06, 2012 23:40
by redcrab
robin wrote:Argh. Somehow the patch did not make it into git. I'm sorry. It should work now.


Thx it works now ;)

PostPosted: Tue Jan 10, 2012 12:00
by hijera
cool mod... But what it could be better if things will be dropped on death place, like in MC.

PostPosted: Tue Jan 10, 2012 12:26
by redcrab
hijera wrote:cool mod... But what it could be better if things will be dropped on death place, like in MC.


+1

PostPosted: Tue Jan 10, 2012 12:48
by rinoux
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

PostPosted: Tue Jan 10, 2012 13:43
by rahonejm
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

+1 =3