• 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 0.X Destroy field area spell not working

willdu

Active Member
Joined
Mar 11, 2017
Messages
91
Reaction score
25
Why this destroy field area spell is not working?
It is not destroying the fields (fire,energy...)

Code:
local combat = createCombatObject()
local fieldItems = {1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1500, 1501, 1502, 1503, 1504, 5061, 5062, 5063, 5064, 5065, 5066, 5067}

function onTargetTile(cid, pos)
    local posEx = {x=pos.x, y=pos.y, z=pos.z, stackpos=254}
    item = getThingfromPos(posEx)
    if item.itemid > 0 then
        if isInArray(fieldItems, item.itemid) == 1 then
            doRemoveItem(item.uid,1)
        end
    end
    doSendMagicEffect(pos,2)
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end

local arr = {
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
}
local area = createCombatArea(arr)
setCombatArea(combat, area)

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
 
Solution
1611119015756.png
1611119034804.png
1611119289487.png
As you can see 1 ~= true and isInArray returns true/false.
So to fix your problem:

change this:
Lua:
if isInArray(fieldItems, item.itemid) == 1 then

to this:
Lua:
if isInArray(fieldItems, item.itemid) then
Why this destroy field area spell is not working?
It is not destroying the fields (fire,energy...)

Code:
local combat = createCombatObject()
local fieldItems = {1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1500, 1501, 1502, 1503, 1504, 5061, 5062, 5063, 5064, 5065, 5066, 5067}

function onTargetTile(cid, pos)
    local posEx = {x=pos.x, y=pos.y, z=pos.z, stackpos=254}
    item = getThingfromPos(posEx)
    if item.itemid > 0 then
        if isInArray(fieldItems, item.itemid) == 1 then
            doRemoveItem(item.uid,1)
        end
    end
    doSendMagicEffect(pos,2)
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end

local arr = {
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
}
local area = createCombatArea(arr)
setCombatArea(combat, area)

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
If you're ever unsure of why something is not happening as expected, add prints into your script and find out where it's breaking.

-- added prints and removed the additional onCastSpell that was in the middle of the script.

Tell us what happens.

Lua:
local combat = createCombatObject()
local fieldItems = {1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1500, 1501, 1502, 1503, 1504, 5061, 5062, 5063, 5064, 5065, 5066, 5067}

function onTargetTile(cid, pos)
    local posEx = {x=pos.x, y=pos.y, z=pos.z, stackpos=254}
    print("position("..pos.x..","..pos.y..","..pos.z..")")
    item = getThingfromPos(posEx)
    print("itemid " .. item.itemid)
    if item.itemid > 0 then
        if isInArray(fieldItems, item.itemid) == 1 then
            print("- - Field item found. Attempting to remove..")
            doRemoveItem(item.uid,1)
        end
    end
    doSendMagicEffect(pos,2)
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

local arr = {
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
}
local area = createCombatArea(arr)
setCombatArea(combat, area)

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
 
If you're ever unsure of why something is not happening as expected, add prints into your script and find out where it's breaking.

-- added prints and removed the additional onCastSpell that was in the middle of the script.

Tell us what happens.

Lua:
local combat = createCombatObject()
local fieldItems = {1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1500, 1501, 1502, 1503, 1504, 5061, 5062, 5063, 5064, 5065, 5066, 5067}

function onTargetTile(cid, pos)
    local posEx = {x=pos.x, y=pos.y, z=pos.z, stackpos=254}
    print("position("..pos.x..","..pos.y..","..pos.z..")")
    item = getThingfromPos(posEx)
    print("itemid " .. item.itemid)
    if item.itemid > 0 then
        if isInArray(fieldItems, item.itemid) == 1 then
            print("- - Field item found. Attempting to remove..")
            doRemoveItem(item.uid,1)
        end
    end
    doSendMagicEffect(pos,2)
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

local arr = {
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 3, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
}
local area = createCombatArea(arr)
setCombatArea(combat, area)

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end


Code:
position(1025,1019,7)
itemid 0
position(1026,1019,7)
itemid 0
position(1027,1019,7)
itemid 0
position(1028,1019,7)
itemid 0
position(1024,1020,7)
itemid 0
position(1025,1020,7)
itemid 0
position(1026,1020,7)
itemid 0
position(1027,1020,7)
itemid 0
position(1028,1020,7)
itemid 0
position(1024,1021,7)
itemid 0
position(1025,1021,7)
itemid 0
position(1026,1021,7)
itemid 0
position(1027,1021,7)
itemid 1492
position(1028,1021,7)
itemid 0
position(1024,1022,7)
itemid 0
position(1025,1022,7)
itemid 0
position(1026,1022,7)
itemid 0
position(1027,1022,7)
itemid 0
position(1028,1022,7)
itemid 0
position(1024,1023,7)
itemid 0
position(1025,1023,7)
itemid 0
position(1026,1023,7)
itemid 0
position(1027,1023,7)
itemid 0
position(1028,1023,7)
itemid 0

showing the fire field i throw, but its not removing the field
 
1611119015756.png
1611119034804.png
1611119289487.png
As you can see 1 ~= true and isInArray returns true/false.
So to fix your problem:

change this:
Lua:
if isInArray(fieldItems, item.itemid) == 1 then

to this:
Lua:
if isInArray(fieldItems, item.itemid) then
 
Solution
Back
Top