Ir para conteúdo

Featured Replies

Postado

Bom galera, direto ao assunto, segui um tópico no OTLand(aqui) para adicionar o evento Zombie Event no meu server.

 

Tudo certo até os players entrarem no mapa do zombie, mas ai começa uns bugs no console:

 

Citar

 

[22:11:19.907] [Error - GlobalEvent Interface]

[22:11:19.910] data/globalevents/scripts/zombie/onthink.lua:onThink
[22:11:19.911] Description:
[22:11:19.912] data/lib/zombie_event.lua:123: attempt to index local 'pir' (a number value)
[22:11:19.913] stack traceback:
[22:11:19.913]  data/lib/zombie_event.lua:123: in function 'spawnNewZombie'
[22:11:19.914]  data/globalevents/scripts/zombie/onthink.lua:6: in function <data/globalevents/scripts/zombie/onthink.lua:1>
[22:11:19.915] [Error - GlobalEvents::think] Couldn't execute event: ZombieGlobalThink

 

Ai vai o meu lib/zombie_event.lua

Spoiler
-- CONFIG
ZE_DEFAULT_NUMBER_OF_PLAYERS = 5
ZE_ACCESS_TO_IGNORE_ARENA = 3
-- POSITIONS
ZE_blockEnterItemPosition = {x= 10166, y=10045, z=5}
ZE_enterPosition = {x = 9930, y = 10105, z = 7}
ZE_kickPosition = {x=10160, y=10054, z=7}
ZE_spawnFromPosition = {x = 9896, y = 10074, z = 7}
ZE_spawnToPosition = {x = 9970, y = 10142, z = 7}
-- ITEM IDS
ZE_blockEnterItemID = 1591
-- STORAGES
-- - player
ZE_isOnZombieArea = 34370
-- - global
ZE_STATUS = 34370 -- =< 0 - off, 1 - waiting for players, 2 - is running
ZE_PLAYERS_NUMBER = 34371
ZE_ZOMBIES_TO_SPAWN = 34372
ZE_ZOMBIES_SPAWNED = 34373
 
-- FUNCTION
 
function setZombiesEventPlayersLimit(value)
doSetStorage(ZE_PLAYERS_NUMBER, value)
end
 
function getZombiesEventPlayersLimit()
return getStorage(ZE_PLAYERS_NUMBER)
end
 
function addPlayerToZombiesArea(cid)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, ZE_enterPosition, true)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
if(getPlayerAccess(cid) < ZE_ACCESS_TO_IGNORE_ARENA) then
setPlayerZombiesEventStatus(cid, os.time())
end
end
 
function kickPlayerFromZombiesArea(cid)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, ZE_kickPosition, true)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
setPlayerZombiesEventStatus(cid, 0)
end
 
function getPlayerZombiesEventStatus(cid)
return getCreatureStorage(cid, ZE_isOnZombieArea)
end
 
function setPlayerZombiesEventStatus(cid, value)
doCreatureSetStorage(cid, ZE_isOnZombieArea, value)
end
 
function getZombiesEventPlayers()
local players = {}
for i, cid in pairs(getPlayersOnline()) do
if(getPlayerZombiesEventStatus(cid) > 0) then
table.insert(players, cid)
end
end
return players
end
 
function getZombiesCount()
return getStorage(ZE_ZOMBIES_SPAWNED)
end
 
function addZombiesCount()
doSetStorage(ZE_ZOMBIES_SPAWNED, getStorage(ZE_ZOMBIES_SPAWNED)+1)
end
 
function resetZombiesCount()
doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
end
 
function getZombiesToSpawnCount()
return getStorage(ZE_ZOMBIES_TO_SPAWN)
end
 
function setZombiesToSpawnCount(count)
doSetStorage(ZE_ZOMBIES_TO_SPAWN, count)
end
 
function addZombiesEventBlockEnterPosition()
if(getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID).uid == 0) then
doCreateItem(ZE_blockEnterItemID, 1, ZE_blockEnterItemPosition)
end
end
 
function removeZombiesEventBlockEnterPosition()
local item = getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID)
if(item.uid ~= 0) then
doRemoveItem(item.uid)
end
end
 
function spawnNewZombie()
local posx = {}
local posy = {}
local posz = {}
local pir = {}
for i=1, 5 do
local posx_tmp = math.random(ZE_spawnFromPosition.x ,ZE_spawnToPosition.x)
local posy_tmp = math.random(ZE_spawnFromPosition.y ,ZE_spawnToPosition.y)
local posz_tmp = math.random(ZE_spawnFromPosition.z ,ZE_spawnToPosition.z)
local pir_tmp = 0
local spec = getSpectators({x=posx_tmp, y=posy_tmp, z=posz_tmp}, 3, 3, false)
if(spec and #spec > 0) then
for z, pid in pairs(spec) do
if(isPlayer(pid)) then
pir_tmp = pir_tmp + 1
end
end
end
posx = posx_tmp
posy = posy_tmp
posz = posz_tmp
pir = pir_tmp
end
local lowest_i = 1
for i=2, 5 do
if(pir < pir[lowest_i]) then
lowest_i = i
end
end
local ret = (type(doCreateMonster("Zombie Event", {x=posx[lowest_i], y=posy[lowest_i], z=posz[lowest_i]}, false)) == 'number')
if(ret) then
addZombiesCount()
end
return ret
end
 
globalevents/scripts/zombie/onthink.lua
Spoiler
function onThink(interval, lastExecution, thinkInterval)
if(getStorage(ZE_STATUS) == 2) then
setZombiesToSpawnCount(getZombiesToSpawnCount()+1)
local players = getZombiesEventPlayers()
for i=1, getZombiesToSpawnCount() * 2 do
if(getZombiesToSpawnCount() > 0 and spawnNewZombie()) then
setZombiesToSpawnCount(getZombiesToSpawnCount()-1)
end
end
end
return true
end

 

 
POR FAVOR, ME AJUDEM!! Quero muito esse evento, e nenhum outro na internet funcionou comigo... NENHUM!

Resolvido por Sekk

Ir para solução
Postado
Spoiler

function setZombiesEventPlayersLimit(value)
    doSetStorage(ZE_PLAYERS_NUMBER, value)
end

function getZombiesEventPlayersLimit()
    return getStorage(ZE_PLAYERS_NUMBER)
end

function addPlayerToZombiesArea(cid)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    doTeleportThing(cid, ZE_enterPosition, true)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    if(getPlayerAccess(cid) < ZE_ACCESS_TO_IGNORE_ARENA) then
        setPlayerZombiesEventStatus(cid, os.time())
    end
end

function kickPlayerFromZombiesArea(cid)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    doTeleportThing(cid, ZE_kickPosition, true)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    setPlayerZombiesEventStatus(cid, 0)
end

function getPlayerZombiesEventStatus(cid)
    return getCreatureStorage(cid, ZE_isOnZombieArea)
end

function setPlayerZombiesEventStatus(cid, value)
    doCreatureSetStorage(cid, ZE_isOnZombieArea, value)
end

function getZombiesEventPlayers()
    local players = {}
    for i, cid in pairs(getPlayersOnline()) do
        if(getPlayerZombiesEventStatus(cid) > 0) then
            table.insert(players, cid)
        end
    end
return players
end

function getZombiesCount()
    return getStorage(ZE_ZOMBIES_SPAWNED)
end

function addZombiesCount()
    doSetStorage(ZE_ZOMBIES_SPAWNED, getStorage(ZE_ZOMBIES_SPAWNED)+1)
end

function resetZombiesCount()
    doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
end

function getZombiesToSpawnCount()
    return getStorage(ZE_ZOMBIES_TO_SPAWN)
end

function setZombiesToSpawnCount(count)
    doSetStorage(ZE_ZOMBIES_TO_SPAWN, count)
end

function addZombiesEventBlockEnterPosition()
    if(getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID).uid == 0) then
        doCreateItem(ZE_blockEnterItemID, 1, ZE_blockEnterItemPosition)
    end
end

function removeZombiesEventBlockEnterPosition()
    local item = getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID)
    if(item.uid ~= 0) then
        doRemoveItem(item.uid)
    end
end

