Isso não vai funcionar do jeito que você está querendo.
- Fórum
- OTServ
- Recursos
- Scripting
- Mods, funções e outros
- [Funções] GetPlayerBy...
info
Grupo: Infante
Registrado: 04/03/11
Posts: 1.6k
Reputação: +393
Char no Tibia: No Have

An?
Eu testei.
Funciono Normalmente e só uma estrutura de repetição e uma verificação boba
Acho que ta faltando table.insert :X
Editado Setembro 16 por caotic
info
Grupo: Visconde
Registrado: 11/08/10
Posts: 477
Reputação: +175
Gênero: Masculino

Tava sem nada para fazer e fiz estas funções.
São quatro funções que verificam o player por alguma coisa x.
Crie um arquivo lua em lib chamado funcby.lua e coloque isto:
function getPlayersByItem(itemid) for _, pid in ipairs(getPlayersOnline()) do if getPlayerItemCount(pid, itemid) > 0 then return pid end end end function getPlayersByVocation(voc) for _, pid in ipairs(getPlayersOnline()) do if getPlayerVocation(pid) == voc then return pid end end end function getPlayersByMoney(money) for _, pid in ipairs(getPlayersOnline()) do if getPlayerMoney(pid) > money then return pid end end end function getPlayersByLevel(level) for _, pid in ipairs(getPlayersOnline()) do if getPlayerLevel(pid) > level then return pid end end end
horrivel, retorna só o 1º player q encaixa na condicao
no caso vc teria q criar 1 array e retornar a array, aí ficaria + util
info
Grupo: Infante
Registrado: 04/03/11
Posts: 1.6k
Reputação: +393
Char no Tibia: No Have

Então ta.
Vo editar e fazer melhor.
Depois eu faço ele por Database ai player off poderia ser verificado.
info
Grupo: Herói
Registrado: 20/05/10
Posts: 3.4k
Reputação: +1.5k
Gênero: Masculino

só colocar os players numa tabela
function getPlayersByVocation(voc)
local players = {}
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerVocation(pid) == tonumber(voc) then
table.insert(players, pid)
end
end
return players
end
cara:
function getPlayersByMoney(money)
x = {}
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerMoney(pid) > tonumber(money) then
table.insert(x, pid)
return x
end
end
end
function getPlayersByLevel(level)
local z = {}
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerLevel(pid) > tonumber(level) then
table.insert(z, pid)
return z
end
end
end
function getPlayersByItem(itemid)
local y = {}
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerItemCount(pid, itemid) > 0 then
table.insert(y, pid)
return y
end
end
end
essas três funções vão retornar no máximo uma tabela com 1 player apenas, pois assim que encontra o primeiro player, ele é inserido na tabela e ao mesmo tempo a função para de ser executada pra retornar um valor.
os returns tem que ficar antes do último end
info
Grupo: Campones
Registrado: 06/02/11
Posts: 73
Reputação: 0
Char no Tibia: não jogo tibia

boa função irei usa no meu client!!!
Interessante, apesar de ser um loop razoável dependendo da quantidade de players.
Por database pode ser feito também, mas ai provavelmente estará trabalhando com numeros bem maiores, terá de redobrar os cuidados para que não fique muito pessada.
info
Grupo: Barão
Registrado: 18/10/10
Posts: 246
Reputação: +89
Char no Tibia: Elite Pamcadaum

function getPlayersByLevel(level)
local z = {}
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerLevel(pid) > tonumber(level) then
table.insert(z, pid)
end
end
return z
end
Nesse caso se um amigo meu for level 50 e eu quiser pegar os que tenham no mínimo level 50, meu amigo não vai estar na lista
Nesse sim:
function getPlayersByLevel(level)
local z = {}
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerLevel(pid) >= tonumber(level) then
table.insert(z, pid)
end
end
return z
end
Não entendi a necessidade de colocar o tonumber alí '-', NUNCA(NUNCA mesmo) ví alguém fazer algo do tipo:
local num = "50" print( tonumber(num) + 2)
Até porque não há necessidade .-.
Editado Janeiro 4 por MaXwEllDeN








info
Grupo: Infante
Registrado: 04/03/11
Posts: 1.6k
Reputação: +393
Char no Tibia: No Have
Tava sem nada para fazer e fiz estas funções.
São quatro funções que verificam o player por alguma coisa x.
Crie um arquivo lua em lib chamado funcby.lua e coloque isto:
function getPlayersByItem(itemid) local y = {} for _, pid in ipairs(getPlayersOnline()) do if getPlayerItemCount(pid, itemid) > 0 then table.insert(y, pid) end end return y end function getPlayersByVocation(voc) local players = {} for _, pid in ipairs(getPlayersOnline()) do if getPlayerVocation(pid) == tonumber(voc) then table.insert(players, pid) end end return players end function getPlayersByMoney(money) x = {} for _, pid in ipairs(getPlayersOnline()) do if getPlayerMoney(pid) > tonumber(money) then table.insert(x, pid) end end return x end function getPlayersByLevel(level) local z = {} for _, pid in ipairs(getPlayersOnline()) do if getPlayerLevel(pid) > tonumber(level) then table.insert(z, pid) end end return z endExemplo:
Editado Setembro 22 por caotic