Jump to content

[AJUDA]Visibilidade de Blips


Recommended Posts

Posted

Então, eu fiz o seguinte código, e nele eu coloquei uma linha de criar um blip atachado com o player, o blip é criado, só que em vez de aparecer somente pro Element especificado, ele aparece para todos, poderiam me ajudar? (Linhas 6 e7)

function pedir (source)
	local players = getElementsByType ("player")
	for _, driver in ipairs (players) do
		local account = getAccountName (getPlayerAccount(driver))
		if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
			local blip = createBlipAttachedTo (source, 62)
			setElementVisibleTo (blip, driver, false)
		end
	end
end
addCommandHandler ("uber", pedir)

 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted
function pedir (source)
	local blip = createBlipAttachedTo (source, 62)
	local players = getElementsByType ("player")
	for _, driver in ipairs (players) do
		local account = getAccountName (getPlayerAccount(driver))
		if not isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
			setElementVisibleTo (blip, driver, false)
		end
	end
end
addCommandHandler ("uber", pedir)

 

Posted

@danblemes1 Seria melhor você criar só 1 tópico pra um assunto, senão fica o mesmo código em outros tópicos.

Sobre o seu problema, acho que que deve usar primeiro código que o OverKILL postou e depois mostrar o elemento para o elemento-alvo, tente:

function pedir (splayer)
	local players = getElementsByType ("player")
	local blip = createBlipAttachedTo (splayer, 62)
	setElementVisibleTo (blip, root, false) -- oculta o blip para todos elementos
	
	for _, driver in ipairs (players) do
		local account = getAccountName (getPlayerAccount(driver))
		if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
			setElementVisibleTo (blip, driver, true) -- mostra o blip para todos do grupo "UBER"
		end
	end
end
addCommandHandler ("uber", pedir)

 

 

  • Like 2

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

Posted (edited)

Então mano, agora, eu queria meio que fazer um codigo em tabela (acho que é esse o nome), tipo, quando um player da o comando "uber", aparece um blip nele visível somente para a ACL Uber, até aí tudo nem só que eu queria que quando o motorista desse o comando "/aceitar + nick do passageiro"...

local blip = createBlipAttachedTo (source, 62)
setElementVisibleTo

function aceitar (thePlayer, commandName, playerName)
    if playerName then
       local theClient = getPlayerFromPartialName (playerName)
       local pName = getPlayerName (theClient)
       if blip and isElement (blip) then
          destroyElement (blip)
          blip = nil
       end
    end
end

Mas por ser um script que vai funcionar com várias pessoas ao mesmo tempo, ou seja, vários blips, eu quero que seja destruído somente o blip daquele player em específico, de modo que não atrapalhe as outras corridas; quais alterações eu teria que fazer?

Edited by danblemes1

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

  • Moderators
Posted

Se eu fosse você, colocaria os blips em uma tabela, usando os jogadores como índices.

local blip = {}

function pedir (splayer)
	local players = getElementsByType ("player")
	blip[splayer] = createBlipAttachedTo (splayer, 62)
	setElementVisibleTo (blip[splayer], root, false) -- Oculta o blip para todo mundo.
	
	for _, driver in ipairs (players) do
		local account = getAccountName (getPlayerAccount(driver))
		if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
			setElementVisibleTo (blip[splayer], driver, true) -- Mostra o blip para todos do grupo "UBER"
		end
	end
end
addCommandHandler ("uber", pedir)

function aceitar (thePlayer, commandName, playerName)
    if playerName then
       local theClient = getPlayerFromPartialName (playerName)
       if blip[thePlayer] and isElement (blip[thePlayer]) then
          destroyElement (blip[thePlayer])
          blip[thePlayer] = nil
       end
    end
end

(Não testado)

  • Thanks 1

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.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
14 minutes ago, Lord Henry said:

Se eu fosse você, colocaria os blips em uma tabela, usando os jogadores como índices.


local blip = {}

function pedir (splayer)
	local players = getElementsByType ("player")
	blip[splayer] = createBlipAttachedTo (splayer, 62)
	setElementVisibleTo (blip[splayer], root, false) -- Oculta o blip para todo mundo.
	
	for _, driver in ipairs (players) do
		local account = getAccountName (getPlayerAccount(driver))
		if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
			setElementVisibleTo (blip[splayer], driver, true) -- Mostra o blip para todos do grupo "UBER"
		end
	end
