Created
April 2, 2022 02:56
-
-
Save Zbizu/19588f1e0c8a8e9507babf06aa2e157b to your computer and use it in GitHub Desktop.
move all creatures and items from one position to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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