function spawnNewZombie()
    local posx = {}
    local posy = {}
    local posz = {}
    local pir = {}
    for i=1, 5 do
        local posx_tmp = math.random(ZE_spawnFromPosition.x ,ZE_spawnToPosition.x)
        local posy_tmp = math.random(ZE_spawnFromPosition.y ,ZE_spawnToPosition.y)
        local posz_tmp = math.random(ZE_spawnFromPosition.z ,ZE_spawnToPosition.z)
        local pir_tmp = 0
        local spec = getSpectators({x=posx_tmp, y=posy_tmp, z=posz_tmp}, 3, 3, false)
        if(spec and #spec > 0) then
            for z, pid in pairs(spec) do
                if(isPlayer(pid)) then
                    pir_tmp = pir_tmp + 1
                end
            end
        end
        posx[i] = posx_tmp
        posy[i] = posy_tmp
        posz[i] = posz_tmp
        pir[i] = pir_tmp
    end
    local lowest_i = 1
    for i=2, 5 do
        if(pir[i] < pir[lowest_i]) then
            lowest_i = i
        end
    end
    local ret = (type(doCreateMonster('Zombie Event', {x=posx[lowest_i], y=posy[lowest_i], z=posz[lowest_i], stackpos = 253})) == 'number')
    if(ret) then
        addZombiesCount()
    end
    return ret
end

 

 

Postado
  • Autor
  • Solução

Resolvido!

 

onattack.lua

Spoiler

function loseOnZombieArena(cid)
    kickPlayerFromZombiesArea(cid)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Voce perdeu.")
    local players = getZombiesEventPlayers()
    if(#players <= 1) then
        local winner = players[1]
        if(winner) then
            doPlayerAddItem(winner, 2157, 5, true)
            doPlayerAddItem(winner, 6119, 1, true)
            doPlayerSendTextMessage(winner, MESSAGE_STATUS_CONSOLE_BLUE, "Voce ganhou o Zombie Event.")
            doBroadcastMessage("Depois de " .. os.time() - getPlayerZombiesEventStatus(winner) .. " segundos, o jogador " .. getCreatureName(winner) .. " ganhou o Zombie Arena Event com " .. getStorage(ZE_ZOMBIES_SPAWNED) .. " zumbis!")
            kickPlayerFromZombiesArea(winner)
        else
            doBroadcastMessage("O evento acabou, infelizmente ninguém ganhou!")
        end
        doSetStorage(ZE_STATUS, 0)
        doSetStorage(ZE_PLAYERS_NUMBER, ZE_DEFAULT_NUMBER_OF_PLAYERS)
        doSetStorage(ZE_ZOMBIES_TO_SPAWN, 0)
        doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
        local width = (math.max(ZE_spawnFromPosition.x, ZE_spawnToPosition.x) - math.min(ZE_spawnFromPosition.x, ZE_spawnToPosition.x)) / 2 + 1
        local height = (math.max(ZE_spawnFromPosition.y, ZE_spawnToPosition.y) - math.min(ZE_spawnFromPosition.y, ZE_spawnToPosition.y)) / 2 + 1
        local centerPos = {x=math.min(ZE_spawnFromPosition.x, ZE_spawnToPosition.x)+width,y=math.min(ZE_spawnFromPosition.y, ZE_spawnToPosition.y)+height,z=ZE_spawnFromPosition.z}
        for z = math.min(ZE_spawnFromPosition.z, ZE_spawnToPosition.z), math.max(ZE_spawnFromPosition.z, ZE_spawnToPosition.z) do
            centerPos.z = z
            for i, uid in pairs(getSpectators(centerPos, width, height, false)) do
                if(isMonster(uid)) then
                    doRemoveCreature(uid)
                end
            end
        end
    end
end
function onStatsChange(target, cid, changetype, combat, value)
    if((cid and isMonster(cid) and getCreatureName(cid) == "Zombie Event") or (isInRange(getThingPosition(target), ZE_spawnFromPosition, ZE_spawnToPosition) and changetype == STATSCHANGE_HEALTHLOSS and math.abs(value) >= getCreatureHealth(target))) then
        doCreatureAddHealth(target, getCreatureMaxHealth(target))
        loseOnZombieArena(target)
        return false
    end
    return true
end

 

lib zombievent.lua

Spoiler

-- CONFIG
ZE_DEFAULT_NUMBER_OF_PLAYERS = 5
ZE_ACCESS_TO_IGNORE_ARENA = 3
-- POSITIONS
ZE_blockEnterItemPosition = {x= 873, y=997, z=7}
ZE_enterPosition = {x = 1638, y = 1530, z = 7}
ZE_kickPosition = {x=874, y=994, z=7}
ZE_spawnFromPosition = {x = 1617, y = 1514, z = 7}
ZE_spawnToPosition = {x = 1671, y = 1565, z = 7}
-- ITEM IDS
ZE_blockEnterItemID = 2700
-- STORAGES
-- - player
ZE_isOnZombieArea = 34370
-- - global
ZE_STATUS = 34370 -- =< 0 - off, 1 - waiting for players, 2 - is running
ZE_PLAYERS_NUMBER = 34371
ZE_ZOMBIES_TO_SPAWN = 34372
ZE_ZOMBIES_SPAWNED = 34373

-- FUNCTION

function setZombiesEventPlayersLimit(value)
doSetStorage(ZE_PLAYERS_NUMBER, value)
end

function getZombiesEventPlayersLimit()
return getStorage(ZE_PLAYERS_NUMBER)
end

function addPlayerToZombiesArea(cid)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, ZE_enterPosition, true)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
if(getPlayerAccess(cid) < ZE_ACCESS_TO_IGNORE_ARENA) then
setPlayerZombiesEventStatus(cid, os.time())
end
end

function kickPlayerFromZombiesArea(cid)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, ZE_kickPosition, true)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
setPlayerZombiesEventStatus(cid, 0)
end

