• 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} Attacking Area

Cadyan

Well-Known Member
Joined
Mar 30, 2008
Messages
845
Reaction score
63
I am getting errors like "attempt to index a boolean value". Any help?
Code:
function onCastSpell(cid, var)
    local PPOS = getPlayerPosition(cid)
    area1 = {x = PPOS.x, y = PPOS.y - 1, z = PPOS.z}
    area2 = {x = PPOS.x + 1, y = PPOS.y, z = PPOS.z}
    local players = {}
    for x = area1.x, area2.x do
        for y = area1.y, area2.y do
            for z = area1.z, area2.z do
                table.insert(players, getTopCreature({x = x, y = y, z = z}).uid)
            end
        end
    end
    area3 = {x = PPOS.x, y = PPOS.y + 1, z = PPOS.z}
    area4 = {x = PPOS.x - 1, y = PPOS.y, z = PPOS.z}
    for x = area3.x, area4.x do
        for y = area3.y, area4.y do
            for z = area3.z, area4.z do
                table.insert(players, getTopCreature({x = x, y = y, z = z}).uid)
            end
        end
    end
  
    if table.maxn(players) >= 1 then
        for i = 1, #players do
            if isPlayer(players[i]) then
                doTargetCombatHealth(0, players[i], COMBAT_PHYSICALDAMAGE, -1, -10, CONST_ME_STUN)
                return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You hit "..getPlayerByName(players[i]).."!')
            else
                doTargetCombatHealth(0, players[i], COMBAT_PHYSICALDAMAGE, -1, -10, CONST_ME_STUN)
                return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You hit a monster!')
            end
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'No targets!')
    end
end
 
Last edited:
Code:
local area = {
{x=-1, y=-1}, {x=0,y=-1}, {x=1, y=-1},
{x=-1, y=0},--[[YOU ARE HERE]]{x=1, y=0},
{x=-1, y=1}, {x=0, y=1}, {x=1, y=1},
}

function onCastSpell(cid, var)
local m_Desc = MESSAGE_INFO_DESCR
local c_Phys = COMBAT_PHYSICALDAMAGE
local c_Stun = CONST_ME_STUN

    local PPOS = getPlayerPosition(cid)
    local c = 0
    for i=1, #area do
        local tmp = {x=0,y=0,z=0}
        tmp.x = PPOS.x+area[i].x
        tmp.y = PPOS.y+area[i].y
        tmp.z = PPOS.z
     
        local targets = getTopCreature(tmp).uid
        if(targets > 0) then
            if isPlayer(targets) then
                return doTargetCombatHealth(0, targets, c_Phys, -1, -10, c_Stun)
            else
                return doTargetCombatHealth(0, targets, c_Phys, -2, -20, c_Stun)
            end
            c = c+1
        end
        if(c==0) then
            doPlayerSendTextMessage(cid, m_Desc, 'No targets!')
        end
    end
end
 
put this
Code:
        if(c==0) then
            doPlayerSendTextMessage(cid, m_Desc, 'No targets!')
        end
outside the loop no need to check this 8 times.
it does only damage to 1 creature because you return, so you cancel the loop. remove return from doTargetCombathHealth
 
Back
Top