Page 1 of 2

Armor drop on death

PostPosted: Sat Mar 29, 2014 12:10
by mcfan
I have a pvp server and I've installed the death mod on it, but when someone dies their armor doesn't drop. I tried copying the code and changing it for each armor slot, but all it does is duplicate the armor. why won't it work?

PostPosted: Sat Mar 29, 2014 17:12
by mcfan
Please, is there anyone who can help me?

PostPosted: Sat Mar 29, 2014 18:32
by Krock
mcfan wrote:Please, is there anyone who can help me?

What did you download? From where?
What is the source code? What did you change in it?

PostPosted: Sat Mar 29, 2014 19:05
by mcfan

PostPosted: Sat Mar 29, 2014 19:06
by mcfan
I copied it and added 1 for each armor space and revised it. and tried 100 different ways. one deleted the armor. another duplicated it. and another crashed minetest! lol

PostPosted: Sat Mar 29, 2014 19:09
by mcfan
https://forum.minetest.net/viewtopic.php?id=4654 - my armor mod. It is the one that uses shields (which I don't like). lol

PostPosted: Sun Mar 30, 2014 07:40
by minermoder27
If you do not like shields, just delete the folder called shields

As for dropping the armor, get the player's armor inventory with
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.get_inventory({type="detached", name=player:get_player_name().."_armor"})
and then just call drop() for each item

PostPosted: Sun Mar 30, 2014 11:17
by mcfan
Isn't there a armor mod just like it with boots though? And thanks, I'll try it.

PostPosted: Tue Apr 01, 2014 11:46
by mcfan
Here is what I did. It didn't work though.

minetest.register_on_dieplayer(function(player)

minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"})

local pos = player:getpos()

for i,stack in ipairs(inv:get_list("_armor")) do

local x = math.random(0, 6)/3

local z = math.random(0, 6)/3

pos.x = pos.x + x

pos.z = pos.z + z

minetest.env:add_item(pos, stack)

stack:clear()

inv:set_stack("detached", i, stack)

pos.x = pos.x - x

pos.z = pos.z - z

end

end)

PostPosted: Wed Apr 02, 2014 19:45
by minermoder27
mcfan wrote:Here is what I did. It didn't work though.

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.register_on_dieplayer(function(player)
   
minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"})
   
    local pos = player:getpos()
   
    for i,stack in ipairs(inv:get_list("_armor")) do
       
        local x = math.random(0, 6)/3
       
        local z = math.random(0, 6)/3
       
        pos.x = pos.x + x
       
        pos.z = pos.z + z
       
        minetest.env:add_item(pos, stack)
       
        stack:clear()
       
        inv:set_stack("detached", i, stack)
       
        pos.x = pos.x - x
       
        pos.z = pos.z - z
   
    end

end)


Firstly, please use the code tags. when you are writing a post, between the " and the email button, there is a <> button. this is for code.

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.register_on_dieplayer(function(player)
   
minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"})
    local pos = player:getpos()
    local armorTypes = {"head", "torso", "legs", "feet"}
    for i,stackName in ipairs(armorTypes) do
        local stack = inv:get_list(stackName .. "_armor")
        local x = math.random(0, 6)/3
        local z = math.random(0, 6)/3
        pos.x = pos.x + x
        pos.z = pos.z + z
        minetest.env:add_item(pos, stack)
        stack:clear()
        inv:set_stack("detached", i, stack)
        pos.x = pos.x - x
        pos.z = pos.z - z
    end
end)


note the code around the for loop

PostPosted: Wed Apr 02, 2014 21:27
by mcfan
17:22:19: ERROR[main]: ServerError: LuaError: error: ...sr/share/minetest/games/MiniTest/mods/death/init.lua:56: attempt to index global 'inv' (a nil value)
17:22:19: ERROR[main]: stack traceback:

I got this when I died.

PostPosted: Wed Apr 02, 2014 22:11
by minermoder27
Sorry, didn't notice,
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.get_inventory({type="detached", name=player:get_player_name().."_armor"})

should be 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
local inv = minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"})


that error is because you didn't set the local variable inv

PostPosted: Thu Apr 03, 2014 17:22
by mcfan
21:40:38: ERROR[main]: ServerError: LuaError: error: ...sr/share/minetest/games/MiniTest/mods/death/init.lua:56: attempt to index local 'inv' (a nil value)
21:40:38: ERROR[main]: stack traceback:

I got this error now.

PostPosted: Fri Apr 04, 2014 11:40
by mcfan
I tried tweaking it but to no avail. Still it has a local 'inv' nil value.

PostPosted: Fri Apr 04, 2014 19:30
by mcfan
Can someone help please. I don't know where minermoder27 went and I not sure what is wrong.

