[MOD] Lose Items on Death

Post Reply
robin
Member
Posts: 22
Joined: Mon Jan 02, 2012 15:53

[MOD] Lose Items on Death

by robin » Post

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-mine ... s/die_hard

Download ZIP
Download TAR.GZ

Updates
Fix: Wrong Interval due to rounding. Thanks redcrab.
Last edited by robin on Fri Jan 06, 2012 13:21, edited 1 time in total.

User avatar
Hackeridze
Member
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Post

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

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.
Last edited by Hackeridze on Thu Jan 05, 2012 17:32, edited 1 time in total.
My game: RTMG
GENTOO USER

User avatar
Calinou
Moderator
Posts: 3169
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

by Calinou » Post

Love it! Should be added in official game IMO.

sfan5
Moderator
Posts: 4095
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5
Location: Germany

by sfan5 » Post

+2
Mods: Mesecons | WorldEdit | Nuke & Minetest builds for Windows (32-bit & 64-bit)

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

by Jeija » Post

+1
Lol some code is from the bow&arrow mod :D! You can use it of course.
Redstone for minetest: Mesecons (mesecons.net)

User avatar
redcrab
Member
Posts: 833
Joined: Tue Dec 13, 2011 13:45
Location: France
Contact:

by redcrab » Post

+1
Death is now somethething else that only a "teleport to spawn location"
Should be part of default mods
0.4 for serious builder click here
Dedicated Minetest redcrab server forum at http://minetestbb.suret.net

It's nice to be important but it is more important to be nice.

User avatar
redcrab
Member
Posts: 833
Joined: Tue Dec 13, 2011 13:45
Location: France
Contact:

by redcrab » Post

failed to execute on latest git (06/01/2012)
"/data/mods/die/init.lua:16: bad argument #2 to 'random' (interval is empty)"

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))
Last edited by redcrab on Fri Jan 06, 2012 08:44, edited 1 time in total.
0.4 for serious builder click here
Dedicated Minetest redcrab server forum at http://minetestbb.suret.net

It's nice to be important but it is more important to be nice.

robin
Member
Posts: 22
Joined: Mon Jan 02, 2012 15:53

by robin » Post

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.
Last edited by robin on Fri Jan 06, 2012 11:46, edited 1 time in total.

User avatar
Hackeridze
Member
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Post

die_hard added into RTMMP
My game: RTMG
GENTOO USER

robin
Member
Posts: 22
Joined: Mon Jan 02, 2012 15:53

by robin » Post

unknown wrote: but I do not see any differences in your first post code... ? where is the fix ?

Code: Select all

oldvalue=math.random(0,(oldvalue/3)-1)
changed to

Code: Select all

oldvalue=math.random(0,(oldvalue/3))

User avatar
redcrab
Member
Posts: 833
Joined: Tue Dec 13, 2011 13:45
Location: France
Contact:

by redcrab » Post

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 ?
0.4 for serious builder click here
Dedicated Minetest redcrab server forum at http://minetestbb.suret.net

It's nice to be important but it is more important to be nice.

User avatar
Hackeridze
Member
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Post

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.
Last edited by Hackeridze on Fri Jan 06, 2012 23:14, edited 1 time in total.
My game: RTMG
GENTOO USER

robin
Member
Posts: 22
Joined: Mon Jan 02, 2012 15:53

by robin » Post

Argh. Somehow the patch did not make it into git. I'm sorry. It should work now.

User avatar
redcrab
Member
Posts: 833
Joined: Tue Dec 13, 2011 13:45
Location: France
Contact:

by redcrab » Post

robin wrote:Argh. Somehow the patch did not make it into git. I'm sorry. It should work now.
Thx it works now ;)
0.4 for serious builder click here
Dedicated Minetest redcrab server forum at http://minetestbb.suret.net

It's nice to be important but it is more important to be nice.

hijera
Member
Posts: 36
Joined: Sun Jun 19, 2011 13:04

by hijera » Post

cool mod... But what it could be better if things will be dropped on death place, like in MC.

User avatar
redcrab
Member
Posts: 833
Joined: Tue Dec 13, 2011 13:45
Location: France
Contact:

by redcrab » Post

hijera wrote:cool mod... But what it could be better if things will be dropped on death place, like in MC.
+1
0.4 for serious builder click here
Dedicated Minetest redcrab server forum at http://minetestbb.suret.net

It's nice to be important but it is more important to be nice.

User avatar
rinoux
Member
Posts: 184
Joined: Tue Dec 27, 2011 12:15

by rinoux » Post

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

rahonejm
Member
Posts: 88
Joined: Wed Dec 28, 2011 01:58
Location: Brazil

by rahonejm » Post

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
Sorry for possible language mistakes

Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests