Jump to content

PLAYER PAIS AJUDA


Recommended Posts

Posted (edited)

Olá pessoal, bom estive pensando, queria saber como posso fazer para obter a localização dos jogadores, vou usar o exemplo do GetPlayerCount, como posso obter os jogadores de outro pais, qual função devo usar, não sei se é falta de leitura minha, mas dei uma procurada na wiki algo relacionado com os paises dos jogadores e até mesmo IP, e não encontrei nada.

Exemplo:

Ao digitar /players envie:

Jogadores Brasileiros: 3

Jogadores Gringos: 2 -- Aqui é todos os paises fora o brasil .

Total: 5

Usei a função GetPlayerCount e fiz este exemplo totalizando o total de jogadores:

function listarJogadores(thePlayer)
	outputChatBox ( "Total: #889123" .. getPlayerCount(), thePlayer, 255, 255, 255, true )
end
addCommandHandler("players", listarJogadores)

 

Edited by OverKILL
Posted

Sobre o loop, usar a função exportada, etc:

function getPlayerCountFromCountry( c )
	local players = 0
	for _, p in pairs( getElementsByType("player") ) do
		country = exports.admin:getPlayerCountry( p )
		if country == tostring(c) then
			players = players + 1
		end
	end
	return players
end

 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
10 minutes ago, DNL291 said:

Sobre o loop, usar a função exportada, etc:


function getPlayerCountFromCountry( c )
	local players = 0
	for _, p in pairs( getElementsByType("player") ) do
		country = exports.admin:getPlayerCountry( p )
		if country == tostring(c) then
			players = players + 1
		end
	end
	return players
end

 

É meio confuso, como vou adicionar este loop junto a função GetPlayerCount ?

Posted (edited)
3 minutes ago, #RooTs said:

Copie a função que ele fez e use 


local country = getPlayerCountFromCountry()

 

Esta parte eu já havia feito, to em dúvida na parte do loop quando puxa os paises, como vou usar a GetPlayerCount pra ele listar em cada output os paises:

Como vou separar por exemplo

Jogadores Brasileiros: 3

Jogadores Gringos: 2 -- Aqui é todos os paises fora o brasil .

Total: 5

Edited by OverKILL
Posted
function listarJogadores(thePlayer)
	local br, gringo = 0,0
	for _,p in ipairs (getElementsByType ( "player" )) do
	local pais = call(getResourceFromName("admin"), "getPlayerCountry", p)
		if (pais == "BR") then br = br + 1
		else gringo = gringo + 1
		end
	end
	outputChatBox ( "Jogadores Brasileiros: #889123" .. br, thePlayer, 255, 255, 255, true )
	outputChatBox ( "Jogadores Gringos: #889123" .. gringo, thePlayer, 255, 255, 255, true )
	outputChatBox ( "Total: #889123" .. getPlayerCount(), thePlayer, 255, 255, 255, true )
end
addCommandHandler("players", listarJogadores)

 

Posted
7 minutes ago, MaligNos said:

function listarJogadores(thePlayer)
	local br, gringo = 0,0
	for _,p in ipairs (getElementsByType ( "player" )) do
	local pais = call(getResourceFromName("admin"), "getPlayerCountry", p)
		if (pais == "BR") then br = br + 1
		else gringo = gringo + 1
		end
	end
	outputChatBox ( "Jogadores Brasileiros: #889123" .. br, thePlayer, 255, 255, 255, true )
	outputChatBox ( "Jogadores Gringos: #889123" .. gringo, thePlayer, 255, 255, 255, true )
	outputChatBox ( "Total: #889123" .. getPlayerCount(), thePlayer, 255, 255, 255, true )
end
addCommandHandler("players", listarJogadores)

 

Testei aqui no local e ele seta como Jogador Gringo

Posted
7 minutes ago, OverKILL said:

Testei aqui no local e ele seta como Jogador Gringo

Se não me engano, quando testa localmente ele não retorna a localização correta do jogador, faz o seguinte no painel do Admin, veja se ele mostra o seu país.

Posted
2 minutes ago, MaligNos said:

Se não me engano, quando testa localmente ele não retorna a localização correta do jogador, faz o seguinte no painel do Admin, veja se ele mostra o seu país.

Eu testei isto agora, e realmente não mostra, testei no servidor e mostrou. obrigado.

Posted (edited)

Adicionar resource na ACL - SERVERSIDE:

function onCountryStart()
    for i,thePlayer in pairs(getElementsByType("player")) do
        getPlayerCountry(thePlayer)
    end
end
addEventHandler("onResourceStart",resourceRoot,onCountryStart)

function getPlayerCountry(thePlayer)
    if thePlayer then
        local playerIP = getPlayerIP(thePlayer)
        if playerIP then
            fetchRemote("http://www.geoplugin.net/json.gp?ip="..playerIP, setPlayerCountry, "", false, thePlayer )
        end
    end
end

function setPlayerCountry(countryTable,errorCode,thePlayer)
    if thePlayer and countryTable and errorCode == 0 then
        local countryTable = fromJSON("["..countryTable.."]")
        if countryTable then
            setElementData(thePlayer,"country",countryTable.geoplugin_countryCode)
            setElementData(thePlayer,"countryName",countryTable.geoplugin_countryName)
        end
    end
end

function listarJogadores(thePlayer,cmd)
    local br = 0
    local players = getElementsByType("player")
    for _,p in ipairs(players) do
        if getElementData(p,"country") == "br" then
            br = br + 1
        end
    end
    outputChatBox("Jogadores Brasileiros: #889123"..br,thePlayer,255,255,255,true)
    outputChatBox("Jogadores Gringos: #889123"..(#players-br),thePlayer,255,255,255,true)
    outputChatBox("Total: #889123"..#players,thePlayer,255,255,255,true)

end
addCommandHandler("players",listarJogadores)

 

Edited by Gw8
Posted

Se você for usar o script no seu servidor hospedado, pra pra economizar a largura de banda, te recomendo usar o código da função exportada do Admin:

E se quiser reconhecido como "BR" no local, mesmo com outro IP, você pode fazer uma edição no código e definir seu local com base na conta, nick, IP.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

eu tinha visto uma vez um joinquit com ( Pais, Estado, e cidade) como é feito isso ?
é usado "FetchRemote" com um link ? tipo isso.

fetchRemote("http://www.geoplugin.net/json.gp?ip="..playerIP, setPlayerCountry, "", false, thePlayer )

 

 DUyJ810.gif

Posted (edited)
34 minutes ago, #RooTs said:

eu tinha visto uma vez um joinquit com ( Pais, Estado, e cidade) como é feito isso ?
é usado "FetchRemote" com um link ? tipo isso.


fetchRemote("http://www.geoplugin.net/json.gp?ip="..playerIP, setPlayerCountry, "", false, thePlayer )

 

Sim.

Ex:

addEventHandler("onPlayerJoin", root,
    function()
        local ip = getPlayerIP(source)
        fetchRemote("http://ip-api.com/json/"..ip, outputJoin, "", false, source)
end)

 

Edited by OverKILL

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...