function getPlayerZombiesEventStatus(cid)
return getCreatureStorage(cid, ZE_isOnZombieArea)
end

function setPlayerZombiesEventStatus(cid, value)
doCreatureSetStorage(cid, ZE_isOnZombieArea, value)
end

function getZombiesEventPlayers()
local players = {}
for i, cid in pairs(getPlayersOnline()) do
if(getPlayerZombiesEventStatus(cid) > 0) then
table.insert(players, cid)
end
end
return players
end

function getZombiesCount()
return getStorage(ZE_ZOMBIES_SPAWNED)
end

function addZombiesCount()
doSetStorage(ZE_ZOMBIES_SPAWNED, getStorage(ZE_ZOMBIES_SPAWNED)+1)
end

function resetZombiesCount()
doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
end

function getZombiesToSpawnCount()
return getStorage(ZE_ZOMBIES_TO_SPAWN)
end

function setZombiesToSpawnCount(count)
doSetStorage(ZE_ZOMBIES_TO_SPAWN, count)
end

function addZombiesEventBlockEnterPosition()
if(getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID).uid == 0) then
doCreateItem(ZE_blockEnterItemID, 1, ZE_blockEnterItemPosition)
end
end

function removeZombiesEventBlockEnterPosition()
local item = getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID)
if(item.uid ~= 0) then
doRemoveItem(item.uid)
end
end

function spawnNewZombie()
    local posx = {}
    local posy = {}
    local posz = {}
    local pir = {}
    for i=1, 5 do
        local posx_tmp = math.random(ZE_spawnFromPosition.x ,ZE_spawnToPosition.x)
        local posy_tmp = math.random(ZE_spawnFromPosition.y ,ZE_spawnToPosition.y)
        local posz_tmp = math.random(ZE_spawnFromPosition.z ,ZE_spawnToPosition.z)
        local pir_tmp = 0
        local spec = getSpectators({x=posx_tmp, y=posy_tmp, z=posz_tmp}, 3, 3, false)
        if(spec and #spec > 0) then
            for z, pid in pairs(spec) do
                if(isPlayer(pid)) then
                    pir_tmp = pir_tmp + 1
                end
            end
        end
        posx = posx_tmp
        posy = posy_tmp
        posz = posz_tmp
        pir = pir_tmp
    end
    local lowest_i = 1
    for i=2, 5 do
        if(pir < pir[lowest_i]) then
            lowest_i = i
        end
    end
    local ret = (type(doCreateMonster("Zombie Event", {x=posx[lowest_i], y=posy[lowest_i], z=posz[lowest_i]}, false, false, false)) == 'number')
    if(ret) then
        addZombiesCount()
    end
    return ret
end

 

032-position.lua

Spoiler

function isInRange(position, fromPosition, toPosition)
    return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

function getDistanceBetween(fromPosition, toPosition)
    local x, y = math.abs(fromPosition.x - toPosition.x), math.abs(fromPosition.y - toPosition.y)
    local diff = math.max(x, y)
    if(fromPosition.z ~= toPosition.z) then
        diff = diff + 9 + 6
    end

    return diff
end

function getDirectionTo(pos1, pos2)
    local dir = NORTH
    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end
    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end
    else
        if(pos1.y > pos2.y) then
            dir = NORTH
        elseif(pos1.y < pos2.y) then
            dir = SOUTH
        end
    end

    return dir
end

function getCreatureLookPosition(cid)
    return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid))
end

function getPositionByDirection(position, direction, size)
    local n = size or 1
    if(direction == NORTH) then
        position.y = position.y - n
    elseif(direction == SOUTH) then
        position.y = position.y + n
    elseif(direction == WEST) then
        position.x = position.x - n
    elseif(direction == EAST) then
        position.x = position.x + n
    elseif(direction == NORTHWEST) then
        position.y = position.y - n
        position.x = position.x - n
    elseif(direction == NORTHEAST) then
        position.y = position.y - n
        position.x = position.x + n
    elseif(direction == SOUTHWEST) then
        position.y = position.y + n
        position.x = position.x - n
    elseif(direction == SOUTHEAST) then
        position.y = position.y + n
        position.x = position.x + n
    end

    return position
end

function doComparePositions(position, positionEx)
    return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
end

function getArea(position, x, y)
    local t = {}
    for i = (position.x - x), (position.x + x) do
        for j = (position.y - y), (position.y + y) do
            table.insert(t, {x = i, y = j, z = position.z})
        end
    end

    return t
end

 

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo