Skip to content

Instantly share code, notes, and snippets.

@Zbizu
Created April 2, 2022 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zbizu/19588f1e0c8a8e9507babf06aa2e157b to your computer and use it in GitHub Desktop.
Save Zbizu/19588f1e0c8a8e9507babf06aa2e157b to your computer and use it in GitHub Desktop.
move all creatures and items from one position to another
-- no need to redefine this in every script, just paste it to your libs
function Position:moveAll(newPos)
local tile = Tile(self)
if tile then
local tileStack = tile:getItems()
for _, tileItem in pairs(tileStack) do
local itemType = tileItem:getType()
if itemType:isMovable() then
tileItem:moveTo(relocatePos)
elseif itemType:getType() == ITEM_TYPE_MAGICFIELD then
tileItem:remove()
end
end
tileStack = tile:getCreatures()
for _, tileCreature in pairs(tileStack) do
tileCreature:teleportTo(relocatePos)
end
return true
end
return false
end
-- example talkaction
local relocatePos = Position(95, 117, 7)
local talk = TalkAction("!test")
function talk.onSay(player, words, param)
local playerPos = player:getPosition()
playerPos:moveAll(relocatePos)
end
talk:register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment