• 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?
 
LUA:
function onCastSpell(cid, var)

local teleport = {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 returnPlayer = doTeleportThing(cid, pos)
	
	if isPlayer(cid) and isPlayer(target) == true then
	addEvent(returnPlayer, teleportDuration, cid, getThingPosition(cid))
	addEvent(returnPlayer, teleportDuration, target, getThingPosition(target))
	doTeleportThing(cid, teleport)
	doTeleportThing(target, teleport)
	elseif not isPlayer(target) then
	doPlayerSendTextMessage(cid,25,"You must be attacking another player.")
end	
return doCombat(cid, combat, var)
end
 
error on console:
LUA:
[03/09/2011 14:46:02] [Error - LuaScriptInterface::loadFile] data/spells/scripts/tsukoyomi.lua:18: '<eof>' expected near 'end'
[03/09/2011 14:46:02] [Warning - Event::loadScript] Cannot load script (data/spells/scripts/tsukoyomi.lua)
[03/09/2011 14:46:02] data/spells/scripts/tsukoyomi.lua:18: '<eof>' expected near 'end'

Edit recopied and now is fixed but when i cast spell server freezs and I get lots of errors:
LUA:
[03/09/2011 14:52:34] [Error - Spell Interface] 
[03/09/2011 14:52:34] data/spells/scripts/support/haste.lua:onCastSpell
[03/09/2011 14:52:34] Description: 
[03/09/2011 14:52:34] (luaAddEvent) Callback parameter should be a function.

[03/09/2011 14:52:55] [Error - Spell Interface] 
[03/09/2011 14:52:55] data/spells/scripts/support/haste.lua:onCastSpell
[03/09/2011 14:52:55] Description: 
[03/09/2011 14:52:55] (luaAddEvent) Callback parameter should be a function.

[03/09/2011 14:53:05] [Error - Spell Interface] 
[03/09/2011 14:53:05] data/spells/scripts/support/haste.lua:onCastSpell
[03/09/2011 14:53:05] Description: 
[03/09/2011 14:53:05] (luaAddEvent) Callback parameter should be a function.

[03/09/2011 14:53:26] [Error - Spell Interface] 
[03/09/2011 14:53:26] data/spells/scripts/support/haste.lua:onCastSpell
[03/09/2011 14:53:26] Description: 
[03/09/2011 14:53:26] (luaAddEvent) Callback parameter should be a function.
[03/09/2011 14:54:19] [HOST]Legless has logged out.
[03/09/2011 14:54:21] Test has logged in.

[03/09/2011 14:54:49] [Error - Spell Interface] 
[03/09/2011 14:54:50] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:50] Description: 
[03/09/2011 14:54:50] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:54:50] [Error - Spell Interface] 
[03/09/2011 14:54:50] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:50] Description: 
[03/09/2011 14:54:50] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:50] [Error - Spell Interface] 
[03/09/2011 14:54:50] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:50] Description: 
[03/09/2011 14:54:50] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:50] [Error - Spell Interface] 
[03/09/2011 14:54:50] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:50] Description: 
[03/09/2011 14:54:50] attempt to index a nil value
[03/09/2011 14:54:50] stack traceback:
[03/09/2011 14:54:50] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:54:50] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:54:52] [Error - Spell Interface] 
[03/09/2011 14:54:52] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:52] Description: 
[03/09/2011 14:54:52] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:54:52] [Error - Spell Interface] 
[03/09/2011 14:54:52] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:52] Description: 
[03/09/2011 14:54:52] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:52] [Error - Spell Interface] 
[03/09/2011 14:54:52] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:52] Description: 
[03/09/2011 14:54:52] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:52] [Error - Spell Interface] 
[03/09/2011 14:54:52] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:52] Description: 
[03/09/2011 14:54:52] attempt to index a nil value
[03/09/2011 14:54:52] stack traceback:
[03/09/2011 14:54:52] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:54:52] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:54:54] [Error - Spell Interface] 
[03/09/2011 14:54:54] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:54] Description: 
[03/09/2011 14:54:54] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:54:54] [Error - Spell Interface] 
[03/09/2011 14:54:54] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:54] Description: 
[03/09/2011 14:54:55] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:55] [Error - Spell Interface] 
[03/09/2011 14:54:55] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:55] Description: 
[03/09/2011 14:54:55] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:55] [Error - Spell Interface] 
[03/09/2011 14:54:55] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:55] Description: 
[03/09/2011 14:54:55] attempt to index a nil value
[03/09/2011 14:54:55] stack traceback:
[03/09/2011 14:54:55] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:54:55] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:54:56] [Error - Spell Interface] 
[03/09/2011 14:54:56] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:56] Description: 
[03/09/2011 14:54:56] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:54:56] [Error - Spell Interface] 
[03/09/2011 14:54:56] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:56] Description: 
[03/09/2011 14:54:56] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:56] [Error - Spell Interface] 
[03/09/2011 14:54:56] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:57] Description: 
[03/09/2011 14:54:57] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:57] [Error - Spell Interface] 
[03/09/2011 14:54:57] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:57] Description: 
[03/09/2011 14:54:57] attempt to index a nil value
[03/09/2011 14:54:57] stack traceback:
[03/09/2011 14:54:57] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:54:57] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:54:57] [Error - Spell Interface] 
[03/09/2011 14:54:57] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:57] Description: 
[03/09/2011 14:54:57] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:54:57] [Error - Spell Interface] 
[03/09/2011 14:54:57] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:57] Description: 
[03/09/2011 14:54:57] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:57] [Error - Spell Interface] 
[03/09/2011 14:54:57] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:57] Description: 
[03/09/2011 14:54:57] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:57] [Error - Spell Interface] 
[03/09/2011 14:54:57] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:57] Description: 
[03/09/2011 14:54:57] attempt to index a nil value
[03/09/2011 14:54:57] stack traceback:
[03/09/2011 14:54:57] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:54:58] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:54:58] [Error - Spell Interface] 
[03/09/2011 14:54:58] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:58] Description: 
[03/09/2011 14:54:58] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:54:58] [Error - Spell Interface] 
[03/09/2011 14:54:58] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:58] Description: 
[03/09/2011 14:54:58] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:58] [Error - Spell Interface] 
[03/09/2011 14:54:58] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:58] Description: 
[03/09/2011 14:54:58] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:58] [Error - Spell Interface] 
[03/09/2011 14:54:58] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:58] Description: 
[03/09/2011 14:54:58] attempt to index a nil value
[03/09/2011 14:54:58] stack traceback:
[03/09/2011 14:54:58] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:54:58] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:54:59] [Error - Spell Interface] 
[03/09/2011 14:54:59] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:59] Description: 
[03/09/2011 14:54:59] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:54:59] [Error - Spell Interface] 
[03/09/2011 14:54:59] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:54:59] Description: 
[03/09/2011 14:54:59] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:54:59] [Error - Spell Interface] 
[03/09/2011 14:55:00] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:00] Description: 
[03/09/2011 14:55:00] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:55:00] [Error - Spell Interface] 
[03/09/2011 14:55:00] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:00] Description: 
[03/09/2011 14:55:00] attempt to index a nil value
[03/09/2011 14:55:00] stack traceback:
[03/09/2011 14:55:00] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:55:00] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:55:00] [Error - Spell Interface] 
[03/09/2011 14:55:00] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:00] Description: 
[03/09/2011 14:55:00] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:55:00] [Error - Spell Interface] 
[03/09/2011 14:55:00] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:00] Description: 
[03/09/2011 14:55:01] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:55:01] [Error - Spell Interface] 
[03/09/2011 14:55:01] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:01] Description: 
[03/09/2011 14:55:01] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:55:01] [Error - Spell Interface] 
[03/09/2011 14:55:01] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:01] Description: 
[03/09/2011 14:55:01] attempt to index a nil value
[03/09/2011 14:55:01] stack traceback:
[03/09/2011 14:55:01] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:55:01] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>

[03/09/2011 14:55:01] [Error - Spell Interface] 
[03/09/2011 14:55:01] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:01] Description: 
[03/09/2011 14:55:01] (luaCreateCombatObject) This function can only be used while loading the script.

[03/09/2011 14:55:01] [Error - Spell Interface] 
[03/09/2011 14:55:01] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:01] Description: 
[03/09/2011 14:55:01] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:55:02] [Error - Spell Interface] 
[03/09/2011 14:55:02] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:02] Description: 
[03/09/2011 14:55:02] (luaSetCombatParam) This function can only be used while loading the script.

[03/09/2011 14:55:02] [Error - Spell Interface] 
[03/09/2011 14:55:02] data/spells/scripts/tsukoyomi.lua:onCastSpell
[03/09/2011 14:55:02] Description: 
[03/09/2011 14:55:02] attempt to index a nil value
[03/09/2011 14:55:02] stack traceback:
[03/09/2011 14:55:02] 	[C]: in function 'doTeleportThing'
[03/09/2011 14:55:02] 	data/spells/scripts/tsukoyomi.lua:9: in function <data/spells/scripts/tsukoyomi.lua:1>
 
Last edited:
Sorry thought this was done. I missed a param.

data/spells/spells.xml
Code:
<instant name="Teleport Strike" words="exeta port" lvl="20" mana="500" range="1" casterTargetOrDirection="1" exhaustion="5000" needlearn="0" event="script" value="attack/teleport strike.lua"/>

data/spells/scripts/attack/teleport strike.lua
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, teleportPos)
	doTeleportThing(target, teleportPos)
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


 
Here, use this, just tested it:

Bs5rJk2.gif


Code:
function onCastSpell(cid, var)
local target = variantToNumber(var)
local teleportPos = {x = 1475, y = 1514, z = 9}
local teleportDuration = 10000 -- in milliseconds (10000 = 10 seconds)
local savePos, savePos2 = getThingPos(cid), getThingPos(target)

doTeleportThing(cid, teleportPos)
doTeleportThing(target, teleportPos)

addEvent(function()
doTeleportThing(cid, savePos)
doTeleportThing(target, savePos2)
end, teleportDuration)

end

EDIT: You might want to add some more effects/messages or other aesthetics.
 
Back
Top