Page 1 of 1

Adding Player's Name

PostPosted: Thu Apr 17, 2014 19:09
by RavonTUS
Greetings,

I haven't found as much time as I would like to improve my coding skills with lua, so I'll ask an easy question, maybe...

When a player dies, I would like to see an item dropped on the ground, but instead of just a piece of "dirt", I want it to say the player's name - "Bob's Dirt". How do you assign a name to an item?

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)
    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 name = player:get_player_name()
    local obj = minetest.add_item(pos, "default:dirt")
    obj.name = name + "'s dirt"  <-- ???
    if obj then
        obj:get_luaentity().collect = true
    end
end )


Any suggestions or examples?

-RavonTUS

PostPosted: Thu Apr 17, 2014 19:31
by Krock
You can not change the item's name.

PostPosted: Fri Apr 18, 2014 09:09
by 4aiman
You can assign metadata to any item or change the description. HOwever, should you change the description, it would change for ALL items with the same name. It can be workarounded/fixed, but it needs to be upstream to be available to everyone w/o changing anything but your mod's code.

On the other hand, meta can be used freely (unless no other mod uses meta for it's evil purposes), but you can't just see it w/o extra code.
The entities themselves can have any extra data you want them to. Just set some property to it :)

I suggest you using HUDs API to add a hud with the description of pointed_under object.
But that won't be enough to show who's dirt it was. Maybe you could also add some field to a player's formspec?