PostPosted: Sat Apr 05, 2014 00:13
by minermoder27
(Sorry for going offline so long)

What line is line 56? could you please upload the entire file, as there is no line 56. Also, it this the bottom-most piece of code in the file, or could is be changing something that then makes some code below it fail?

tip: when uploading single files, [url]pastebin.com[/url]

PostPosted: Mon Apr 07, 2014 13:42
by mcfan
minetest.register_on_dieplayer(function(player)
local inv = player:get_inventory()
local pos = player:getpos()
for i,stack in ipairs(inv:get_list("main")) do
local x = math.random(0, 6)/3
local z = math.random(0, 6)/3
pos.x = pos.x + x
pos.z = pos.z + z
minetest.env:add_item(pos, stack)
stack:clear()
inv:set_stack("main", i, stack)
pos.x = pos.x - x
pos.z = pos.z - z
end
end)

minetest.register_on_dieplayer( function (player)
local pos = player:getpos()
local x = math.random(0, 15)/10 - 1.25
local z = math.random(0, 15)/10 - 1.25
pos.x = pos.x + x
pos.z = pos.z + z
pos.y = pos.y + .25
local obj = minetest.add_item(pos, "default:apple_golden")
if obj then
obj:get_luaentity().collect = true
end
end )

minetest.register_on_dieplayer( function (player)
local dropItem = ""
if math.random(0,3) == 1 then
dropItem = "default:creeperhead"
else
dropItem = "default:head"
end

local pos = player:getpos()
local x = math.random(0, 15)/10 - 1.25
local z = math.random(0, 15)/10 - 1.25
pos.x = pos.x + x
pos.z = pos.z + z
pos.y = pos.y + .25
local obj = minetest.add_item(pos, dropItem)
if obj then
obj:get_luaentity().collect = true
end
end )

minetest.register_on_dieplayer(function(player)

local inv = minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"})
local pos = player:getpos()
local armorTypes = {"head", "torso", "legs", "feet"}
for i,stackName in ipairs(armorTypes) do
local stack = inv:get_list(stackName .. "_armor")
local x = math.random(0, 6)/3
local z = math.random(0, 6)/3
pos.x = pos.x + x
pos.z = pos.z + z
minetest.env:add_item(pos, stack)
stack:clear()
inv:set_stack("detached", i, stack)
pos.x = pos.x - x
pos.z = pos.z - z
end
end)


So yours is the last paragraph in the list.

PostPosted: Mon Apr 07, 2014 13:43
by mcfan
For some reason the code thing didn't work. I tried it with this.

PostPosted: Mon Apr 07, 2014 13:50
by Krock
mcfan wrote:For some reason the code thing didn't work. I tried it with this.

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
local inv = minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"})
    local pos = player:getpos()
    local armorTypes = {"head", "torso", "legs", "feet"}
    for i,stackName in ipairs(armorTypes) do
---> local stack = inv:get_list(stackName .. "_armor")

get_list = stack? I don't get it.

PostPosted: Mon Apr 07, 2014 14:34
by mcfan
I don't know. minermoder17 programmed it. Do you know how to fix it?

PostPosted: Tue Apr 08, 2014 21:07
by stu
mcfan wrote:I don't know. minermoder17 programmed it. Do you know how to fix it?

I have just added support for the bones mod, maybe this can help you.

#2786a81

PostPosted: Wed Apr 09, 2014 11:37
by mcfan
Not to be mean, but I don't like the bones mod. I like it to be more like MC and drop stuff when you die. If you did that are you able to fix the error I'm getting?

PostPosted: Thu Apr 10, 2014 11:21
by mcfan
Does anyone know how to fix this error?

PostPosted: Thu Apr 10, 2014 11:26
by Krock
mcfan wrote:Does anyone know how to fix this error?

Which error?

PostPosted: Thu Apr 10, 2014 13:32
by mcfan
This one:

21:40:38: ERROR[main]: ServerError: LuaError: error: ...sr/share/minetest/games/MiniTest/mods/death/init.lua:56: attempt to index local 'inv' (a nil value)
21:40:38: ERROR[main]: stack traceback:

It is in the armor drop section.

PostPosted: Fri Apr 11, 2014 12:31
by mcfan
I couldn't figure out how to fix this error. Could someone help me please?

PostPosted: Fri Apr 11, 2014 15:45
by Achilles
This is a good idea... Armor lasts ages... Will be good to have it drop when you die.

PostPosted: Fri Apr 11, 2014 15:45
by Achilles
Even better if it gets pulverizes when you die

PostPosted: Fri Apr 11, 2014 15:46
by Achilles
Any chance of that happening?

PostPosted: Fri Apr 11, 2014 18:21
by mcfan
It is better dropping than being pulverized because the player who killed you can then get the armor and use it.