end
addCommandHandler ("uber", pedir)

function aceitar (thePlayer, commandName, playerName)
    if playerName then
       local theClient = getPlayerFromPartialName (playerName)
       if blip[thePlayer] and isElement (blip[thePlayer]) then
          destroyElement (blip[thePlayer])
          blip[thePlayer] = nil
       end
    end
end

(Não testado)

Mas nesse código, quem é o solicitante? O thePlayer ou o playerName?

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted
5 hours ago, danblemes1 said:

Mas nesse código, quem é o solicitante? O thePlayer ou o playerName?

⬇️⬇️⬇️⬇️

6 hours ago, danblemes1 said:

... quando o motorista desse o comando "/aceitar + nick do passageiro"...

 

Pelo que você mesmo disse, thePlayer é o que digitou o comando para aceitar (o "Uber") e playerName o solicitante.

O que mais você deve fazer no código é verificar se o jogador que digitou o comando é mesmo da ACL "UBER".

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

Posted
10 hours ago, DNL291 said:

⬇️⬇️⬇️⬇️

Pelo que você mesmo disse, thePlayer é o que digitou o comando para aceitar (o "Uber") e playerName o solicitante.

O que mais você deve fazer no código é verificar se o jogador que digitou o comando é mesmo da ACL "UBER".

Mas ali o blip está relacionado com o thePlayer, e thePlayer é o Uber

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted
27 minutes ago, danblemes1 said:

Mas ali o blip está relacionado com o thePlayer, e thePlayer é o Uber

  • thePlayer = Motorista Uber
  • playerName = String nick do passageiro
  • theClient = Elemento passageiro
function aceitar (thePlayer, commandName, playerName)
	if playerName then
		local theClient = getPlayerFromPartialName (playerName)
		if not theClient then return end
		if blip[theClient] and isElement (blip[theClient]) then
			destroyElement (blip[theClient])
			blip[theClient] = nil
		end
	end
end
addCommandHandler("aceitar", aceitar)

Falta verificar se o usuário que acionou essa função é realmente um motorista de Uber, como já mencionado pelo @DNL291

Posted
14 minutes ago, MaligNos said:
  • thePlayer = Motorista Uber
  • playerName = String nick do passageiro
  • theClient = Elemento passageiro

function aceitar (thePlayer, commandName, playerName)
	if playerName then
		local theClient = getPlayerFromPartialName (playerName)
		if not theClient then return end
		if blip[theClient] and isElement (blip[theClient]) then
			destroyElement (blip[theClient])
			blip[theClient] = nil
		end
	end
end
addCommandHandler("aceitar", aceitar)

Falta verificar se o usuário que acionou essa função é realmente um motorista de Uber, como já mencionado pelo @DNL291

Ah sim, agora eu entendi, eu tava meio que usando o mesmo objeto para o nick e para o passageiro 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted

agora, o blip é criado, mas não aparece o chamado nem pro uber, e nem a mensagem para o solicitante...

function pedir (splayer)
	local money = getPlayerMoney (splayer)
	if (money >= 30) then
		local players = getElementsByType ("player")
		blip[splayer] = createBlipAttachedTo (splayer, 62)
		setElementVisibleTo (blip[splayer], root, false)
		for _, driver in ipairs (players) do
			local account = getAccountName (getPlayerAccount(driver))
			if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
				local passageiro = getPlayerName (splayer)
				local lugar = getElementZoneName (splayer)
				setElementVisibleTo (blip[splayer], driver, true)
				outputChatBox (" ", driver, 255, 255, 255, true)
				outputChatBox ("#838B83===============================================", driver, 255, 255, 255, true)
				outputChatBox (" ", driver, 255, 255, 255, true)
				outputChatBox ("✘ #838B83Uber Brasil #FFFFFF✘ - O cidadão "..passageiro.." #FFFFFFestá solicitando um Uber em "..lugar.."", driver, 255, 255, 255, true)
				outputChatBox (" ", driver, 255, 255, 255, true)
				outputChatBox ("#838B83===============================================", driver, 255, 255, 255, true)
				outputChatBox (" ", driver, 255, 255, 255, true)
			end
		end
		outputChatBox (" ", splayer, 255, 255, 255, true)
		outputChatBox ("✘ #838B83Uber Brasil #FFFFFF✘ - Você solicitou um Uber, aguarde até alguém chegar", splayer, 255, 255, 255, true)
		outputChatBox (" ", splayer, 255, 255, 255, true)
	else
		outputChatBox ("✘ #838B83Uber Brasil #FFFFFF✘ - #ff0000Você não tem dinheiro suficiente para pedir um Uber #000000(#00FF00 R$30 #000000)", splayer, 255, 255, 255, true)
	end
