Jump to content

Elemento Inexistente


Recommended Posts

Olá, tô com uma dúvida aqui, quando eu tento adicionar as armas de um jogador no Discord, meio que o player especificado não existe, pois não aparece arma nenhuma, podem me ajudar?

function DeltaAbrir(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
	if button == "left" then
		if state ==  "down" then
			if clickedElement then
				if (getElementType(clickedElement) == "player") then
					local x, y, z = getElementPosition(localPlayer)
					local px, py, pz = getElementPosition(clickedElement)
					local distance = getDistanceBetweenPoints3D(x, y, z, px, py, pz)
					if not isEventHandlerAdded("onClientRender", root, DeltaDX) then
						if (distance <= 3) then
							playerName = getPlayerName(clickedElement):gsub("#%x%x%x%x%x%x", "")
							addEventHandler("onClientRender", root, DeltaDX)
							DX = true
						end
					end
				end
			end
			if isCursorShowing() then
				if DX == true then
					if isCursorOnElement(screenW * 0.8281, screenH * 0.9167, screenW * 0.1563, screenH * 0.0333) then --// FECHAR
						removeEventHandler("onClientRender", root, DeltaDX)
						DX = false
						showCursor(false)
					elseif isCursorOnElement(screenW * 0.8281, screenH * 0.5167, screenW * 0.1563, screenH * 0.0333) then --// REVISTAR
						setPedAnimation(localPlayer, "POLICE", "plc_drgbst_01", 3000, false, false, false, false)
						setTimer(function()
							removeEventHandler("onClientRender", root, DeltaDX)
							DX = false
							addEventHandler("onClientRender", root, DeltaDXArmas)
							if isElement(clickedElement) then --// A partir daqui eu ja tento começar as verificações...
								for _, weapon in ipairs(getPedWeapons(clickedElement)) do
									if getPedTotalAmmo(clickedElement, getSlotFromWeapon(weapon)) > 0 then
										local theRow = guiGridListAddRow(gridWeapons)
										guiGridListSetItemText(gridWeapons, theRow, 1, getWeaponNameFromID(weapon), false, false)
										guiGridListSetItemText(gridWeapons, theRow, 2, getPedTotalAmmo(clickedElement, getSlotFromWeapon(weapon)), false, false)
									end
								end
							end
							guiSetVisible(gridWeapons, true)
							DXArmas = true
						end, 3500, 1)
					end
				elseif DXArmas == true then
					if isCursorOnElement(screenW * 0.8281, screenH * 0.9167, screenW * 0.1563, screenH * 0.0333) then --// FECHAR
						removeEventHandler("onClientRender", root, DeltaDXArmas)
						guiSetVisible(gridWeapons, false)
						DXArmas = false
						showCursor(false)
					end
				end
			end
		end
	end
end
addEventHandler("onClientClick", root, DeltaAbrir)

--// FUNÇÃO UTIL

function getPedWeapons(ped)
	local playerWeapons = {}
	if ped and isElement(ped) and getElementType(ped) == "ped" or getElementType(ped) == "player" then
		for i = 0, 12 do
			local wep = getPedWeapon(ped,i)
			if wep and wep ~= 0 then
				table.insert(playerWeapons,wep)
			end
		end
	else
		return false
	end
	return playerWeapons
end

 

Link to comment

Então, primeiro eu tinha tentando fazer um loop nos slots, porém no debug acusa era necessário um elemento como argumento, no caso o "clickedElement" que era pra ser o argumento, não tá existindo, e eu confirmei isso utilizando uma função útil para obter as armas, onde eu verifico se existe o jogador, e se existir, adiciona uma row, porém a mesma não é adicionada.

Link to comment

Eu tentei fazer assim também, porém não aparece armamento nenhuma na lista ;-;

if clickedElement then
	if (getElementType(clickedElement) == "player") then
		for i = 1, 12 do
			local playerWeapon = getPedWeapon(clickedElement, i)
			if i and i ~= 0 then
				theRow = guiGridListAddRow(gridWeapons)
				guiGridListSetItemText(gridWeapons, theRow, 1, playerWeapon, false, false)
			end
		end
  	end
end
guiSetVisible(gridWeapons, true)

 

Edited by #DeltaSCR
Erro na indentação.
Link to comment
  • Moderators

Qual a dificuldade em fazer uma depuração no código:


if clickedElement then
	outputChatBox("clickedElement " .. tostring(clickedElement))
	if (getElementType(clickedElement) == "player") then
		for i = 1, 12 do
			local playerWeapon = getPedWeapon(clickedElement, i)
			outputChatBox( "playerWeapon (" .. tostring(i) .. ") : " .. tostring(playerWeapon) )
			if i and i ~= 0 then
				theRow = guiGridListAddRow(gridWeapons)
				guiGridListSetItemText(gridWeapons, theRow, 1, playerWeapon, false, false)
				outputChatBox("theRow " .. tostring(theRow) .."; gridWeapons ".. tostring(gridWeapons))
			end
		end
  	end
else
	outputChatBox("clickedElement = false")
end
guiSetVisible(gridWeapons, true)

 

Link to comment
  • Moderators

Se você testar clicando em você mesmo tenho certeza que não vai mostrar false.

Testei este código e o clickedElement funciona:

function DeltaAbrir(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
	if button == "left" and state ==  "down" then
		outputChatBox("clickedElement: "..tostring(clickedElement))
		if clickedElement then
			if (getElementType(clickedElement) == "player") then
				local x, y, z = getElementPosition(localPlayer)
				local px, py, pz = getElementPosition(clickedElement)
				--local distance = getDistanceBetweenPoints3D(x, y, z, px, py, pz)
				--if not isEventHandlerAdded("onClientRender", root, DeltaDX) then
					--if (distance <= 3) then
						playerName = getPlayerName(clickedElement):gsub("#%x%x%x%x%x%x", "")
						outputChatBox("playerName: "..tostring(playerName))
						--addEventHandler("onClientRender", root, DeltaDX)
						--DX = true
					--end
				--
			end
		end
	end
end
addEventHandler("onClientClick", root, DeltaAbrir)

addCommandHandler("cur", function()
	showCursor(true)
end)

 

Link to comment

Essas dúvidas ai acima eu resolvi, agora no mesmo código, estou com um certo problema, aparentemente simples, porém não to conseguindo resolver - Podem me ajudar?

ERRO:

Spoiler

1IwCjGD.png

Código a seguir:

client-side:

elseif isCursorOnElement(screenW * 0.8281, screenH * 0.5667, screenW * 0.1563, screenH * 0.0333) then
	if not getElementData(playerClicked, "Delta:Algemado") then
		setPedAnimation(playerClicked, "GRAVEYARD", "mrnM_loop", -1, true, false, false, false)
		setElementData(playerClicked, "Delta:Algemado", true)
	else
		setPedAnimation(playerClicked)
		theData = "Delta:Algemado"
		triggerServerEvent("Delta:RemoveData", playerClicked, theData)
	end
end

 

server-side:

function removePlayerData(playerClicked, theData)
	removeElementData(playerClicked, theData)
end
addEvent("Delta:RemoveData", true)
addEventHandler("Delta:RemoveData", getRootElement(), removePlayerData)

 

Link to comment
1 minute ago, DNL291 said:

triggerServerEvent("Delta:RemoveData", resourceRoot, playerClicked, theData)

Sobre as armas do player, o recomendado é obter as armas no lado server e mandar os valores ao cliente.

As armas eu consegui obter no client com função util... Mas fazer no Server, resultará em melhor desempenho do código?

Link to comment
  • Moderators

A única diferença é que vai evitar problemas nos valores reais; o que é setado no client só fica disponível no mesmo, a menos que:

1) Você seta o valor também no server para sincronizar

2) O MTA internamente faça a sincronização com o server

