• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Summon floorchange

Andréew

Humble mapper.
Joined
Apr 14, 2015
Messages
821
Solutions
2
Reaction score
1,806
Location
Sweden
Hey guys! i have this piece of code i found here on the forum made by @azzkaban, i edited it abit to my likings.
tho to the point, i would like do know how to add so that the summon will get teleported to me if im to far away or change floor.

here is the code, im using TFS 1.2

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, 0, 0, 0)
local maxsumons = 1
function onCastSpell(cid, var)
    local summoncount = getCreatureSummons(cid)
    if #summoncount < 1 then
        for i = 1, maxsumons - #summoncount do
            doConvinceCreature(cid, doSummonCreature("Skeleton", getCreaturePosition(cid)))
        end
    end
    return doCombat(cid, combat, var)
end
 
Solution
Change your spell to:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, 0, 0, 0)
local maxsumons = 1
function onCastSpell(creature, variant)
    local summoncount = #creature:getSummons()
    if summoncount < 1 then
        for i = 1, maxsumons - summoncount do
            local summon = Game.createMonster("Skeleton", creature:getPosition())
            if summon ~= nil then
                summon:setMaster(creature)
                summon:registerEvent("summontp")
            end
        end
    end
    return combat:execute(creature, variant)
end

Add this to...

Frija

Well-Known Member
Joined
Jul 2, 2014
Messages
106
Solutions
22
Reaction score
54
Change your spell to:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, 0, 0, 0)
local maxsumons = 1
function onCastSpell(creature, variant)
    local summoncount = #creature:getSummons()
    if summoncount < 1 then
        for i = 1, maxsumons - summoncount do
            local summon = Game.createMonster("Skeleton", creature:getPosition())
            if summon ~= nil then
                summon:setMaster(creature)
                summon:registerEvent("summontp")
            end
        end
    end
    return combat:execute(creature, variant)
end

Add this to creaturescripts.xml:
Code:
<event type="think" name="summontp" script="summon_tp.lua" />

In summon_tp.lua:
Lua:
local maxDistance = 8

local function getFreePos(position)
    local usePosition = Position(position)
    local tiles = { Tile(usePosition) }

    local tile
    for y = -1, 1 do
        for x = -1, 1 do
            if x ~= 0 or y ~= 0 then
                usePosition.x = position.x + x
                usePosition.y = position.y + y

                tile = Tile(usePosition)
                if tile then
                    tiles[#tiles + 1] = tile
                end
            end
        end
    end

    for i = 1, #tiles do
        tile = tiles[i]
        if tile:getCreatureCount() == 0 and not tile:hasProperty(CONST_PROP_BLOCKSOLID) and not tile:hasFlag(TILESTATE_PROTECTIONZONE) and not tile:hasFlag(TILESTATE_FLOORCHANGE) and not tile:hasFlag(TILESTATE_TELEPORT) then
            return tile:getPosition()
        end
    end
    return false
end

function onThink(creature, interval)
    local master = creature:getMaster()
    if master then
        local masterPos = master:getPosition()
        local creaturePos = creature:getPosition()
        if creaturePos:getDistance(masterPos) > maxDistance or creaturePos.z ~= masterPos.z then
            local destination = getFreePos(masterPos)
            if destination then
                creature:teleportTo(destination)
            end
        end
    end
    return true
end

If you try to set maxDistance to anything higher the script shouldn't work as the monster will be in indle state.
 
Solution
Top