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

TFS 1.2 Help With Spell

lazarus321

Member
Joined
May 8, 2017
Messages
209
Reaction score
20
I have this spell who pushes 1 target. I would like you to push everyone inside the area, can anyone help?

Lua:
--I have this spell who pushes 1 target. I would like you to push everyone inside the area, can anyone help?

local combat0 = Combat()
combat0:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_POFF)
combat0:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combat0:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat0:setArea(createCombatArea(AREA_CIRCLE3X3))

local dfcombat0_Push = {CONST_ANI_ARROW,0,1,0,2,0,3,0,-1,0,-2,0,-3,-1,-2,-2,-1,-3,0,-2,1,-1,2,1,2,2,1,3,0,2,-1,1,-2,1,-1,1,0,1,1,2,0,-1,0,-1,1,-2,0,-1,-1}

local function RunPart(c,cid,var,dirList,dirEmitPos)
    local player = Player(cid)
    local target = getCreatureTarget(cid)
    local position = getCreaturePosition(cid)
    local fromPosition = getCreaturePosition(target)
    local x = ((fromPosition.x - position.x) < 0 and -1 or ((fromPosition.x - position.x) == 0 and 0 or 1))
    local y = ((fromPosition.y - position.y) < 0 and -1 or ((fromPosition.y - position.y) == 0 and 0 or 1))
    local toPosition = {x = fromPosition.x + x, y = fromPosition.y + y, z = fromPosition.z}

    if (isCreature(cid)) then
        doCombat(cid, c, var)
        
        if (dirList ~= nil) then
            local i = 2;
            
            while (i < #dirList) do
                doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x-dirList,y=dirEmitPos.y-dirList[i+1],z=dirEmitPos.z},dirList[1])
                i = i + 2
                
                if Tile(toPosition):queryAdd(target) == RETURNVALUE_NOERROR then
                    doTeleportThing(target, toPosition, true)
                end  
            end 
        end
    end
end

function onCastSpell(cid, var)
    local startPos = getCreaturePosition(cid)
    
    RunPart(combat0,cid,var,dfcombat0_Push,startPos)
    
    return true
end
 
Last edited by a moderator:
Solution
I have this spell who pushes 1 target. I would like you to push everyone inside the area, can anyone help?

Lua:
--I have this spell who pushes 1 target. I would like you to push everyone inside the area, can anyone help?

local combat0 = Combat()
combat0:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_POFF)
combat0:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combat0:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat0:setArea(createCombatArea(AREA_CIRCLE3X3))

local dfcombat0_Push = {CONST_ANI_ARROW,0,1,0,2,0,3,0,-1,0,-2,0,-3,-1,-2,-2,-1,-3,0,-2,1,-1,2,1,2,2,1,3,0,2,-1,1,-2,1,-1,1,0,1,1,2,0,-1,0,-1,1,-2,0,-1,-1}

local function RunPart(c,cid,var,dirList,dirEmitPos)
    local player = Player(cid)
    local target =...
This code looks so bad. x)
Intentionally obscured to make it difficult to understand perhaps?
It declares variables, then just to mess with you creates a separate function for semingly no reason at all. And then renames all the parameters into a different name. The while iteration is out of whack where it incrments by two, grabbing the value it iterates over to do something. And then check the exact same tile multiple times and teleports you there.

This script only works on the first person it finds? Does it move player just 1sqm? Does it run multiple times?
 
This script works only on target (first person) and move the player 1 sqm. Well i will try make another script from zero like this. thanks.
 
I have this spell who pushes 1 target. I would like you to push everyone inside the area, can anyone help?

Lua:
--I have this spell who pushes 1 target. I would like you to push everyone inside the area, can anyone help?

local combat0 = Combat()
combat0:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_POFF)
combat0:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
combat0:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat0:setArea(createCombatArea(AREA_CIRCLE3X3))

local dfcombat0_Push = {CONST_ANI_ARROW,0,1,0,2,0,3,0,-1,0,-2,0,-3,-1,-2,-2,-1,-3,0,-2,1,-1,2,1,2,2,1,3,0,2,-1,1,-2,1,-1,1,0,1,1,2,0,-1,0,-1,1,-2,0,-1,-1}

local function RunPart(c,cid,var,dirList,dirEmitPos)
    local player = Player(cid)
    local target = getCreatureTarget(cid)
    local position = getCreaturePosition(cid)
    local fromPosition = getCreaturePosition(target)
    local x = ((fromPosition.x - position.x) < 0 and -1 or ((fromPosition.x - position.x) == 0 and 0 or 1))
    local y = ((fromPosition.y - position.y) < 0 and -1 or ((fromPosition.y - position.y) == 0 and 0 or 1))
    local toPosition = {x = fromPosition.x + x, y = fromPosition.y + y, z = fromPosition.z}

    if (isCreature(cid)) then
        doCombat(cid, c, var)
       
        if (dirList ~= nil) then
            local i = 2;
           
            while (i < #dirList) do
                doSendDistanceShoot(dirEmitPos,{x=dirEmitPos.x-dirList,y=dirEmitPos.y-dirList[i+1],z=dirEmitPos.z},dirList[1])
                i = i + 2
               
                if Tile(toPosition):queryAdd(target) == RETURNVALUE_NOERROR then
                    doTeleportThing(target, toPosition, true)
                end 
            end
        end
    end
end

function onCastSpell(cid, var)
    local startPos = getCreaturePosition(cid)
   
    RunPart(combat0,cid,var,dfcombat0_Push,startPos)
   
    return true
end
You can try this out, I tried to use your example but it didn't work at all so I'm not sure exactly what you want. Let me know.

Add these in data/lib/core/position.lua:
Lua:
function Position:isClear(checkCreatures)
    local tile = Tile(self)
    if not tile then
        return false
    end

    if checkCreatures and tile:getCreatureCount() > 0 then
        return false
    end

    if tile:hasFlag(TILESTATE_PROTECTIONZONE) or
    tile:hasFlag(TILESTATE_TELEPORT) or
    tile:hasFlag(TILESTATE_FLOORCHANGE) or
    tile:hasFlag(TILESTATE_BLOCKSOLID) or
    tile:hasFlag(TILESTATE_NOPVPZONE) then
        return false
    end
    return true
end

function Position:getDirectionTo(toPosition)
    local dir = NORTH
    if(self.x > toPosition.x) then
        dir = WEST
        if(self.y > toPosition.y) then
            dir = NORTHWEST
        elseif(self.y < toPosition.y) then
            dir = SOUTHWEST
        end
    elseif(self.x < toPosition.x) then
        dir = EAST
        if(self.y > toPosition.y) then
            dir = NORTHEAST
        elseif(self.y < toPosition.y) then
            dir = SOUTHEAST
        end
    else
        if(self.y > toPosition.y) then
            dir = NORTH
        elseif(self.y < toPosition.y) then
            dir = SOUTH
        end
    end
    return dir
end

And here's the spell script:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_POFF)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_ARROW)
end

function onTargetCreature(creature, target)
    local position = target:getPosition()
    position:getNextPosition(creature:getPosition():getDirectionTo(position), 1)
    if position:isClear(true) then
        addEvent(function(cid, position)
            local target = Creature(cid)
            if target then
                target:teleportTo(position, true)
            end
        end, 100, target.uid, position)
    end
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
 
Solution
You can try this out, I tried to use your example but it didn't work at all so I'm not sure exactly what you want. Let me know.

Add these in data/lib/core/position.lua:
Lua:
function Position:isClear(checkCreatures)
    local tile = Tile(self)
    if not tile then
        return false
    end

    if checkCreatures and tile:getCreatureCount() > 0 then
        return false
    end

    if tile:hasFlag(TILESTATE_PROTECTIONZONE) or
    tile:hasFlag(TILESTATE_TELEPORT) or
    tile:hasFlag(TILESTATE_FLOORCHANGE) or
    tile:hasFlag(TILESTATE_BLOCKSOLID) or
    tile:hasFlag(TILESTATE_NOPVPZONE) then
        return false
    end
    return true
end

function Position:getDirectionTo(toPosition)
    local dir = NORTH
    if(self.x > toPosition.x) then
        dir = WEST
        if(self.y > toPosition.y) then
            dir = NORTHWEST
        elseif(self.y < toPosition.y) then
            dir = SOUTHWEST
        end
    elseif(self.x < toPosition.x) then
        dir = EAST
        if(self.y > toPosition.y) then
            dir = NORTHEAST
        elseif(self.y < toPosition.y) then
            dir = SOUTHEAST
        end
    else
        if(self.y > toPosition.y) then
            dir = NORTH
        elseif(self.y < toPosition.y) then
            dir = SOUTH
        end
    end
    return dir
end

And here's the spell script:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_POFF)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

function onTargetTile(creature, position)
    creature:getPosition():sendDistanceEffect(position, CONST_ANI_ARROW)
end

function onTargetCreature(creature, target)
    local position = target:getPosition()
    position:getNextPosition(creature:getPosition():getDirectionTo(position), 1)
    if position:isClear(true) then
        addEvent(function(cid, position)
            local target = Creature(cid)
            if target then
                target:teleportTo(position, true)
            end
        end, 100, target.uid, position)
    end
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
for me the spell actually work because i look with another client char, the caster client closes because debug but the other client can see the spell working, maybe any idea why is making my client debug when trying to use this spell?

edit: only throws debug when used in normal player if gamemaster uses spell doesnt throw debug.

edit2: i fixed the problem with this What is spell id? (https://otland.net/threads/what-is-spell-id.245613/) spellid should be an aexisting id in order to work properly, i thought spellid was a consecutive, my fall.

thanks in advice!!
 
Last edited:
Back
Top