Adding Player's Name

Post Reply
RavonTUS
Member
Posts: 11
Joined: Mon Nov 11, 2013 18:02

Adding Player's Name

by RavonTUS » Post

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?

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

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

You can not change the item's name.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

by 4aiman » Post

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests