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

Solved Massive Destroy Field SPELL (not rune) does not remove fields

AdiMit

c(;
Joined
May 2, 2016
Messages
70
Solutions
2
Reaction score
3
Hello dear community, :)

I tried to create a spell working exactly in the same way as the Destroy Field Rune does; however, I wanted to make it massive (=CIRCLE3X3)...

I'm currently using the [8.60] The Forgotten Server 0.3.6 (Crying Damson) V8 by Printer, from the thread: [8.60] The Forgotten Server 0.3.6 (Crying Damson) V8;

The spell is possible to be casted, but it does not remove any fields (and yet the rune works fine).
I get the following error message:
DestroyFieldError.png

Here is the script of the spell:
Lua:
UNREMOVABLE_FIELDS = {1497, 1498, 1499, 1505, 1506, 1507, 1508, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 11094, 11095}

local function doRemoveField(cid, pos)
    local field = getTileItemByType(pos, ITEM_TYPE_MAGICFIELD)
    if(not isInArray(UNREMOVABLE_FIELDS, field.itemid)) then
        doRemoveItem(field.uid)
        doSendMagicEffect(pos, CONST_ME_POFF)
        return true
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_POFF)

local area = createCombatArea(AREA_CIRCLE3X3)
setCombatArea(combat, area)

function onCastSpell(cid, var)
    local pos = variantToPosition(var)
    if(pos.x == CONTAINER_POSITION) then
        pos = getThingPos(cid)
    end

    if(pos.x ~= 0 and pos.y ~= 0) then
        return doRemoveField(cid, pos)
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    doRemoveField(cid, pos)
    doCombat(cid, combat, var)
    return true
end

If you happen to know how to resolve the issue, I would be greatly thankful for your support, :)
Best Regards!
 
Solution
here you go

Code:
UNREMOVABLE_FIELDS = {1497, 1498, 1499, 1505, 1506, 1507, 1508, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 11094, 11095}

local function doRemoveField(cid, pos)
    local field = getTileItemByType(pos, ITEM_TYPE_MAGICFIELD)
    if(not isInArray(UNREMOVABLE_FIELDS, field.itemid)) then
        doRemoveItem(field.uid)
        doSendMagicEffect(pos, CONST_ME_POFF)
        return true
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end

function onCastSpell(cid, var)
local main_pos = getCreaturePosition(cid)
    local positions = {
        [1] = {x = main_pos.x - 1, y = main_pos.y - 1, z = main_pos.z},
        [2] =...
Code:
UNREMOVABLE_FIELDS = {1497, 1498, 1499, 1505, 1506, 1507, 1508, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 11094, 11095}

local function doRemoveField(cid, pos)
    local field = getTileItemByType(pos, ITEM_TYPE_MAGICFIELD)
    if(not isInArray(UNREMOVABLE_FIELDS, field.itemid)) then
        doRemoveItem(field.uid)
        doSendMagicEffect(pos, CONST_ME_POFF)
        return true
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end

function onCastSpell(cid, var)
local main_pos = getCreaturePosition(cid)
    local positions = {
        [1] = {x = main_pos.x - 1, y = main_pos.y - 1, z = main_pos.z},
        [2] = {x = main_pos.x, y = main_pos.y - 1, z = main_pos.z},
        [3] = {x = main_pos.x + 1, y = main_pos.y - 1, z = main_pos.z},
        [4] = {x = main_pos.x - 1, y = main_pos.y, z = main_pos.z},
        [5] = {x = main_pos.x + 1, y = main_pos.y, z = main_pos.z},
        [6] = {x = main_pos.x - 1, y = main_pos.y + 1, z = main_pos.z},
        [7] = {x = main_pos.x, y = main_pos.y + 1, z = main_pos.z},
        [8] = {x = main_pos.x + 1, y = main_pos.y + 1, z = main_pos.z},
        --End square 1 sqm
        [9] = {x = main_pos.x - 2, y = main_pos.y - 2, z = main_pos.z},
        [10] = {x = main_pos.x, y = main_pos.y - 2, z = main_pos.z},
        [11] = {x = main_pos.x + 2, y = main_pos.y - 2, z = main_pos.z},
        [12] = {x = main_pos.x - 2, y = main_pos.y, z = main_pos.z},
        [13] = {x = main_pos.x + 2, y = main_pos.y, z = main_pos.z},
        [14] = {x = main_pos.x - 2, y = main_pos.y + 2, z = main_pos.z},
        [15] = {x = main_pos.x, y = main_pos.y + 2, z = main_pos.z},
        [16] = {x = main_pos.x + 2, y = main_pos.y + 2, z = main_pos.z}
        --End square 2 sqm
    }
    for i = 1, #positions do
        doRemoveField(cid, positions[i])
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end

This should do it.

return doRemoveField(cid, positions)
delete 'return'.

Itutorial was first.

Almost perfect: :)
DestroyFieldError3.png

