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?
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
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?
<event type="think" name="SummonTp" script="SummonTp.lua"/>
<event type="think" name="SummonTp" script="SummonTp.lua"/>
registerCreatureEvent(cid, "SummonTp")
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:
data/creaturescripts/scripts/login.lua:Code:<event type="think" name="SummonTp" script="SummonTp.lua"/>
data/creaturescripts/scripts/SummonTp.lua:Code:registerCreatureEvent(cid, "SummonTp")
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