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

Bomberman, problem with: "local a = getPlayersInRange({x=864, y=1335, z=7}, 30, 34) if #a == 1 then"

ligus

New Member
Joined
Apr 26, 2010
Messages
253
Reaction score
0
Hey, this is bomberman.lua talkaction:
Code:
function getPlayersInRange(pos, rX, rY)
    local ret = {}
    for x = -rX, rX do
        for y = -rY, rY do
            local v = getTopCreature({x = pos.x+x, y = pos.y+y, z = pos.z})
            if v.type == 1 then
                table.insert(ret, v.uid)
            end
        end
    end
    return ret
end

function isPositionInArray(haystack, needle)
    for i = 1, #haystack do
        if haystack[i].x == needle.x and haystack[i].y == needle.y and haystack[i].z == needle.z then
            return true
        end
    end
    return false
end

local t = {
    from = {x=864, y=1335, z=7},
    to = {x=898, y=1365, z=7},
    storage = {
        placed = 13001,
        max = 13002,
        radius = 13003
    },
    delay = 3000,
    bombID = 1285,
    effect = CONST_ME_FIREAREA,
    blockID = 9468,
    text = "BOOM!",
    temple = {x=919, y=1351, z=7},
    exceptions = {
        {x=864, y=1335, z=7},
        {x=865, y=1335, z=7},
        {x=864, y=1336, z=7},
      
        {x=864, y=1364, z=7},
        {x=864, y=1365, z=7},
        {x=865, y=1365, z=7},
      
        {x=897, y=1365, z=7},
        {x=898, y=1365, z=7},
        {x=898, y=1364, z=7},
      
        {x=897, y=1335, z=7},
        {x=898, y=1335, z=7},
        {x=898, y=1336, z=7}
    }
}
function reset()
    local dummy = doCreateItem(1285, 1, {x=864, y=1335, z=7})
    for x = t.from.x, t.to.x do
        for y = t.from.y, t.to.y do
            local pos = {x=x,y=y,z=t.from.z}
            local i1, i2, i3  = getTileItemById(pos, 2751).uid, getTileItemById(pos, 7692).uid, getTileItemById(pos, 7688).uid
            if i1 > 0 then
                doRemoveItem(i1)
            end
            if i2 > 0 then
                doRemoveItem(i2)
            end
            if i3 > 0 then
                doRemoveItem(i3)
            end
            if queryTileAddThing(dummy, pos, 4) == RETURNVALUE_NOERROR and not isPositionInArray(t.exceptions, pos) then
                doCreateItem(t.blockID, 1, pos)
            end
        end
    end
    doRemoveItem(dummy)
end

local function boom(pos, cid)
    local v = getTileItemById(pos, t.bombID).uid
    if isPlayer(cid) and isInRange(getThingPos(cid), t.from, t.to) then
        setPlayerStorageValue(cid, t.storage.placed, getPlayerStorageValue(cid, t.storage.placed) - 1)
        doCreatureSay(cid, t.text, TALKTYPE_ORANGE_2, false, nil, pos)
        doSendMagicEffect(pos, t.effect)
        local c = getTopCreature(pos).uid
        if isPlayer(c) and isInRange(getThingPos(c), t.from, t.to) then
            doSendMagicEffect(pos, CONST_ME_GIFT_WRAPS)
            doTeleportThing(c, t.temple)
            doSendMagicEffect(t.temple, CONST_ME_MORTAREA)
            local n1, n2 = getPlayerName(c), getPlayerName(cid)
          
            for _, pid in ipairs(getPlayersOnline()) do
                if(isInRange(getPlayerPosition(pid), {x = 914, y = 1340, z = 7}, {x = 924, y = 1356, z = 7})) then
                    doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, n1==n2 and n1 .. " killed " .. (getPlayerSex(c) == 0 and "her" or "him") .. "self!" or n1 .. " was killed by " .. n2 .. "!")
                end
            end
          

            local a = getPlayersInRange({x=864, y=1335, z=7}, 30, 34)
            if #a == 1 then
          
            for _, pid in ipairs(getPlayersOnline()) do
                if(isInRange(getPlayerPosition(pid), {x = 914, y = 1340, z = 7}, {x = 924, y = 1356, z = 7})) then
                    doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, getPlayerName(a[1]) .. " has won the match!")
                end
            end
                doPlayerAddItem(cid, 8976, 1)
                doTeleportThing(a[1], t.temple)
                doSendMagicEffect(t.temple, CONST_ME_FIREWORK_RED)
                reset()
                reset()
            end
        else
            local b = getTileItemById(pos, t.blockID).uid
            if b > 0 then
                doSendMagicEffect(pos, CONST_ME_BLOCKHIT)
                doRemoveItem(b)
                local r = math.random(10)
                if r < 4 then
                    doCreateItem(r==1 and 2751 or r==2 and 692 or r==3 and 7688, 1, _pos)
                end
            end
        end
        local N, E, W, S, l = 1, 1, 1, 1, getPlayerStorageValue(cid, t.storage.radius)
        function loopDir(dir)
            local _pos = {x=pos.x+(dir=="E" and E or dir=="W" and -W or 0), y=pos.y+(dir=="N" and -N or dir=="S" and S or 0), z=pos.z}
            if queryTileAddThing(v, _pos, 4) == RETURNVALUE_NOERROR or getTileItemById(_pos, t.blockID).uid > 0 then
                doSendMagicEffect(_pos, t.effect)
                local c = getTopCreature(_pos).uid
                if isPlayer(c) and isInRange(getThingPos(c), t.from, t.to) then
                    doSendMagicEffect(_pos, CONST_ME_GIFT_WRAPS)
                    doTeleportThing(c, t.temple)
                    doSendMagicEffect(t.temple, CONST_ME_MORTAREA)
                    local n1, n2 = getPlayerName(c), getPlayerName(cid)          
                  
                    for _, pid in ipairs(getPlayersOnline()) do
                        if(isInRange(getPlayerPosition(pid), {x = 914, y = 1340, z = 7}, {x = 924, y = 1356, z = 7})) then
                            doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, n1==n2 and n1 .. " killed " .. (getPlayerSex(c) == 0 and "her" or "him") .. "self!" or n1 .. " was killed by " .. n2 .. "!")
                        end
                    end
                  
                    local a = getPlayersInRange({x=864, y=1335, z=7}, 30, 34)
                    if #a == 1 then
                  
                    for _, pid in ipairs(getPlayersOnline()) do
                        if(isInRange(getPlayerPosition(pid), {x = 914, y = 1340, z = 7}, {x = 924, y = 1356, z = 7})) then
                            doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, getPlayerName(a[1]) .. " has won the match!")
                        end
                    end
                        doPlayerAddItem(cid, 8976, 1)
                        doTeleportThing(a[1], t.temple)
                        doSendMagicEffect(t.temple, CONST_ME_FIREWORK_RED)
                        reset()
                        reset()
                        return "endgame"
                    end
                else
                    local b = getTileItemById(_pos, t.blockID).uid
                    if b > 0 then
                        doSendMagicEffect(_pos, CONST_ME_BLOCKHIT)
                        doRemoveItem(b)
                        local r = math.random(10)
                        if r < 4 then
                            doCreateItem(r==1 and 2751 or r==2 and 7692 or r==3 and 7688, 1, _pos)
                        end
                        return false
                    end
                end
            elseif queryTileAddThing(v, _pos, 4) == 3 then
                return false
            end
            return true
        end
        while N <= l do
            local q = loopDir("N")
            if q == "endgame" then
                return doRemoveItem(v, 1)
            elseif not q then
                break
            else
                N = N + 1
            end
        end
        while E <= l do
            local q = loopDir("E")
            if q == "endgame" then
                return doRemoveItem(v, 1)
            elseif not q then
                break
            else
                E = E + 1
            end
        end
        while W <= l do
            local q = loopDir("W")
            if q == "endgame" then
                return doRemoveItem(v, 1)
            elseif not q then
                break
            else
                W = W + 1
            end
        end
        while S <= l do
            local q = loopDir("S")
            if q == "endgame" then
                return doRemoveItem(v, 1)
            elseif not q then
                break
            else
                S = S + 1
            end
        end
    end
    doRemoveItem(v, 1)
end
function onSay(cid, words, param, channel)
    if isInRange(getThingPos(cid), t.from, t.to) then
        setPlayerStorageValue(cid, t.storage.placed, math.max(getPlayerStorageValue(cid, t.storage.placed), 0))
        setPlayerStorageValue(cid, t.storage.max, math.max(getPlayerStorageValue(cid, t.storage.max), 1))
        setPlayerStorageValue(cid, t.storage.radius, math.max(getPlayerStorageValue(cid, t.storage.radius), 1))
        if getPlayerStorageValue(cid, t.storage.placed) < getPlayerStorageValue(cid, t.storage.max) then
            doCreateItem(t.bombID, 1, getThingPos(cid))
            addEvent(boom, t.delay, getThingPos(cid), cid)
            setPlayerStorageValue(cid, t.storage.placed, getPlayerStorageValue(cid, t.storage.placed) + 1)
        end
        return true
    end
end

When game ends then these line don't work:
local a = getPlayersInRange({x=864, y=1335, z=7}, 30, 34)
if #a == 1 then

One player is teleported to temple but second is still in game arena, why?
 
Use getSpectators insted, getTopCreature does what it says returns a table of all players on top, not the stacked players.
 
Still does not work

local a = getSpectators({x=864, y=1335, z=7}, 30, 34)
if #a == 1 then
Code:
[20:38:52.267] [Error - TalkAction Interface]
[20:38:52.269] In a timer event called from:
[20:38:52.271] data/talkactions/scripts/bomb.lua:onSay
[20:38:52.273] Description:
[20:38:52.274] data/talkactions/scripts/bomb.lua:142: attempt to get length of local 'a' (a nil value)
[20:38:52.276] stack traceback:
[20:38:52.277]  data/talkactions/scripts/bomb.lua:142: in function 'loopDir'
[20:38:52.279]  data/talkactions/scripts/bomb.lua:194: in function <data/talkactions/scripts/bomb.lua:78>


local a = getTopCreature({x=864, y=1335, z=7}, 30, 34)
if #a == 1 then
Code:
[20:43:52.288] [Error - TalkAction Interface]
[20:43:52.290] In a timer event called from:
[20:43:52.292] data/talkactions/scripts/bomb.lua:eek:nSay
[20:43:52.294] Description:
[20:43:52.295] attempt to index a number value
[20:43:52.296] stack traceback:
[20:43:52.297]  [C]: in function 'getTopCreature'
[20:43:52.298]  data/talkactions/scripts/bomb.lua:141: in function 'loopDir'
[20:43:52.300]  data/talkactions/scripts/bomb.lua:184: in function <data/talkactions/scripts/bomb.lua:78>
 
Back
Top