end
addCommandHandler ("uber", pedir)

 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted
56 minutes ago, danblemes1 said:

agora, o blip é criado, mas não aparece o chamado nem pro uber, e nem a mensagem para o solicitante...

Visualmente não identifiquei nenhum erro. Use o /debugscript 3 e veja se aparece alguma mensagem de erro ou warning.

Posted
Just now, MaligNos said:

Visualmente não identifiquei nenhum erro. Use o /debugscript 3 e veja se aparece alguma mensagem de erro ou warning.

eu usei ele no nivel 3, e le enão acusou nada, talvez seja a outra função:

function aceitar (thePlayer, commandName, playerName)
	local account = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
		if playerName then
			local theClient = getPlayerFromPartialName (playerName)
			if blip[theClient] and isElement (blip[theClient]) then
				destroyElement (blip[theClient])
				blip[theClient] = nil
			end
		end
	end
end
addCommandHandler ("aceitar", aceitar)

 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted
17 minutes ago, danblemes1 said:

eu usei ele no nivel 3, e le enão acusou nada, talvez seja a outra função:


function aceitar (thePlayer, commandName, playerName)
	local account = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
		if playerName then
			local theClient = getPlayerFromPartialName (playerName)
			if blip[theClient] and isElement (blip[theClient]) then
				destroyElement (blip[theClient])
				blip[theClient] = nil
			end
		end
	end
end
addCommandHandler ("aceitar", aceitar)

 

A função getPlayerFromPartialName não é nativa, você deve colocar ela no seu código.

Posted

Assumindo que o código da função getPlayerFromPartialName não estava no seu código, você deveria ter recebido um aviso no debug do tipo: "atempt to call global getPlayerFromPartialName". Isso porque essa função não faz parte do MTA, ela deve ser criada no seu próprio código.

Então certifique-se que esta função esteja dentro do seu código:

function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

 

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

  • Moderators
Posted (edited)
20 minutes ago, danblemes1 said:

Então a função não estava funcionando somente por causa do "local"?

Não cara. As funções úteis elas não são nativas. Isso significa que você precisa colocar o código dela junto para funcionar, e não só a chamada de função.

Acesse o link do getPlayerFromPartialName e copie aquele código que aparece.

Edit: Copie o código que o @DNL291 passou e coloque no seu script.

Edited by Lord Henry

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.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
10 hours ago, DNL291 said:

Assumindo que o código da função getPlayerFromPartialName não estava no seu código, você deveria ter recebido um aviso no debug do tipo: "atempt to call global getPlayerFromPartialName". Isso porque essa função não faz parte do MTA, ela deve ser criada no seu próprio código.

Então certifique-se que esta função esteja dentro do seu código:


function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

 

Então meu codigo pode continuar daquele jeito, correto? mas ai acrescentando essa função

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted
7 hours ago, danblemes1 said:

Então meu codigo pode continuar daquele jeito, correto? mas ai acrescentando essa função

Sim, adicione ela no código e faça o teste. Lembre-se de deixar o debug ativado.

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

Posted

Então mano eu criei a seguinte função para quando o motorista der o comando /aceitar + nick destruir o blip do solicitante, até ai tudo bem, mas eu queria que fosse tirado 30 reais do solicitante e passado ao motorista, eu fiz da seguinte forma:

function aceitar (thePlayer, commandName, playerName)
	local account = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
		if playerName then
			local theClient = getPlayerFromPartialName (playerName)
			if blip[theClient] and isElement (blip[theClient]) then
				destroyElement (blip[theClient])
				blip[theClient] = nil
			end
			takePlayerMoney (playerName)
			givePlayerMoney (thePlayer)
		end
	end
