#DeltaSCR Posted February 21, 2019 Author Share Posted February 21, 2019 @DNL291A Verificação das Armas está assim, porém o debug acusa que é esperado um "ped", no argumento "1", podem me ajudar? (Eis o código) function click (button, state, absoluteX, absoluteY) local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then playerName = guiGridListGetItemText (source, sr, 1) thePlayer = getPlayerFromName (playerName) end end if (getPedWeapon (thePlayer, 2)) then dxDrawText("Pistola (#00FF00✔#FFFFFF)", screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) else dxDrawText("Pistola (#FF0000✘#FFFFFF)", screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) end Link to comment
DNL291 Posted February 21, 2019 Share Posted February 21, 2019 Tente assim: local weapons = {} local selectedPlayer function click (button, state, absoluteX, absoluteY) local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do weapons[i] = { getPedWeapon ( thePlayer, i ) } end selectedPlayer = thePlayer end else selectedPlayer = nil weapons = {} end end if selectedPlayer and weapons[2] then dxDrawText("Pistola (#00FF00?#FFFFFF)", screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) else dxDrawText("Pistola (#FF0000?#FFFFFF)", screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) end Link to comment
#DeltaSCR Posted February 22, 2019 Author Share Posted February 22, 2019 14 hours ago, DNL291 said: Tente assim: local weapons = {} local selectedPlayer function click (button, state, absoluteX, absoluteY) local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do weapons[i] = { getPedWeapon ( thePlayer, i ) } end selectedPlayer = thePlayer end else selectedPlayer = nil weapons = {} end end if selectedPlayer and weapons[2] then dxDrawText("Pistola (#00FF00?#FFFFFF)", screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) else dxDrawText("Pistola (#FF0000?#FFFFFF)", screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) end @DNL291 Mas a variavel selectedPlayer não armazena nenhum valor não? Link to comment
DNL291 Posted February 22, 2019 Share Posted February 22, 2019 (edited) Armazena o jogador quando seleciona, e quando 'des-seleciona' remove o player da variável. A propósito, você já testou o código? Edited February 22, 2019 by DNL291 Link to comment
#DeltaSCR Posted February 22, 2019 Author Share Posted February 22, 2019 (edited) 3 minutes ago, DNL291 said: Armazena o jogador quando seleciona, e quando 'des-seleciona' remove o player da variável. A propósito, você já testou o código? Testei sim, porém aconteceu um erro: Está funcionado corretamente a parte de selecionar e descelecionar, só que quando eu seleciono um player, mesmo com arma nenhuma, no painel indica como se estivesse com todos os Slots ocupados... Edited February 22, 2019 by danblemes1 Link to comment
DNL291 Posted February 22, 2019 Share Posted February 22, 2019 Ah, é que retorna 0 se não tiver arma no slot, e no código não tem nenhuma verificação. Link to comment
#DeltaSCR Posted February 22, 2019 Author Share Posted February 22, 2019 1 minute ago, DNL291 said: Ah, é que retorna 0 se não tiver arma no slot, e no código não tem nenhuma verificação. Então como eu faria essa verificação? Link to comment
DNL291 Posted February 22, 2019 Share Posted February 22, 2019 function click (button, state, absoluteX, absoluteY) local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do local w = getPedWeapon ( thePlayer, i ) if w and w ~= 0 then weapons[i] = { w } end end selectedPlayer = thePlayer end else selectedPlayer = nil weapons = {} end end Isso deve funcionar. Link to comment
#DeltaSCR Posted February 22, 2019 Author Share Posted February 22, 2019 5 minutes ago, DNL291 said: function click (button, state, absoluteX, absoluteY) local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do local w = getPedWeapon ( thePlayer, i ) if w and w ~= 0 then weapons[i] = { w } end end selectedPlayer = thePlayer end else selectedPlayer = nil weapons = {} end end Isso deve funcionar. Só me restou uma dúvida: Então onde e como eu deveria encaixar a verificação das armas? (Se não for muito incômodo, por favor, me de um exemplo) Link to comment
DNL291 Posted February 22, 2019 Share Posted February 22, 2019 (edited) A verificação não vai mudar muito, se o slot tiver vazio vai retornar nil. Mas ali no DX você pode deixar assim: local slot2Text = weapons[2] and "Com ".. getWeaponNameFromID(weapons[2]) or "Sem arma" if selectedPlayer then -- se Não quiser que mostre o dx apenas quando selecionar uma row remova essa verificação dxDrawText( slot2Text, screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) end Edited February 22, 2019 by DNL291 Link to comment
#DeltaSCR Posted February 22, 2019 Author Share Posted February 22, 2019 3 minutes ago, DNL291 said: A verificação não vai mudar muito, se o slot tiver vazio vai retornar nil. Mas ali no DX você pode deixar assim: local slot2Text = weapons[2] and "Com ".. getWeaponNameFromID(weapons[2]) or "Sem arma" if selectedPlayer then -- se Não quiser que mostre o dx apenas quando selecionar uma row remova essa verificação dxDrawText( slot2Text, screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) end É pq o meu objetivo é: Se ele tiver a arma, fica o "V", caso contrário "X" (ambos no painel DX) Link to comment
DNL291 Posted February 22, 2019 Share Posted February 22, 2019 Então você pode deixar mais simples: dxDrawText( (weapons[2] and "V" or "X"), screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) Link to comment
#DeltaSCR Posted February 22, 2019 Author Share Posted February 22, 2019 2 minutes ago, DNL291 said: Então você pode deixar mais simples: dxDrawText( (weapons[2] and "V" or "X"), screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) E oque eu faço com a Variável "slot2Text"? Link to comment
DNL291 Posted February 22, 2019 Share Posted February 22, 2019 (edited) Aquela variável era do código antigo, usando o meu último código não vai precisar dela. Edited February 22, 2019 by DNL291 Link to comment
#DeltaSCR Posted February 23, 2019 Author Share Posted February 23, 2019 5 minutes ago, DNL291 said: Aquela variável era do código antigo, usando o meu último código não vai precisar dela. Então ficaria assim:? function click (button, state, absoluteX, absoluteY) local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do local w = getPedWeapon ( thePlayer, i ) if w and w ~= 0 then weapons[i] = { w } end end selectedPlayer = thePlayer end else selectedPlayer = nil weapons = {} dxDrawText( (weapons[2] and "Pistola(#00FF00✔#FFFFF)" or "Pistola (#FF0000✘#FFFFFF)"), screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) end end (Desculpe se estiver mal identado, estou pelo celular) Link to comment
DNL291 Posted February 23, 2019 Share Posted February 23, 2019 dxDrawText é separada do evento onClientGUIClick. Coloque ela em outra função com o evento onClientRender. Link to comment
#DeltaSCR Posted February 23, 2019 Author Share Posted February 23, 2019 (edited) Agora eu estou obtendo o Dinheiro do Player selecionado (thePlayer), porém quando eu deseleciono o player, no DX, mantém o dinheiro do player, como posso fixar isso? local money = getPlayerMoney (thePlayer) if money and money ~= 0 then dxDrawText("Dinheiro: "..money.."", screenW * 0.6461, screenH * 0.3167, screenW * 0.5703, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "left", "center", false, false, false, false, false) end Edited February 23, 2019 by danblemes1 Link to comment
#DeltaSCR Posted February 23, 2019 Author Share Posted February 23, 2019 Resolvido Agora estou com o seguinte problema na verificação de data - O debugscript acusa o seguinte: WARNING: ...:153: Bad Argument @ 'getElementData' [Expected element at argument 1, got nil] A seguir está o código: if selectedPlayer then if getElementData (thePlayer, "AirNewSCR_Porte_de_Armas") == "Sim" then dxDrawText("PDA (#00FF00✔#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, false, false) else dxDrawText("PDA (#FF0000✘#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, false, false) selectedPlayer = nil end end Link to comment
DNL291 Posted February 23, 2019 Share Posted February 23, 2019 Troque por 'selectedPlayer'. Link to comment
#DeltaSCR Posted February 24, 2019 Author Share Posted February 24, 2019 17 hours ago, DNL291 said: Troque por 'selectedPlayer'. if selectedPlayer then if getElementData (selectedPlayer, "AirNewSCR_Porte_de_Armas") == "Sim" then dxDrawText("PDA (#00FF00✔#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) else dxDrawText("PDA (#FF0000✘#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) selectedPlayer = nil end end Está exatamente assim, porém bugou tudo, não obtem mais dado nenhum do Player Link to comment
DNL291 Posted February 24, 2019 Share Posted February 24, 2019 Deve ser na verificação if selectedPlayer then. Mostre como está a função click. Link to comment
#DeltaSCR Posted February 24, 2019 Author Share Posted February 24, 2019 1 hour ago, DNL291 said: Deve ser na verificação if selectedPlayer then. Mostre como está a função click. A função click permanece a mesma que você mandou anteriormente Link to comment
DNL291 Posted February 25, 2019 Share Posted February 25, 2019 (edited) Pode ser o element-data não retornando o valor certo. Você também setou nil na variável selectedPlayer, com um valor inválido a verificação não vai executar e nenhum texto vai ser mostrado. Faça um teste neste código e veja o que mostra no chat e debug: local weapons = {} function createPlayerList () playersList = guiCreateGridList (0.26, 0.25, 0.11, 0.57, true) local column = guiGridListAddColumn (playersList, "Jogadores", 0.9) if (column) then for _, v in ipairs (getElementsByType("player")) do local row = guiGridListAddRow (playerList) guiGridListSetItemText (playerList, row, 1, string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", ""), false, false) end addEventHandler ("onClientGUIClick", playerList, click, false) end end addEventHandler ("onClientResourceStart", resourceRoot, createPlayerList) function click (button) if button ~= "left" then return end local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do local w = getPedWeapon ( thePlayer, i ) if w and w ~= 0 then weapons[i] = w end end iprint( weapons ) selectedPlayer = thePlayer c = false end outputChatBox("thePlayer: "..tostring(thePlayer)) else selectedPlayer = nil weapons = {} outputChatBox("Nenhum jogador selecionado") end end addEventHandler( "onClientRender", root, function() dxDrawText( (weapons[2] and "V" or "X"), screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) --if selectedPlayer then local PDA = "" if selectedPlayer then PDA = getElementData (selectedPlayer, "AirNewSCR_Porte_de_Armas") end if c ~= true then outputChatBox("@PDA: "..tostring(PDA)) c = true end if PDA == "Sim" then dxDrawText("PDA (#00FF00✔#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) else dxDrawText("PDA (#FF0000✘#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) --selectedPlayer = nil -- você está anulando a variável que é necessária p/ o texto ser mostrado end --end end ) function _getPlayerFromName( name ) if not (name) then return false end -- for i,p in pairs(getElementsByType("player")) do if getPlayerName(p):gsub("#%x%x%x%x%x%x", "") == name then return p end end return false end Edited February 25, 2019 by DNL291 Link to comment
#DeltaSCR Posted February 25, 2019 Author Share Posted February 25, 2019 6 minutes ago, DNL291 said: Pode ser o element-data não retornando o valor certo. Você também setou nil na variável selectedPlayer, com um valor inválido a verificação não vai executar e nenhum texto vai ser mostrado. Faça um teste neste código e veja o que mostra no chat e debug: local weapons = {}function createPlayerList () playersList = guiCreateGridList (0.26, 0.25, 0.11, 0.57, true) local column = guiGridListAddColumn (playersList, "Jogadores", 0.9) if (column) then for _, v in ipairs (getElementsByType("player")) do local row = guiGridListAddRow (playerList) guiGridListSetItemText (playerList, row, 1, string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", ""), false, false) end addEventHandler ("onClientGUIClick", playerList, click, false) endendaddEventHandler ("onClientResourceStart", resourceRoot, createPlayerList)function click (button) if button ~= "left" then return end local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do local w = getPedWeapon ( thePlayer, i ) if w and w ~= 0 then weapons[i] = w end end iprint( weapons ) selectedPlayer = thePlayer c = false end outputChatBox("thePlayer: "..tostring(thePlayer)) else selectedPlayer = nil weapons = {} outputChatBox("Nenhum jogador selecionado") endendaddEventHandler( "onClientRender", root, function() dxDrawText( (weapons[2] and "V" or "X"), screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) --if selectedPlayer then local PDA = "" if selectedPlayer then PDA = getElementData (selectedPlayer, "AirNewSCR_Porte_de_Armas") end if c ~= true then outputChatBox("@PDA: "..tostring(PDA)) c = true end if PDA == "Sim" then dxDrawText("PDA (#00FF00✔#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) else dxDrawText("PDA (#FF0000✘#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) --selectedPlayer = nil -- você está anulando a variável que é necessária p/ o texto ser mostrado end --end end)function _getPlayerFromName( name ) if not (name) then return false end -- for i,p in pairs(getElementsByType("player")) do if getPlayerName(p):gsub("#%x%x%x%x%x%x", "") == name then return p end end return falseend Vou testar e em breve te aviso o que deu, provavelmente foi isso ai da variável que você disse mesmo Link to comment
#DeltaSCR Posted February 25, 2019 Author Share Posted February 25, 2019 12 hours ago, DNL291 said: Pode ser o element-data não retornando o valor certo. Você também setou nil na variável selectedPlayer, com um valor inválido a verificação não vai executar e nenhum texto vai ser mostrado. Faça um teste neste código e veja o que mostra no chat e debug: local weapons = {} function createPlayerList () playersList = guiCreateGridList (0.26, 0.25, 0.11, 0.57, true) local column = guiGridListAddColumn (playersList, "Jogadores", 0.9) if (column) then for _, v in ipairs (getElementsByType("player")) do local row = guiGridListAddRow (playerList) guiGridListSetItemText (playerList, row, 1, string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", ""), false, false) end addEventHandler ("onClientGUIClick", playerList, click, false) end end addEventHandler ("onClientResourceStart", resourceRoot, createPlayerList) function click (button) if button ~= "left" then return end local sr = guiGridListGetSelectedItem (source) if sr and sr ~= -1 then local playerName = guiGridListGetItemText (source, sr, 1) local thePlayer = _getPlayerFromName (playerName) if isElement(thePlayer) then for i=1,12 do local w = getPedWeapon ( thePlayer, i ) if w and w ~= 0 then weapons[i] = w end end iprint( weapons ) selectedPlayer = thePlayer c = false end outputChatBox("thePlayer: "..tostring(thePlayer)) else selectedPlayer = nil weapons = {} outputChatBox("Nenhum jogador selecionado") end end addEventHandler( "onClientRender", root, function() dxDrawText( (weapons[2] and "V" or "X"), screenW * 0.3750, screenH * 0.3167, screenW * 0.4336, screenH * 0.3583, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) --if selectedPlayer then local PDA = "" if selectedPlayer then PDA = getElementData (selectedPlayer, "AirNewSCR_Porte_de_Armas") end if c ~= true then outputChatBox("@PDA: "..tostring(PDA)) c = true end if PDA == "Sim" then dxDrawText("PDA (#00FF00✔#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) else dxDrawText("PDA (#FF0000✘#FFFFFF)", screenW * 0.7661, screenH * 0.4333, screenW * 0.5703, screenH * 0.4750, tocolor(255, 255, 255, 255), 1.00, "clear", "center", "center", false, false, false, true, false) --selectedPlayer = nil -- você está anulando a variável que é necessária p/ o texto ser mostrado end --end end ) function _getPlayerFromName( name ) if not (name) then return false end -- for i,p in pairs(getElementsByType("player")) do if getPlayerName(p):gsub("#%x%x%x%x%x%x", "") == name then return p end end return false end @DNL291 Eis a print, aparentemente está funcionando Spoiler https://prntscr.com/mpuf3w Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now