• 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!

summons teleports to player

darkflame152

New Member
Joined
Dec 16, 2008
Messages
24
Reaction score
0
how do you make a summon teleport to a player so that when the monster is off the screen he teleports next to you?
 
Creaturescripts:
Code:
local config = {
        tilesLimitToTeleport = 8, -- if summon is X sqm away it will be teleported to owner
        interval = 5, -- checks summons positions every X seconds
        teleportMonsterSummonsToo = true -- not work if your monsters havent registered this creaturescript
}

function onThink(cid, interval)
    if teleportMonsterSummonsToo == true or isMonster(cid) == false then
        local summons = getCreatureSummons(cid)
        if(not summons or next(summons) == nil) then
            return false
        end

        local pos = getThingPos(cid)
        if(getTilePzInfo(pos)) == true then
            return false
        end
        for _, sid in pairs(summons) do 
            local summonPos = getThingPos(sid)
            if(getDistanceBetween(pos, summonPos) > config.tilesLimitToTeleport or pos.z ~= summonPos.z) then
                doTeleportThing(sid, pos)
                doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
                doSendMagicEffect(summonPos, CONST_ME_MAGIC_RED)
            end
        end
    end
    return true
end

Remember to register it in login.lua
 
Creaturescripts:
Code:
local config = {
        tilesLimitToTeleport = 8, -- if summon is X sqm away it will be teleported to owner
        interval = 5, -- checks summons positions every X seconds
        teleportMonsterSummonsToo = true -- not work if your monsters havent registered this creaturescript
}

function onThink(cid, interval)
    if teleportMonsterSummonsToo == true or isMonster(cid) == false then
        local summons = getCreatureSummons(cid)
        if(not summons or next(summons) == nil) then
            return false
        end

        local pos = getThingPos(cid)
        if(getTilePzInfo(pos)) == true then
            return false
        end
        for _, sid in pairs(summons) do
            local summonPos = getThingPos(sid)
            if(getDistanceBetween(pos, summonPos) > config.tilesLimitToTeleport or pos.z ~= summonPos.z) then
                doTeleportThing(sid, pos)
                doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
                doSendMagicEffect(summonPos, CONST_ME_MAGIC_RED)
            end
        end
    end
    return true
end

Remember to register it in login.lua

How should I register it? What event type is it?
 
creaturescripts\scripts\login.lua

add this line

Code:
registerCreatureEvent(cid, "YOUR LUA NAME which you add in creature script folder")
 
data/creaturescripts/creaturescripts.xml:
Code:
<event type="think" name="SummonTp" script="SummonTp.lua"/>
data/creaturescripts/scripts/login.lua:
Code:
registerCreatureEvent(cid, "SummonTp")
data/creaturescripts/scripts/SummonTp.lua:
Code:
local config = {
        tilesLimitToTeleport = 8, -- if summon is X sqm away it will be teleported to owner
        interval = 5, -- checks summons positions every X seconds
        teleportMonsterSummonsToo = true -- not work if your monsters havent registered this creaturescript
}

function onThink(cid, interval)
    if teleportMonsterSummonsToo == true or isMonster(cid) == false then
        local summons = getCreatureSummons(cid)
        if(not summons or next(summons) == nil) then
            return false
        end

        local pos = getThingPos(cid)
        if(getTilePzInfo(pos)) == true then
            return false
        end
        for _, sid in pairs(summons) do 
            local summonPos = getThingPos(sid)
            if(getDistanceBetween(pos, summonPos) > config.tilesLimitToTeleport or pos.z ~= summonPos.z) then
                doTeleportThing(sid, pos)
                doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
                doSendMagicEffect(summonPos, CONST_ME_MAGIC_RED)
            end
        end
    end
    return true
end
 
data/creaturescripts/creaturescripts.xml:
Code:
<event type="think" name="SummonTp" script="SummonTp.lua"/>
data/creaturescripts/scripts/login.lua:
Code:
registerCreatureEvent(cid, "SummonTp")
data/creaturescripts/scripts/SummonTp.lua:
Code:
local config = {
        tilesLimitToTeleport = 8, -- if summon is X sqm away it will be teleported to owner
        interval = 5, -- checks summons positions every X seconds
        teleportMonsterSummonsToo = true -- not work if your monsters havent registered this creaturescript
}

function onThink(cid, interval)
    if teleportMonsterSummonsToo == true or isMonster(cid) == false then
        local summons = getCreatureSummons(cid)
        if(not summons or next(summons) == nil) then
            return false
        end

        local pos = getThingPos(cid)
        if(getTilePzInfo(pos)) == true then
            return false
        end
        for _, sid in pairs(summons) do
            local summonPos = getThingPos(sid)
            if(getDistanceBetween(pos, summonPos) > config.tilesLimitToTeleport or pos.z ~= summonPos.z) then
                doTeleportThing(sid, pos)
                doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
                doSendMagicEffect(summonPos, CONST_ME_MAGIC_RED)
            end
        end
    end
    return true
end

i don't think interval = 5 changes anything.
Function onThink() still executes every 1 second.
 
Back
Top