end
addCommandHandler ("aceitar", aceitar)

Mas dessa forma não funciona

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted
46 minutes ago, danblemes1 said:

Então mano eu criei a seguinte função para quando o motorista der o comando /aceitar + nick destruir o blip do solicitante, até ai tudo bem, mas eu queria que fosse tirado 30 reais do solicitante e passado ao motorista, eu fiz da seguinte forma:


function aceitar (thePlayer, commandName, playerName)
	local account = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
		if playerName then
			local theClient = getPlayerFromPartialName (playerName)
			if blip[theClient] and isElement (blip[theClient]) then
				destroyElement (blip[theClient])
				blip[theClient] = nil
			end
			takePlayerMoney (playerName)
			givePlayerMoney (thePlayer)
		end
	end
end
addCommandHandler ("aceitar", aceitar)

Mas dessa forma não funciona

Você quer tirar $30 do passageiro e dar 30$ ao motorista, mas no seu script não está definido esse valor em nenhum lugar, então obviamente que não iria funciona.
Use a wiki takePlayerMoney / givePlayerMoney e veja quais parâmetro precisam ser passados em cada função.

Posted
38 minutes ago, MaligNos said:

Você quer tirar $30 do passageiro e dar 30$ ao motorista, mas no seu script não está definido esse valor em nenhum lugar, então obviamente que não iria funciona.
Use a wiki takePlayerMoney / givePlayerMoney e veja quais parâmetro precisam ser passados em cada função.

mano, seguinte, a função ta tipo, tudo certa (pelo menos ao meu ver), o givePlayerMoney funciona, no caso o motorista perde o dinheiro, mas o solicitante não perde nada:

function aceitar (thePlayer, commandName, playerName)
	local account = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
		if playerName then
			local theClient = getPlayerFromPartialName (playerName)
			if blip[theClient] and isElement (blip[theClient]) then
				destroyElement (blip[theClient])
				blip[theClient] = nil
			end
		end
		givePlayerMoney (thePlayer, 30)
		takePlayerMoney (playerName, 30)
	end
end
addCommandHandler ("aceitar", aceitar)

 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted

danblemes1 Quando houver um problema no script use /debugscript 3 e mostre o erro. Claro que nesse caso o erro está claro como já foi mostrado.

Só estranhei o fato de você não ter mostrado primeiro erro (da função getPlayerFromPartialName) e mais outra vez não falar do erro no debug. Você tá usando mesmo o /debugscript 3 pra ver os erros?

Sobre o take/givePlayerMoney é bem óbvio o problema ali, eu te pergunto: aonde ali que está o valor de 30? Se você ler a sintaxe verá que deve ser assim:

			takePlayerMoney (theClient, 30)
			givePlayerMoney (thePlayer, 30)

Note que troquei playerName por theClient. playerName é uma string - o texto recebido do comando; theClient é o elemento, o qual deve ser passado nas funções takePlayerMoneygivePlayerMoney.

Além disso também deve ser verificado se o jogador possui o valor de "30 reais" assim como você fez ali em cima, no comando /uber. E também faça a verificação se o 'theClient' é mesmo um jogador existente.

Tente isto:


function aceitar (thePlayer, commandName, playerName)
	local account = getAccountName (getPlayerAccount(thePlayer))
	if isObjectInACLGroup ("user."..account, aclGetGroup ("UBER")) then
		if not playerName then
			return outputChatBox( "Erro: digite o nome do passageiro!", thePlayer, 230, 0, 0 )
		end
		local theClient = getPlayerFromPartialName (playerName)
		if theClient then
			local money = getPlayerMoney (theClient)
			if (money < 30) then
				return outputChatBox( "Erro: esse passageiro não tem a quantia necessária!", thePlayer, 230, 0, 0 )
			end
			if blip[theClient] and isElement (blip[theClient]) then
				destroyElement (blip[theClient])
				blip[theClient] = nil
			end
			takePlayerMoney (theClient, 30)
			givePlayerMoney (thePlayer, 30)
		else
			outputChatBox( "Erro: jogador não encontrado!", thePlayer, 230, 0, 0 )
		end
	end
end
addCommandHandler ("aceitar", aceitar)

 

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

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