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

[Lua] "Boomerang" Walking

I

Icy

Guest
Well I'm trying to make a spell, that when cast starts a 10-second timer. After the 10 seconds are up it'll teleport the user back to his/her original location.. but I'm having a few errors with my "custom" function..

Code:
--[[------------------
<<Script by Icy Mage>>
------------------]]--

local inDisplacement = 60000

local function teleportBack(cid, pos)
setPlayerStorageValue(cid, inDisplacement, 0)
doTeleportThing(cid, originalPosition)
doSendMagicEffect(getPlayerPosition(cid),17)
end

function onCastSpell(cid, var)

	if getPlayerStorageValue(cid, inDisplacement) < 9000 then
		originalPosition = getPlayerPosition(cid)
		setPlayerStorageValue(cid, inDisplacement, 9001)
		addEvent(teleportBack, 10000)
		doSendMagicEffect(getPlayerPosition(cid),17)
	else
		doPlayerSendTextMessage(cid,27,"You are already in temporal displacement!")
	end
	return TRUE
end
After the 10 seconds are up I get these 3 errors (relating to the `teleportBack` function not detecting the caster :p

Code:
[12/09/2009 01:56:19] Lua Script Error: [Spell Interface] 
[12/09/2009 01:56:19] in a timer event called from: 
[12/09/2009 01:56:19] data/spells/scripts/custom/temporal displacement.lua:onCastSpell

[12/09/2009 01:56:19] luaDoPlayerSetStorageValue(). Player not found

[12/09/2009 01:56:19] Lua Script Error: [Spell Interface] 
[12/09/2009 01:56:19] in a timer event called from: 
[12/09/2009 01:56:19] data/spells/scripts/custom/temporal displacement.lua:onCastSpell

[12/09/2009 01:56:19] luaDoTeleportThing(). Thing not found

[12/09/2009 01:56:19] Lua Script Error: [Spell Interface] 
[12/09/2009 01:56:19] in a timer event called from: 
[12/09/2009 01:56:19] data/spells/scripts/custom/temporal displacement.lua:onCastSpell

[12/09/2009 01:56:20] luaGetCreaturePosition(). Creature not found

[12/09/2009 01:56:20] Lua Script Error: [Spell Interface] 
[12/09/2009 01:56:20] in a timer event called from: 
[12/09/2009 01:56:20] data/spells/scripts/custom/temporal displacement.lua:onCastSpell

[12/09/2009 01:56:20] attempt to index a boolean value
[12/09/2009 01:56:20] stack traceback:
[12/09/2009 01:56:20] 	[C]: in function 'doSendMagicEffect'
[12/09/2009 01:56:20] 	data/spells/scripts/custom/temporal displacement.lua:6: in function <data/spells/scripts/custom/temporal displacement.lua:3>

Any suggestions on how I can fix the errors? :blink:
 
I beleive it may be because you put
PHP:
local function teleportBack(cid, pos)

Your not soppose to have local infront of your function
 
This should do it :)

Lua:
local inDisplacement = 60000

local function teleportBack(params)
	local cid = params.cid
	local pos = params.pos
	setPlayerStorageValue(cid, inDisplacement, 0)
	doTeleportThing(cid, originalPosition)
	doSendMagicEffect(getPlayerPosition(cid),17)
end

function onCastSpell(cid, var)

	if getPlayerStorageValue(cid, inDisplacement) < 9000 then
		originalPosition = getPlayerPosition(cid)
		setPlayerStorageValue(cid, inDisplacement, 9001)
		local params = {
			cid = cid,
			pos = originalPosition
		}
		addEvent(teleportBack, 10000)
		doSendMagicEffect(getPlayerPosition(cid),17)
	else
		doPlayerSendTextMessage(cid,27,"You are already in temporal displacement!")
	end
	return TRUE
end
 
Code:
local inDisplacement = 60000

function teleportBack(params)
        local cid = params.cid
        local pos = params.pos
        setPlayerStorageValue(cid, inDisplacement, 0)
        doTeleportThing(cid, originalPosition)
        doSendMagicEffect(getPlayerPosition(cid),17)
end

function onCastSpell(cid, var)

        if getPlayerStorageValue(cid, inDisplacement) < 9000 then
                originalPosition = getPlayerPosition(cid)
                setPlayerStorageValue(cid, inDisplacement, 9001)
                local params = {
                        cid = cid,
                        pos = originalPosition
                }
                addEvent(teleportBack, 10000, params)
                doSendMagicEffect(getPlayerPosition(cid),17)
        else
                doPlayerSendTextMessage(cid,27,"You are already in temporal displacement!")
        end
        return TRUE
end

Havent done any LUA in a while, but I believe thats correct. You were passing the parameters to the function through AddEvent


__________________

Are you tired of the customer neglect of TibiaBotNG? Do you think LoW needs to add more updates? Are you tired of using a crappy bot because its a cheap alternative to Elf? Well, dont be tired anymore! Check out my blog!
 
Last edited:
Function teleportBack should be defined as local.

Also you can use:
Code:
function teleportBack(cid, pos)

Code:
addEvent(teleportBack, 10 * 1000, cid, orginalPosition)



And... i see problem here:
Code:
doTeleportThing(cid, originalPosition)

Should be:
Code:
doTeleportThing(cid, pos)
 
Code:
local inDisplacement = 60000

function teleportBack(params)
        local cid = params.cid
        local pos = params.pos
        setPlayerStorageValue(cid, inDisplacement, 0)
        doTeleportThing(cid, originalPosition)
        doSendMagicEffect(getPlayerPosition(cid),17)
end

function onCastSpell(cid, var)

        if getPlayerStorageValue(cid, inDisplacement) < 9000 then
                originalPosition = getPlayerPosition(cid)
                setPlayerStorageValue(cid, inDisplacement, 9001)
                local params = {
                        cid = cid,
                        pos = originalPosition
                }
                addEvent(teleportBack, 10000, params)
                doSendMagicEffect(getPlayerPosition(cid),17)
        else
                doPlayerSendTextMessage(cid,27,"You are already in temporal displacement!")
        end
        return TRUE
end

Havent done any LUA in a while, but I believe thats correct. You were passing the parameters to the function through AddEvent

Thank you so much =]
 
Uhmm, one problem - if a second person casts it while the first person is already in it, then the first person teleports to the second person's original spot when the time ends z.z
 
Back
Top