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

script crashing server if player logs out.

RigBy

Member
Joined
Jun 9, 2015
Messages
44
Solutions
1
Reaction score
6
I was redoing an old script for version 1.3, but if I log off the char, it crashes the server.

Lua:
function getPosDirs(p, dir)
return dir == 1 and {x=p.x-1, y=p.y, z=p.z} or dir == 2 and {x=p.x-1, y=p.y+1, z=p.z} or dir == 3 and {x=p.x, y=p.y+1, z=p.z} or dir == 4 and {x=p.x+1, y=p.y+1, z=p.z} or dir == 5 and {x=p.x+1, y=p.y, z=p.z} or dir == 6 and {x=p.x+1, y=p.y-1, z=p.z} or dir == 7 and {x=p.x, y=p.y-1, z=p.z} or dir == 8 and {x=p.x-1, y=p.y-1, z=p.z}
end

function posIgual(pos1, pos2)
return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z and true or false
end

effect = 10
distance = CONST_ANI_SUDDENDEATH
damage = COMBAT_DEATHDAMAGE

function evilspiritwalk(creature, danomin, danomax, pos, rounds, ultimapos)
    if rounds == 0 then
        return true
    end
    if not isCreature(creature) then
    return true
    end
    posdisp = {}
    for _, dir in pairs({1, 5, 7, 3}) do
        local tile
        tile = Tile(Position(getPosDirs(pos, dir)))
        if tile:isWalkable() and not posIgual(getPosDirs(pos, dir), getThingPos(creature)) and not posIgual(getPosDirs(pos, dir), ultimapos) then
            table.insert(posdisp, getPosDirs(pos, dir))
        end
    end
    
    if #posdisp < 1 then
        return true
    end
        posesc = posdisp[math.random(1, #posdisp)]
        ultimapos = pos
        doSendDistanceShoot(pos, posesc, distance)
        doAreaCombatHealth(creature, damage, posesc, 0, -1000, -2000, effect)
        addEvent(function()
            evilspiritwalk(creature, danomin, danomax, posesc, rounds - 1, ultimapos)
        end, 140)
    end

function onCastSpell(creature, var)
    evilspiritwalk(creature, 10, 20, getThingPos(creature), 20, {x=1, y=1, z=1})
    return true
end
 
obviously this script is wrong, because you are handling user data through addEvent here I have fixed the syntax, but I have not improved or modified anything in the script, I have not tried it either

Lua:
function getPosDirs(p, dir)
return dir == 1 and {x=p.x-1, y=p.y, z=p.z} or dir == 2 and {x=p.x-1, y=p.y+1, z=p.z} or dir == 3 and {x=p.x, y=p.y+1, z=p.z} or dir == 4 and {x=p.x+1, y=p.y+1, z=p.z} or dir == 5 and {x=p.x+1, y=p.y, z=p.z} or dir == 6 and {x=p.x+1, y=p.y-1, z=p.z} or dir == 7 and {x=p.x, y=p.y-1, z=p.z} or dir == 8 and {x=p.x-1, y=p.y-1, z=p.z}
end

local effect = 10
local distance = CONST_ANI_SUDDENDEATH
local damage = COMBAT_DEATHDAMAGE

function evilspiritwalk(cid, danomin, danomax, pos, rounds, ultimapos)
    if rounds == 0 then return end
    local creature = Creature(cid)
    if not creature then return end

    local posdisp = {}
    for _, dir in pairs({1, 5, 7, 3}) do
        local tile = Tile(Position(getPosDirs(pos, dir)))
        if tile and tile:isWalkable() and Position(getPosDirs(pos, dir)) ~= creature:getPosition()) and Position(getPosDirs(pos, dir)) ~= ultimapos then
            table.insert(posdisp, Posiiton(getPosDirs(pos, dir)))
        end
    end
    
    if #posdisp > 0 then
        local posesc = posdisp[math.random(1, #posdisp)]
        ultimapos = pos
        doSendDistanceShoot(pos, posesc, distance)
        doAreaCombatHealth(creature, damage, posesc, 0, -1000, -2000, effect)
        addEvent(evilspiritwalk, 140, cid, danomin, danomax, posesc, rounds - 1, ultimapos)
    end
end

function onCastSpell(creature, var)
    evilspiritwalk(creature:getId(), 10, 20, creature:getPosition(), 20, Position(1, 1, 1))
    return true
end
 
Back
Top