Edit:

No caso das armas não deve ter nenhum problema em obter no cliente, pois giveWeapon só funciona no server.

  • Like 1
Link to comment

Só mais uma dúvida - O sistema funciona assim: Quando um player clicar em outro jogador, se esse player estiver na ACL, daí abre o painel, porém eu fiquei em dúvida nessa questão da ACL, tipo, o que eu devo acrescentar depois de verificar a ACL?

 

Server:

function DeltaACL()
	local accountName = getAccountName(getPlayerAccount(client))
	if isObjectInACLGroup("user."..accountName, aclGetGroup("FT")) then
		--// O que devo acrescentar aqui?
	end
end
addEvent("Delta:VACL", true)
addEventHandler("Delta:VACL", resourceRoot, DeltaACL)

 

Client:

function DeltaAbrir(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
	triggerServerEvent("Delta:VACL", getLocalPlayer())
	if button == "left" and state == "down" then
		if clickedElement then
			if (getElementType(clickedElement) == "player") then
				local x, y, z = getElementPosition(localPlayer)
				local px, py, pz = getElementPosition(clickedElement)
				local distance = getDistanceBetweenPoints3D(x, y, z, px, py, pz)
				if distance <= 3 then
					if not isEventHandlerAdded("onClientRender", root, DeltaDX) then
						playerName = getPlayerName(clickedElement):gsub("#%x%x%x%x%x%x", "")
						addEventHandler("onClientRender", root, DeltaDX)
						DX = true
					end
				end
				playerClicked = clickedElement
			end
		end
	end
end
addEventHandler("onClientClick", root, DeltaAbrir)

 

Edited by #DeltaSCR
Edit: Desculpa por uma dúvida tão simples, porém surgiu '-'
Link to comment
function DeltaACL()
	local accountName = getAccountName(getPlayerAccount(client))
	if isObjectInACLGroup("user."..accountName, aclGetGroup("FT")) then
		triggerClientEvent(client, "openDx", resourceRoot)
	end
end
addEvent("Delta:VACL", true)
addEventHandler("Delta:VACL", resourceRoot, DeltaACL)
function DeltaAbrir(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
	if button == "left" and state == "down" then
		if clickedElement then
			if (getElementType(clickedElement) == "player") then
				local x, y, z = getElementPosition(localPlayer)
				local px, py, pz = getElementPosition(clickedElement)
				local distance = getDistanceBetweenPoints3D(x, y, z, px, py, pz)
				if distance <= 3 then
					triggerServerEvent("Delta:VACL", resourceRoot)
					playerName = getPlayerName(clickedElement):gsub("#%x%x%x%x%x%x", "")
				end
				playerClicked = clickedElement
			end
		end
	end
end
addEventHandler("onClientClick", root, DeltaAbrir)

addEvent("openDx", true)
addEventHandler("openDx", resourceRoot,
	function()
		if not isEventHandlerAdded("onClientRender", root, DeltaDX) then
			addEventHandler("onClientRender", root, DeltaDX)
			DX = true
		end
	end
)

 

Edited by MaligNos
  • Thanks 1
Link to comment

Sim.

Recomendo que você de uma estudada em lógica de programação, pois isso é um dos conceitos mais básicos.... Você pode sim aprender pela tentativa e erro (como agora), mas o tempo gasto para aprender vai ser bem maior, antes 50 minutos estudando, do que 2 horas quebrando a cabeça.

Link to comment

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