luigilc
Lua Learner
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?
local teleport = {x=1000, y=1000, z=7}
function onCastSpell(cid, var)
doTeleportThing(cid, teleport, true)
doSendMagicEffect(getPlayerPosition(cid), 10)
return 1
end
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
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![]()
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
Also, DoSendMagicEffect should be doSendMagicEffectOh yes sorry, remove local.castinfight to castinfight typo
Thanks, and sorry I won't post requests on the support section anymore.Thread moved to requests.
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
<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>
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
[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
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