alowner Posted June 3, 2020 Posted June 3, 2020 markers = { inicio = {352.43173217773, 2540.5510253906, 15.72790145874}, } function isPlayerInACL(player, acl) if isElement(player) and getElementType(player) == "player" and aclGetGroup(acl or "") and not isGuestAccount(getPlayerAccount(player)) then local account = getPlayerAccount(player) return isObjectInACLGroup( "user.".. getAccountName(account), aclGetGroup(acl) ) end return false end function markerInicial (x,y,z,Painel_droga) for i, v in ipairs (markers) do Painel_droga = createMarker (v[1], v[2],v[3], "cylinder", 255, 0, 157, 50) end end ------------------------ function Open_Painel (source, player) if isPlayerInACL(thePlayer, "trafico") then triggerClientEvent(source, "Abrir_Painel", source) else outputChatBox("Você não faz parte de nenhuma gang!", player) end end addEventHandler("onMarkerHit", Painel_droga, Open_Painel) --- erro aqui, na hora de verificar o arugmento 2. Se alguém conseguir me ajudar, ficarei muito grato.
Blaack Posted June 3, 2020 Posted June 3, 2020 20 minutes ago, alowner said: markers = { inicio = {352.43173217773, 2540.5510253906, 15.72790145874}, } function isPlayerInACL(player, acl) if isElement(player) and getElementType(player) == "player" and aclGetGroup(acl or "") and not isGuestAccount(getPlayerAccount(player)) then local account = getPlayerAccount(player) return isObjectInACLGroup( "user.".. getAccountName(account), aclGetGroup(acl) ) end return false end function markerInicial (x,y,z,Painel_droga) for i, v in ipairs (markers) do Painel_droga = createMarker (v[1], v[2],v[3], "cylinder", 255, 0, 157, 50) end end ------------------------ function Open_Painel (source, player) if isPlayerInACL(thePlayer, "trafico") then triggerClientEvent(source, "Abrir_Painel", source) else outputChatBox("Você não faz parte de nenhuma gang!", player) end end addEventHandler("onMarkerHit", Painel_droga, Open_Painel) --- erro aqui, na hora de verificar o arugmento 2. Se alguém conseguir me ajudar, ficarei muito grato. markers = { inicio = {352.43173217773, 2540.5510253906, 15.72790145874}, } function isPlayerInACL(player, acl) if isElement(player) and getElementType(player) == "player" and aclGetGroup(acl or "") and not isGuestAccount(getPlayerAccount(player)) then local account = getPlayerAccount(player) return isObjectInACLGroup( "user.".. getAccountName(account), aclGetGroup(acl) ) end return false end function markerInicial (x,y,z,Painel_droga) for i, v in ipairs (markers) do Painel_droga = createMarker (v[1], v[2],v[3], "cylinder", 255, 0, 157, 50) end end ------------------------ function Open_Painel (hitElement) local source = hitElement if getElementType(source) == "player" then if isPlayerInACL(source, "trafico") then -- Quem é thePlayer ? if isPlayerInACL(thePlayer, "trafico") then triggerClientEvent(source, "Abrir_Painel", source) else outputChatBox("Você não faz parte de nenhuma gang!", source) end end end addEventHandler("onMarkerHit", Painel_droga, Open_Painel) --- erro aqui, na hora de verificar o arugmento 2. 1
DNL291 Posted June 3, 2020 Posted June 3, 2020 thePlayer na linha 22 irá retornar nil; o valor não foi definido em nenhum lugar. Você deve usar o primeiro parâmetro do evento para obter o hitElement (elemento que encostou na marker). Além disso, vai precisar também verificar se esse elemento é um player, faça isso com getElementByType(source) == "player" em uma condição if. E nunca use source como parâmetro; este é uma variável predefinida do MTA e que dependendo da ocasião pode gerar erros no seu código. Fora esses problemas na sua função, você também irá precisar adicionar o evento para cada marker que for criada, e isso não vai acontecer pois o loop está armazenando as markers numa só variável. Isso vai fazer com que só a última marker do loop continue salva. Uma solução seria o seguinte código: local tMarkers = {} function markerInicial (x,y,z,Painel_droga) for i, v in ipairs (markers) do tMarkers[ createMarker (v[1], v[2],v[3], "cylinder", 255, 0, 157, 50) ] = i -- armazenar o índice referente ao da tabela dos locais end end Função Open_Painel: function Open_Painel (hitElement) if tMarkers[source] and getElementType(hitElement) == "player" then if isPlayerInACL(hitElement, "trafico") then triggerClientEvent(hitElement, "Abrir_Painel", hitElement) else outputChatBox("Você não faz parte de nenhuma gang!", hitElement) end end end addEventHandler("onMarkerHit", resourceRoot, Open_Painel) -- adicionar esse evento só para markers neste resource Edit: O erro que você menciona, ocorre porque a linha do evento "onMarkerHit" irá chamar assim que ligar o resource, e nesse momento o valor da variável ainda não foi definido; só será definido quando a função 'markerInicial' for chamada. Edit #2: Você não precisa criar a sub-tabela com uma variável na tabela 'markers', assim já basta: markers = { {352.43173217773, 2540.5510253906, 15.72790145874}, -- sub-tabela 1 {x, y, z}, -- sub-tabela 2 } Isso na verdade faria seu loop com ipairs falhar, já que este é um loop para índices numéricos. 2
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