Adding Player's Name

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

Adding Player's Name

by RavonTUS » Thu Apr 17, 2014 19:09

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
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

by Krock » Thu Apr 17, 2014 19:31

You can not change the item's name.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

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

by 4aiman » Fri Apr 18, 2014 09:09

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?
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 8 guests

cron