Works except these 8 tiles at an angle and the one when the character is standing
 
here you go

Code:
UNREMOVABLE_FIELDS = {1497, 1498, 1499, 1505, 1506, 1507, 1508, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 11094, 11095}

local function doRemoveField(cid, pos)
    local field = getTileItemByType(pos, ITEM_TYPE_MAGICFIELD)
    if(not isInArray(UNREMOVABLE_FIELDS, field.itemid)) then
        doRemoveItem(field.uid)
        doSendMagicEffect(pos, CONST_ME_POFF)
        return true
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end

function onCastSpell(cid, var)
local main_pos = getCreaturePosition(cid)
    local positions = {
        [1] = {x = main_pos.x - 1, y = main_pos.y - 1, z = main_pos.z},
        [2] = {x = main_pos.x, y = main_pos.y - 1, z = main_pos.z},
        [3] = {x = main_pos.x + 1, y = main_pos.y - 1, z = main_pos.z},
        [4] = {x = main_pos.x - 1, y = main_pos.y, z = main_pos.z},
        [5] = {x = main_pos.x + 1, y = main_pos.y, z = main_pos.z},
        [6] = {x = main_pos.x - 1, y = main_pos.y + 1, z = main_pos.z},
        [7] = {x = main_pos.x, y = main_pos.y + 1, z = main_pos.z},
        [8] = {x = main_pos.x + 1, y = main_pos.y + 1, z = main_pos.z},
        --End square 1 sqm
        [9] = {x = main_pos.x - 2, y = main_pos.y - 2, z = main_pos.z},
        [10] = {x = main_pos.x - 2, y = main_pos.y - 1, z = main_pos.z},
        [11] = {x = main_pos.x - 2, y = main_pos.y + 1, z = main_pos.z},
        [12] = {x = main_pos.x + 2, y = main_pos.y - 1, z = main_pos.z},
        [13] = {x = main_pos.x + 2, y = main_pos.y + 1, z = main_pos.z},
        [14] = {x = main_pos.x + 1, y = main_pos.y - 2, z = main_pos.z},
        [15] = {x = main_pos.x - 1, y = main_pos.y - 2, z = main_pos.z},
        [16] = {x = main_pos.x + 1, y = main_pos.y + 2, z = main_pos.z},
        [17] = {x = main_pos.x - 1, y = main_pos.y + 2, z = main_pos.z},
        [18] = {x = main_pos.x, y = main_pos.y - 2, z = main_pos.z},
        [19] = {x = main_pos.x + 2, y = main_pos.y - 2, z = main_pos.z},
        [20] = {x = main_pos.x - 2, y = main_pos.y, z = main_pos.z},
        [21] = {x = main_pos.x + 2, y = main_pos.y, z = main_pos.z},
        [22] = {x = main_pos.x - 2, y = main_pos.y + 2, z = main_pos.z},
        [23] = {x = main_pos.x, y = main_pos.y + 2, z = main_pos.z},
        [24] = {x = main_pos.x + 2, y = main_pos.y + 2, z = main_pos.z},
        [25] = main_pos
        --End square 2 sqm
    }
    for i = 1, #positions do
        doRemoveField(cid, positions[i])
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end
 
