Teleport an entity?

User avatar
MineYoshi
Member
 
Posts: 4267
Joined: Wed Jul 08, 2015 13:20
GitHub: MineYosh
IRC: MineYoshi
In-game: Kirby_Retro

Teleport an entity?

by MineYoshi » Mon Sep 12, 2016 19:08

I have the question, i mean i have a mob, how i teleport it with a command?
Do i need a mod, or a modification in the Engine?
People talk about freedom of speech, so i'll say that God exists.
Open your eyes!! See The big unicorn conspiracy.!! :D The government has been lying to us about unicorns!!
"I've learned there are three things you don't discuss with people: religion, politics and the Great Pumpkin" - Linus Van Pelt
I'm the Officially 1st ABJist in the world ( ͡° ͜ʖ ͡°)
 

User avatar
maikerumine
Member
 
Posts: 946
Joined: Mon Aug 04, 2014 14:27
GitHub: maikerumine
In-game: maikerumine

Re: Teleport an entity?

by maikerumine » Mon Sep 12, 2016 20:28

MineYoshi wrote:I have the question, i mean i have a mob, how i teleport it with a command?
Do i need a mod, or a modification in the Engine?

I do this hackisly with the nether portal mod, see here:
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_abm({
nodenames = {"default:portal"},
interval = 1,
chance = 2,
action = function(pos, node)
minetest.add_particlespawner(
32, --amount
4, --time
{x = pos.x - 0.25, y = pos.y - 0.25, z = pos.z - 0.25}, --minpos
{x = pos.x + 0.25, y = pos.y + 0.25, z = pos.z + 0.25}, --maxpos
{x = -0.8, y = -0.8, z = -0.8}, --minvel
{x = 0.8, y = 0.8, z = 0.8}, --maxvel
{x = 0, y = 0, z = 0}, --minacc
{x = 0, y = 0, z = 0}, --maxacc
0.5, --minexptime
1, --maxexptime
1, --minsize
2, --maxsize
false, --collisiondetection
"default_particle.png^[colorize:#FF0000:150" --texture
)
--for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
for _,obj in ipairs(minetest.get_objects_inside_radius(pos,1)) do   --maikerumine added for objects to travel
local lua_entity = obj:get_luaentity() --maikerumine added for objects to travel
--if obj:is_player() then
if obj:is_player() or lua_entity then
local meta = minetest.get_meta(pos)
local target = minetest.string_to_pos(meta:get_string("target"))
if target then
-- force emerge of target area
minetest.get_voxel_manip():read_from_map(target, target)
if not minetest.get_node_or_nil(target) then
minetest.emerge_area(
vector.subtract(target, 4), vector.add(target, 4))
end
-- teleport the player
minetest.after(3, function(obj, pos, target)
local objpos = obj:getpos() if objpos == nil then return end   --maikerumine added for objects to travel
objpos.y = objpos.y + 0.1 -- Fix some glitches at -8000
if minetest.get_node(objpos).name ~= "default:portal" then
return
end
obj:setpos(target)
minetest.sound_play("tng_transporter1", {pos=target,gain=0.5,max_hear_distance = 8,}) --maikerumine added sound when travel
local function check_and_build_portal(pos, target)
local n = minetest.get_node_or_nil(target)
if n and n.name ~= "default:portal" then
build_portal(target, pos)
minetest.after(2, check_and_build_portal, pos, target) --was 2
minetest.after(4, check_and_build_portal, pos, target)
elseif not n then
minetest.after(1, check_and_build_portal, pos, target)
end
end
minetest.after(1, check_and_build_portal, pos, target) --was 1
end, obj, pos, target)
end
end
end
end,
})


the key is here:
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 lua_entity = obj:get_luaentity() --maikerumine added for objects to travel
--if obj:is_player() then
if obj:is_player() or lua_entity then


I'm no good coder, so I hope this helps.

EDIT-- Also UjEdwin made a cool boomerang type mod that must do entity moving too.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron