Jump to content

[Ajuda] ID


Recommended Posts

Posted (edited)

Bom esta função está a buscar o nome do jogador, mas no entanto queria que fosse buscar pelo ID como posso fazê-lo?

Obrigado desde já a ajuda! ❤️

function getPlayerFromNamePart( string )
    if( string and type( string ) == 'string' ) then
        local matches = { }
        for k,v in ipairs( getElementsByType'player' ) do
            if( string.find( getPlayerName( v ), tostring( string ), 0 ) ) then
                table.insert ( matches, v );
            end
        end
       
        if( #matches == 1 ) then
            return matches[1];
        end
    end
    return false;
end

 

Edited by GodKraken
  • Moderators
Posted (edited)

Dai depende de como o ID está salvo no jogador. Geralmente é por elementData, dai nesses casos vc pode fazer assim:

function getPlayerFromID (id)
	for i, player in ipairs (getElementsByType ("player")) do
		if getElementData (player, "ID") == id then -- Supondo que o ID esteja salvo com a data de nome "ID".
			return player
		end
	end
	return false
end

 

Edited by Lord Henry

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! spacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted
2 hours ago, Lord Henry said:

Dai depende de como o ID está salvo no jogador. Geralmente é por elementData, dai nesses casos vc pode fazer assim:


function getPlayerFromID (id)
	for i, player in ipairs (getElementsByType ("player")) do
		if getElementData (player, "ID") == id then -- Supondo que o ID esteja salvo com a data de nome "ID".
			return player
		end
	end
	return false
end

 

Sim está salvando como ID, porém ainda não funcionou.

addEventHandler('onClientGUIClick', root,
function ()
    if (source == buttonFechar) then
        guiSetVisible ( wantedJanela, false )
		guiSetVisible ( JanelaSec, false )
        showCursor ( false )
    elseif (source == buttonAlterar) then
        guiSetVisible ( JanelaSec, true )
        guiBringToFront ( JanelaSec )
    elseif (source == ButtonSec2) then
        guiSetVisible ( JanelaSec, false )
    elseif (source == ButtonSec1) then
        guiSetVisible ( JanelaSec, false )
	gethename = getPlayerFromID( tostring( guiGetText( editWanted1 ) ) )
	getlevel = guiGetText(editWanted2)
	triggerServerEvent("onStupidStar", localPlayer, getlevel, gethename)
    end
end)

function getPlayerFromID (id)
	for i, player in ipairs (getElementsByType ("player")) do
		if getElementData (player, "ID") == id then -- Supondo que o ID esteja salvo com a data de nome "ID".
			return player
		end
	end
	return false
end

 

Posted (edited)
16 minutes ago, Jonas^ said:

Obviamente não vai funcionar pois você nem trocou o nome da data, me mostre o código aonde ele salva o ID na conta.

Resolvido !

 

Edited by GodKraken

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