• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Spell Teleportation

luigilc

Lua Learner
Joined
Mar 24, 2010
Messages
863
Reaction score
37
Location
A music box
I'm trying to make a spell that teleports the caster and it's target to a x,y,z position but I'm failing hard, I'm starting to learn lua and I can't figure out how to make it to work. Can anyone help me?
 
its easy isnt it???

LUA:
local teleport = {x=1000, y=1000, z=7}
function onCastSpell(cid, var)
	doTeleportThing(cid, teleport, true)
	doSendMagicEffect(getPlayerPosition(cid), 10)
return 1
	end

u can edit the teleport to the place that u want :)
 
or.. why no use talkactions..

LUA:
function onSay(cid, words, param)
        doTeleportThing(cid, {x=0,y=,z=0})
    doSendMagicEffect(getPlayerPosition(cid), 2)
    doSendAnimatedText(getCreaturePosition(cid), '*Teleport*', TEXTCOLOR_YELLOW)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Now you are teleport")
return true
end
 
I made you a more advanced version since a simple version was already posted.

LUA:
local teleport = {x=1000, y=1000, z=7} -- teleport location
local effectid = 10 -- effect ID oncast.
local castinfight = false -- true = allow cast in fight, false = not allow

function onCast(cid, var)

if local.castinfight = false then
if isPlayerPzLocked(cid) == FALSE then
doTeleportThing(cid, teleport, true)
doSendMagicEffect(getPlayerPosition(cid), effectid)
else
doPlayerSendChannelMessage(cid, "You are in combat and therefor cannot cast this spell.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
elseif local.castinfight = true then
doTeleportThing(cid, teleport, true)
DoSendMagicEffect(getPlayerPosition(cid), effectid)
end
return true
end
 
I made you a more advanced version since a simple version was already posted.

LUA:
local teleport = {x=1000, y=1000, z=7} -- teleport location
local effectid = 10 -- effect ID oncast.
local castinfight = false -- true = allow cast in fight, false = not allow

function onCast(cid, var)

if local.castinfight = false then
if isPlayerPzLocked(cid) == FALSE then
doTeleportThing(cid, teleport, true)
doSendMagicEffect(getPlayerPosition(cid), effectid)
else
doPlayerSendChannelMessage(cid, "You are in combat and therefor cannot cast this spell.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
elseif local.castinfight = true then
doTeleportThing(cid, teleport, true)
DoSendMagicEffect(getPlayerPosition(cid), effectid)
end
return true
end

Edited: tested the spell and its not working :)
 
Last edited:
LUA:
local teleport = {x=1000, y=1000, z=7} -- teleport location
local effectid = 10 -- effect ID oncast.
local castinfight = false -- true = allow cast in fight, false = not allow
 
function onCast(cid, var)
		if castinfight == false then
			if isPlayerPzLocked(cid) == false then
				doTeleportThing(cid, teleport)
				doSendMagicEffect(getPlayerPosition(cid), effectid)
			else
				doPlayerSendChannelMessage(cid, "You are in combat and therefor cannot cast this spell.")
				doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
			end
		elseif castinfight == true then
			doTeleportThing(cid, teleport)
			doSendMagicEffect(getCreaturePosition(cid), effectid)
		end
	return true
end
Tried fixing it, test it now.
 
Thread moved to requests.
Thanks, and sorry I won't post requests on the support section anymore.
Those are for sure nice scripts, but not exactly what I wanted, I want a spell that teleports both, the attacker and the one being attacked, not only the caster, but his target too.
Is it possible?
 
LUA:
local teleportPos = {x=1000, y=1000, z=7}

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_TELEPORT)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)

function onTarget(cid, target)
        return doTeleportThing(cid, teleportPos) and doTeleportThing(target, teleportPos)
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTarget")

function onCastSpell(cid, var)
	return doCombat(cid, combat, var)
end

Code:
<instant name="Teleport Strike" words="exori tele" lvl="80" mana="800" prem="1" range="7" casterTargetOrDirection="1" blockwalls="1" exhaustion="2000" groups="1,1500" icon="87" needlearn="0" event="script" value="attack/teleport strike.lua">
    <vocation id="1"/>
    <vocation id="5"/>
</instant>
 
Make sure to wherever your teleporting them to is all No-Logout zones. If you don't want them to logout before it sends em back.

LUA:
local teleportPos = {x=1000, y=1000, z=7}
local teleportDuration = 10000 -- in milliseconds (10000 = 10 seconds)
 
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_TELEPORT)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)

local function returnPlayer(cid, pos)
	if(isPlayer(cid))then
		doTeleportThing(cid, pos)
	end
end

local function teleportPlayers(cid, target)
	addEvent(returnPlayer, teleportDuration, cid, getThingPosition(cid))
	addEvent(returnPlayer, teleportDuration, target, getThingPosition(target))
	doTeleportThing(cid)
	doTeleportThing(target)
end

function onTarget(cid, target)
	return teleportPlayers(cid, target)
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTarget")
 
function onCastSpell(cid, var)
	return doCombat(cid, combat, var)
end
 
Thank you Syntax, and also your scripts are very clean and easy to understand and it really helps me cuz I'm trying to learn lua, so, again thank you very much.
 
I wasn't able to test the script in the past few days and now I can, When I'm using Syntax script I get this error:
LUA:
[02/09/2011 15:52:15] [Error - Spell Interface] 
[02/09/2011 15:52:15] In a callback: data/spells/scripts/tsukoyomi.lua:onTarget
[02/09/2011 15:52:15] (Unknown script file)
[02/09/2011 15:52:15] Description: 
[02/09/2011 15:52:15] attempt to index a number value
Sorry for not posting this before but I couldn't test it
 
is it possible to make it like
"teleport" and if player is lookin -> then he jumps etc 3 sqm? the same for south, west and north. :)
and doesnt work if player has skull or are safe zoon rejected.
 
Try this:

Code:
function onCastSpell(cid, frompos, var, topos)
local jogadorpos = getCreaturePosition(cid)
local target = getCreatureTarget(cid)
local monsterpos = getCreaturePosition(target)
if target == isMonster or isCreature then
doTeleportThing(cid,monsterpos)
doTeleportThing(target,jogadorpos)
doSendMagicEffect(jogadorpos, 61)
doSendMagicEffect(monsterpos, 61)
else
doPlayerSendTextMessage(cid,20,'You can only use it on creatures')
end
end
 
I didn't understand azzkaban post and I need a teleport that has a limited time, when you teleport you have like 10 seconds, then it teleports both the attacker and the target to the same position they were before
 
Back
Top