I need help with attaching an entity to a player
Have it functional for several different players, accessible from the player and the player from the entity
I've tried several times but I can't seem to add only one and still have it remain attached and remove it after leaving
Many thanks for your help!
[Question] Entity attached to player
[Question] Entity attached to player
Last edited by Extex on Thu Aug 22, 2019 01:05, edited 1 time in total.
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP
Re: [Question] Entity attached to player
See my mount code, it could help you a bit:
Code: Select all
petz.force_detach = function(player)
local attached_to = player:get_attach()
if not attached_to then
return
end
local entity = attached_to:get_luaentity()
if entity.driver and entity.driver == player then
entity.driver = nil
end
player:set_detach()
default.player_attached[player:get_player_name()] = false
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
default.player_set_animation(player, "stand" , 30)
player:set_properties({visual_size = {x = 1, y = 1}, pointable = true })
end
-------------------------------------------------------------------------------
minetest.register_on_leaveplayer(function(player)
petz.force_detach(player)
end)
minetest.register_on_shutdown(function()
local players = minetest.get_connected_players()
for i = 1, #players do
petz.force_detach(players[i])
end
end)
minetest.register_on_dieplayer(function(player)
petz.force_detach(player)
return true
end)
- Krock
- Developer
- Posts: 4650
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: [Question] Entity attached to player
@runs: They want to attach an entity to a player. Your code assumes the inverse.
Here's a 5.0+ approach:
parent = player
child = luaentity
https://github.com/minetest/minetest/bl ... 3619-L3621
Here's a 5.0+ approach:
parent = player
child = luaentity
Code: Select all
... inside object definition
on_detach(self, parent)
print("got detached from player " .. parent:get_player_name())
self.object:remove()
end,
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
Re: [Question] Entity attached to player
OK added.
But how would I attach it to the player (and keep it attached to the player) and be able to edit it in-game?
But how would I attach it to the player (and keep it attached to the player) and be able to edit it in-game?
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP
Re: [Question] Entity attached to player
I need some way to access the entity from the player, and the player from the entity.
And keep it attached to the player
And keep it attached to the player
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP
- sparky
- Member
- Posts: 154
- Joined: Sun Oct 05, 2014 00:54
- GitHub: Elkien3
- IRC: ircSparky
- In-game: sparky
- Location: USA
- Contact:
Re: [Question] Entity attached to player
What do you mean by "access"?
You can save the entity id in a table, something like:
You can also have the entity (or even the player I think) have it's own variable
eg: or
or you can get the object the entity is attached to with
I'm pretty sure when you attach an object to a player the player can't see it, nor the collision box of it, unless they are in third person.
Also the Selection/collisionboxes of entities attached to entities are not functional further than 200 nodes from (0,0,0)
You can save the entity id in a table, something like:
Code: Select all
entites[playername] = add_entity()
eg:
Code: Select all
self.owner = player
Code: Select all
entites[playername].owner = player
Code: Select all
self:get_attach()
Also the Selection/collisionboxes of entities attached to entities are not functional further than 200 nodes from (0,0,0)
Who is online
Users browsing this forum: Bing [Bot] and 16 guests