Isso não vai funcionar do jeito que você está querendo.
- Forums
- OTServ
- Recursos
- Scripting
- Mods, funções e outros
- [Funções] GetPlayerBy...
info
Group: Infante
Joined: 04/03/11
Posts: 1.6k
Reputation: +393
Tibia Character: 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
Edited Setembro 16 by caotic
info
Group: Visconde
Joined: 11/08/10
Posts: 477
Reputation: +175
Gender: 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
Group: Infante
Joined: 04/03/11
Posts: 1.6k
Reputation: +393
Tibia Character: No Have

Então ta.
Vo editar e fazer melhor.
Depois eu faço ele por Database ai player off poderia ser verificado.
info
Group: Herói
Joined: 20/05/10
Posts: 3.4k
Reputation: +1.5k
Gender: 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
Group: Campones
Joined: 06/02/11
Posts: 73
Reputation: 0
Tibia Character: 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
Group: Barão
Joined: 18/10/10
Posts: 246
Reputation: +89
Tibia Character: 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 .-.
Edited Janeiro 4 by MaXwEllDeN








info
Group: Infante
Joined: 04/03/11
Posts: 1.6k
Reputation: +393
Tibia Character: 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:
Edited Setembro 22 by caotic