Ir para conteúdo

Featured Replies

Postado
  • Este é um post popular.

Olá. A algum tempo atrás eu havia feito essa função, mas decidi compartilhar com vocês.

 

Você pode instala-la definitivamente na sua libs ou pode apenas usar em algum script ocasional:

function getCombatAreaPos(centerpos, area) -- by MaTTch
	if(type(area) ~= "table") then
		error("area is not a table")
		return false
	elseif(not centerpos) then
		return false
	end
	local t, center, ret = {}, {}, {}
	for n in ipairs(area) do
		for i = 2, 3 do
			if(table.find(area[n], i)) then
				center = {n, table.find(area[n], i)}
				break
			end
		end
	end
	if(#center == 0) then
		error("area do not have a number center")
		return false
	end
	for line in ipairs(area) do
		for _, value in ipairs(area[line]) do
			t[line] = t[line] and t[line] or {}
			if(value == 1 or value == 3) then
				table.insert(t[line], 1)
			else
				table.insert(t[line], 0)
			end
		end
	end
	for y in pairs(t) do
		for l, x in pairs(t[y]) do
			local ry, rx = y - center[1], l - center[2]
			if(#area == 1) then
				ry = 0
			end
			if(x == 1) then
				table.insert(ret, {x=centerpos.x+(rx),y=centerpos.y+(ry),z=centerpos.z})
			end
		end
	end
	return ret
end

- Como funciona?

A função retorna uma tabela com as posições da area de combat.

 

Exemplo:

function onSay(cid, words, param)
    local area = { -- Area
        {1,0,0,0,0,0,1},
        {0,1,0,0,0,1,0},
        {0,0,1,0,1,0,0},
        {0,0,0,2,0,0,0}, -- 2 ou 3 é o numero do centro
        {0,0,1,0,1,0,0},
        {0,1,0,0,0,1,0},
        {1,0,0,0,0,0,1}
    }
    
    for _, pos in pairs(getCombatAreaPos(getThingPos(cid), area)) do -- loop com todas as tabelas
        doSendMagicEffect(pos, 10) -- efeito em todas as posicoes da tabela
    end
    return true
end

Espero que tenham entendido...

 

Créditos:

MaTTch (eu)

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.7k

Informação Importante

Confirmação de Termo