The Entities module provides access to all Entity objects currently loaded.
Here is an overview of the Entities functions:
Function | Parameters | Results |
---|---|---|
find | selector | table |
summon | nbt | Entity |
Below you find short descriptions about each of the functions and some examples about how to use them in your spells.
The ‘find’ function returns a table of Entity objects that match the given selector.
Printing the number of all players currently logged in.
found = Entities.find("@a")
print(#found)
Printing the position of player mickkay.
found = Entities.find("mickkay")[1]
print(found.pos)
Printing the positions of all cows in the (loaded part of the) world.
found = Entities.find("@e[type=cow]")
for _,cow in pairs(found) do
print(cow.pos)
end
Printing the names of all dropped items in the (loaded part of the) world.
found = Entities.find("@e[type=item]")
for _,e in pairs(found) do
print(e.name)
end
The ‘summon’ function returns a freshly created entity of the given type, having the optionally given Nbt values.
Creating a pig and moving it half a meter upwards.
pig = Entities.summon("pig")
pig:move("up",0.5)
Creating a creeper with no AI.
Entities.summon("creeper", {NoAI=1})
Creating a zombie with no AI that is spinning around.
z = Entities.summon("zombie", {NoAI=1})
while true do
z.rotationYaw = z.rotationYaw + 10
sleep(1)
end