[Funções] GetPlayerBy...

caotic
Por caotic
em Mods, funções e outros

caotic

Afinal de contas,sou um mordomo e tanto
avatar
Infante
Infante

INFOS

Grupo: InfanteRegistrado: 04/03/11Posts: 1599Char 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
end

 

 

Exemplo:

 

function onSay(cid, words, param)

for _, i in ipairs(getPlayersByItem(2152)) do
doPlayerSendTextMessage(i, MESSAGE_STATUS_CONSOLE_BLUE, "Oi")
end
return true
end

Oneshot

avatar
Marquês
Marquês

INFOS

Grupo: MarquêsRegistrado: 05/07/09Posts: 1347

Isso não vai funcionar do jeito que você está querendo.

caotic

Afinal de contas,sou um mordomo e tanto
avatar
Infante
Infante

INFOS

Grupo: InfanteRegistrado: 04/03/11Posts: 1599Char 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

Eskylo

boa sorte
avatar
Visconde
Visconde

INFOS

Grupo: ViscondeRegistrado: 11/08/10Posts: 477Gê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

Atenciosamente, Eskylo

 

 

Ironman-icon.png

.

.

caotic

Afinal de contas,sou um mordomo e tanto
avatar
Infante
Infante

INFOS

Grupo: InfanteRegistrado: 04/03/11Posts: 1599Char 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.

Vodkart

Sumus Validus
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 21/05/10Posts: 3406Gê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

bossisg.png

brun123

vash
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 24/09/06Posts: 512

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

5303fg1.png

juanterresalmeida

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 07/02/11Posts: 73Char no Tibia: não jogo tibia

boa função irei usa no meu client!!!

dalvorsn

õ/
avatar
Conde
Conde

INFOS

Grupo: CondeRegistrado: 21/12/11Posts: 750Gênero: Masculino

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.

"A covardia coloca a questão: É seguro? O comodismo coloca a questão: É popular? A etiqueta coloca a questão: é elegante? Mas a consciência coloca a questão, É correto? E chega uma altura em que temos de tomar uma posição que não é segura, não é elegante, não é popular, mas o temos de fazer porque a nossa consciência nos diz que é essa a atitude correta."

(Martin Luther King)

MaXwEllDeN

string.reverse("adiV a arohaD")
avatar
Barão
Barão

INFOS

Grupo: BarãoRegistrado: 18/10/10Posts: 246Char 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 .-.

eq9qh0.png