• 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 unify in the same spell

darkmu

Active Member
Joined
Aug 26, 2007
Messages
249
Solutions
1
Reaction score
44
Location
Paraná,Brazil
I wonder if you can help me unify Prince Drazzak's spell.

In this case, he would randomly choose a vocation to give the maximum damage, without the need to create several separate spells for each type of vocation.

TFS 1.3


Lua:
local storage = 674531
local voc = {1, 5}

    arr = {
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    }

local area = createCombatArea(arr)

local combat = Combat()
combat:setArea(area)

function onTargetTile(creature, pos)
    local creatureTable = {}
    local n, i = Tile({x=pos.x, y=pos.y, z=pos.z}).creatures, 1
    if n ~= 0 then
        local v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        while v ~= 0 do
            if isCreature(v) == true then
                table.insert(creatureTable, v)
                if n == #creatureTable then
                    break
                end
            end
            i = i + 1
            v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        end
    end
    if #creatureTable ~= nil and #creatureTable > 0 then
        for r = 1, #creatureTable do
            if creatureTable[r] ~= creature then
                local min = 4000
                local max = 8000
                local player = Player(creatureTable[r])

                if isPlayer(creatureTable[r]) == true and isInArray(voc, player:getVocation():getId()) then
                    doTargetCombatHealth(creature, creatureTable[r], COMBAT_DEATHDAMAGE, -min, -max, CONST_ME_NONE)
                elseif isMonster(creatureTable[r]) == true then
                    doTargetCombatHealth(creature, creatureTable[r], COMBAT_DEATHDAMAGE, -min, -max, CONST_ME_NONE)
                end
            end
        end
    end
    pos:sendMagicEffect(CONST_ME_MORTAREA)
    return true
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

local function delayedCastSpell(cid, var)
    local creature = Creature(cid)
    if not creature then
        return
    end
    creature:say("DIE!", TALKTYPE_ORANGE_1)
    return combat:execute(creature, positionToVariant(creature:getPosition()))
end

function onCastSpell(creature, var)
local value = Game.getStorageValue(storage)
    if(os.time()-value >= 4) then
        creature:say("All SORCERERS must DIE!", TALKTYPE_ORANGE_1)
        safeAddEvent(delayedCastSpell, 4000, creature:getId(), var)
        Game.setStorageValue(storage, os.time())
    end
    return true
end

 
Solution
It is shitty way to do it but should work.

Lua:
local storage = 674531
local vocationStorage = 674532
local vocations = {
    [1] = {name = "SORCERERS", vocationIds = {1, 5},
    [2] = {name = "DRUIDS", vocationIds = {2, 6},
    [3] = {name = "PALADINS", vocationIds = {3, 7},
    [4] = {name = "KNIGHTS", vocationIds = {4, 8},
}

    arr = {
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}...

Azakelis

Advanced OT User
Joined
Feb 17, 2014
Messages
158
Solutions
15
Reaction score
224
It is shitty way to do it but should work.

Lua:
local storage = 674531
local vocationStorage = 674532
local vocations = {
    [1] = {name = "SORCERERS", vocationIds = {1, 5},
    [2] = {name = "DRUIDS", vocationIds = {2, 6},
    [3] = {name = "PALADINS", vocationIds = {3, 7},
    [4] = {name = "KNIGHTS", vocationIds = {4, 8},
}

    arr = {
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
    }

local area = createCombatArea(arr)

local combat = Combat()
combat:setArea(area)

function onTargetTile(creature, pos)
    local creatureTable = {}
    local n, i = Tile({x=pos.x, y=pos.y, z=pos.z}).creatures, 1
    if n ~= 0 then
        local v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        while v ~= 0 do
            if isCreature(v) == true then
                table.insert(creatureTable, v)
                if n == #creatureTable then
                    break
                end
            end
            i = i + 1
            v = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=i}).uid
        end
    end
    if #creatureTable ~= nil and #creatureTable > 0 then
        for r = 1, #creatureTable do
            if creatureTable[r] ~= creature then
                local min = 4000
                local max = 8000
                local player = Player(creatureTable[r])

                local voc = Game.getStorageValue(vocationStorage)
                if isPlayer(creatureTable[r]) == true and isInArray(vocations[voc].vocationIds, player:getVocation():getId()) then
                    doTargetCombatHealth(creature, creatureTable[r], COMBAT_DEATHDAMAGE, -min, -max, CONST_ME_NONE)
                elseif isMonster(creatureTable[r]) == true then
                    doTargetCombatHealth(creature, creatureTable[r], COMBAT_DEATHDAMAGE, -min, -max, CONST_ME_NONE)
                end
            end
        end
    end
    pos:sendMagicEffect(CONST_ME_MORTAREA)
    return true
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

local function delayedCastSpell(cid, var)
    local creature = Creature(cid)
    if not creature then
        return
    end
    creature:say("DIE!", TALKTYPE_ORANGE_1)
    return combat:execute(creature, positionToVariant(creature:getPosition()))
end

function onCastSpell(creature, var)
local value = Game.getStorageValue(storage)
    if(os.time()-value >= 4) then
        local random = math.random(1,#vocations)
        Game.setStorageValue(vocationStorage, random)
        creature:say(string.format("All %s must DIE!", vocations[random].name), TALKTYPE_ORANGE_1)
        safeAddEvent(delayedCastSpell, 4000, creature:getId(), var)
        Game.setStorageValue(storage, os.time())
    end
    return true
end
 
Solution
Top