[MOD] Lose Items on Death

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

[MOD] Lose Items on Death

by robin » Thu Jan 05, 2012 16:17

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.
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 » Thu Jan 05, 2012 17:28

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

User avatar
Calinou
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Thu Jan 05, 2012 17:47

Love it! Should be added in official game IMO.
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Thu Jan 05, 2012 18:05

+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

by Jeija » Fri Jan 06, 2012 08:00

+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: 831
Joined: Tue Dec 13, 2011 13:45

by redcrab » Fri Jan 06, 2012 08:18

+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: 831
Joined: Tue Dec 13, 2011 13:45

by redcrab » Fri Jan 06, 2012 08:42

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))
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 » Fri Jan 06, 2012 11:43

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 » Fri Jan 06, 2012 18:36

die_hard added into RTMMP
My game: RTMG
GENTOO USER
 

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

by robin » Fri Jan 06, 2012 22:21

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))
 

User avatar
redcrab
Member
 
Posts: 831
Joined: Tue Dec 13, 2011 13:45

by redcrab » Fri Jan 06, 2012 23:05

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 » Fri Jan 06, 2012 23:13

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 » Fri Jan 06, 2012 23:14

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

User avatar
redcrab
Member
 
Posts: 831
Joined: Tue Dec 13, 2011 13:45

by redcrab » Fri Jan 06, 2012 23:40

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 » Tue Jan 10, 2012 12:00

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

User avatar
redcrab
Member
 
Posts: 831
Joined: Tue Dec 13, 2011 13:45

by redcrab » Tue Jan 10, 2012 12:26

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

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

by rahonejm » Tue Jan 10, 2012 13:43

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
 


Return to WIP Mods

Who is online

Users browsing this forum: Bing [Bot] and 12 guests

cron