Solution
here you go

Code:
UNREMOVABLE_FIELDS = {1497, 1498, 1499, 1505, 1506, 1507, 1508, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 11094, 11095}

local function doRemoveField(cid, pos)
    local field = getTileItemByType(pos, ITEM_TYPE_MAGICFIELD)
    if(not isInArray(UNREMOVABLE_FIELDS, field.itemid)) then
        doRemoveItem(field.uid)
        doSendMagicEffect(pos, CONST_ME_POFF)
        return true
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end

function onCastSpell(cid, var)
local main_pos = getCreaturePosition(cid)
    local positions = {
        [1] = {x = main_pos.x - 1, y = main_pos.y - 1, z = main_pos.z},
        [2] = {x = main_pos.x, y = main_pos.y - 1, z = main_pos.z},
        [3] = {x = main_pos.x + 1, y = main_pos.y - 1, z = main_pos.z},
        [4] = {x = main_pos.x - 1, y = main_pos.y, z = main_pos.z},
        [5] = {x = main_pos.x + 1, y = main_pos.y, z = main_pos.z},
        [6] = {x = main_pos.x - 1, y = main_pos.y + 1, z = main_pos.z},
        [7] = {x = main_pos.x, y = main_pos.y + 1, z = main_pos.z},
        [8] = {x = main_pos.x + 1, y = main_pos.y + 1, z = main_pos.z},
        --End square 1 sqm
        [9] = {x = main_pos.x - 2, y = main_pos.y - 2, z = main_pos.z},
        [10] = {x = main_pos.x - 2, y = main_pos.y - 1, z = main_pos.z},
        [11] = {x = main_pos.x - 2, y = main_pos.y + 1, z = main_pos.z},
        [12] = {x = main_pos.x + 2, y = main_pos.y - 1, z = main_pos.z},
        [13] = {x = main_pos.x + 2, y = main_pos.y + 1, z = main_pos.z},
        [14] = {x = main_pos.x + 1, y = main_pos.y - 2, z = main_pos.z},
        [15] = {x = main_pos.x - 1, y = main_pos.y - 2, z = main_pos.z},
        [16] = {x = main_pos.x + 1, y = main_pos.y + 2, z = main_pos.z},
        [17] = {x = main_pos.x - 1, y = main_pos.y + 2, z = main_pos.z},
        [18] = {x = main_pos.x, y = main_pos.y - 2, z = main_pos.z},
        [19] = {x = main_pos.x + 2, y = main_pos.y - 2, z = main_pos.z},
        [20] = {x = main_pos.x - 2, y = main_pos.y, z = main_pos.z},
        [21] = {x = main_pos.x + 2, y = main_pos.y, z = main_pos.z},
        [22] = {x = main_pos.x - 2, y = main_pos.y + 2, z = main_pos.z},
        [23] = {x = main_pos.x, y = main_pos.y + 2, z = main_pos.z},
        [24] = {x = main_pos.x + 2, y = main_pos.y + 2, z = main_pos.z},
        [24] = main_pos
        --End square 2 sqm
    }
    for i = 1, #positions do
        doRemoveField(cid, positions[i])
    end

    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return false
end

It's perfect!
Thank you again! :)
 
oops in the positions table make sure u make the last positions [25] = main_pos

Got it! :)
But I think it was just right as you posted it:
"
  1. [24] = {x = main_pos.x + 2, y = main_pos.y + 2, z = main_pos.z},
  2. [25] = main_pos
  3. --End square 2 sqm
"
 
I edited it to correct version after I commented the mistake.

Always remember if theres a will theres a way.

Glad I could help, it can probably be codded better in the future but for now that will do it for you.
 
I edited it to correct version after I commented the mistake.

Always remember if theres a will theres a way.

Glad I could help, it can probably be codded better in the future but for now that will do it for you.


Oh, I get it :)

Well, the most important thing is that it WORKS thanks to you! :)
 
Back
Top