• 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 Swap Postion rune

seleo

Active Member
Joined
Jun 6, 2012
Messages
498
Reaction score
33
Location
Egypt
Hello
can someone fix this spell please
Lua:
local combat = createCombatObject()

local config = {
    notAllowed = {"training monk", "Slaktaren", "Admin"},
    exhaustStorage = 1338,
    exhaustTime = 5, -- Seconds
    slowStorage = 1339,
    slowTime = 3, -- Seconds
    slowSpeed = 100, -- Speed will be set to 100 when swaping for slowTime seconds.
    }

function effect(cid, var, targetpos, mypos, target)
    doSendMagicEffect(mypos, CONST_ME_ENERGYHIT)
    doSendMagicEffect(targetpos, CONST_ME_ENERGYHIT)
end

function slowed(cid, speed)
    doChangeSpeed(cid, getPlayerStorageValue(cid, config.slowStorage) - getCreatureSpeed(cid))
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
end

function onCastSpell(cid, var)
    setPlayerStorageValue(cid, config.slowStorage, getCreatureSpeed(cid))
    local mypos = getCreaturePosition(cid)
    local target = getCreatureTarget(cid)
    local targetpos = getCreaturePosition(target)
    if not exhaustion.get(cid, config.exhaustStorage) then
        for _,v in ipairs(config.notAllowed) do
            if string.find(getCreatureName(target):lower(), v) then
                doPlayerSendCancel(cid, "You can't swap " .. getCreatureName(target) .. "!")
                doSendMagicEffect(mypos, CONST_ME_POFF)
                return false
            else
                doTeleportThing(cid, targetpos)
                doTeleportThing(target, mypos)
                doChangeSpeed(cid, -getCreatureSpeed(cid)+config.slowSpeed)
                doSendDistanceShoot(mypos, targetpos, CONST_ANI_ENERGYBALL)
                doSendDistanceShoot(targetpos, mypos, CONST_ANI_ENERGYBALL)
                addEvent(effect, 150, cid, var, targetpos, mypos, target)
                addEvent(slowed, config.slowTime * 1000, cid, speed)
                exhaustion.set(cid, config.exhaustStorage, config.exhaustTime)
            end
        end
    else
        doPlayerSendCancel(cid, "You have to wait " .. exhaustion.get(cid, config.exhaustStorage) .. " seconds to swap positions again!")
        return false
    end
    doCombat(cid, combat, var)
    return true
end

i found that here
http://otland.net/f82/swap-positions-116071/

the problem is if i used this spell as a rune it gives me this error in console
21513d1372849291-swap-positions-2z7o7wi.jpg


and another problem you can attack a player away of you and use the rune on another one beside you and you will change position with the away player

i hope some one can fix this spell to work as a rune and dont switch positions with away players
only players that beside the caster
 
Last edited by a moderator:
Lua:
local combat = createCombatObject()
 
local config = {
    notAllowed = {"training monk", "Slaktaren", "Admin"},
    exhaustStorage = 1338,
    exhaustTime = 5, -- Seconds
    slowStorage = 1339,
    slowTime = 3, -- Seconds
    slowSpeed = 100, -- Speed will be set to 100 when swaping for slowTime seconds.
    }
 
function effect(cid, var, targetpos, mypos, target)
    doSendMagicEffect(mypos, CONST_ME_ENERGYHIT)
    doSendMagicEffect(targetpos, CONST_ME_ENERGYHIT)
end
 
function slowed(cid, speed)
    doChangeSpeed(cid, getPlayerStorageValue(cid, config.slowStorage) - getCreatureSpeed(cid))
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
end
 
function onCastSpell(cid, var)
    setPlayerStorageValue(cid, config.slowStorage, getCreatureSpeed(cid))
    local mypos = getCreaturePosition(cid)
    local target = getCreatureTarget(cid)
    local targetpos = getCreaturePosition(target)
    if not exhaustion.get(cid, config.exhaustStorage) then
        for _,v in ipairs(config.notAllowed) do
            if isInArray(config.notAllowed, getCreatureName(target)) then
                doPlayerSendCancel(cid, "You can't swap " .. getCreatureName(target) .. "!")
                doSendMagicEffect(mypos, CONST_ME_POFF)
                return false
            else
                doTeleportThing(cid, targetpos)
                doTeleportThing(target, mypos)
                doChangeSpeed(cid, -getCreatureSpeed(cid)+config.slowSpeed)
                doSendDistanceShoot(mypos, targetpos, CONST_ANI_ENERGYBALL)
                doSendDistanceShoot(targetpos, mypos, CONST_ANI_ENERGYBALL)
                addEvent(effect, 150, cid, var, targetpos, mypos, target)
                addEvent(slowed, config.slowTime * 1000, cid, speed)
                exhaustion.set(cid, config.exhaustStorage, config.exhaustTime)
            end
        end
    else
        doPlayerSendCancel(cid, "You have to wait " .. exhaustion.get(cid, config.exhaustStorage) .. " seconds to swap positions again!")
        return false
    end
    doCombat(cid, combat, var)
    return true
end
this should fix the error in the line 29
 
To don't work with far targets, set the "allowfaruse" tag to "0" like below:

Code:
<rune name="Swapper" id="2299" allowfaruse="0" charges="1" lvl="8" maglv="0" exhaustion="2000" groups="1,2000" icon="21" needtarget="1" blocktype="solid" event="script" value="custom/swapper.lua"/>

Thanks to the original autor of this script and thank you tetra20 for the fix! :D
 
allow far use disabled already

Code:
	<rune name="Swap Rune" id="2306" allowfaruse="0" charges="1" lvl="150" maglv="10" exhaustion="2000" needtarget="0" blocktype="solid" event="script" value="custom/swap.lua">
		<vocation id="3"/>
		<vocation id="7" showInDescription="0"/>
	</rune>

the problem is you swap with the target player if you used the swap rune in a player beside you
 
Back
Top