Renaz Posted May 27, 2019 Posted May 27, 2019 (edited) Algum tempo atrás eu pedi ajuda aqui no forum sobre um script de prender , eu queria saber agora como eu crio uma tabela (no chat ou painel gui) aparecendo os presos e o tempo eu não faço a minima ideia como Edited May 27, 2019 by Renazz
DNL291 Posted May 27, 2019 Posted May 27, 2019 Primeiro você vai precisar alguma forma de obter o preso e o tempo de prisão, pode estar armazenado em element-data ou numa tabela. Você vai precisar de um loop em todos jogadores verificando os valores e salva o preso e o tempo numa tabela.
Renaz Posted May 27, 2019 Author Posted May 27, 2019 no caso quando o player é preso eu usei uma função pra setar a data "preso" na conta, ainda quando o tempo acaba essa data é removida.
Jonas^ Posted May 27, 2019 Posted May 27, 2019 (edited) Function útil. https://wiki.multitheftauto.com/wiki/GetPlayersByData Edited May 27, 2019 by Jonas^
DNL291 Posted May 27, 2019 Posted May 27, 2019 local playerdata = "preso" function getPlayersByData(dataName) if dataName and type(dataName) == "string" then local playersTable = {} for i,v in ipairs(getElementsByType("player")) do if getElementData(v, dataName) then table.insert(playersTable, v) end end if #playersTable == 0 then return false end return playersTable else return false end end for i, player in ipairs(getPlayersByData(playerdata)) do print( "Data: ".. playerdata .."; Jogador: ".. tostring(getPlayerName(player)) ) end 1
Jonas^ Posted May 27, 2019 Posted May 27, 2019 Nem tentou pelo visto... addCommandHandler ("presos", function (player, cmd) local presos = getPlayersByData ("preso") or {} local msg = "" if #presos == 0 then msg = "Nenhum jogador preso encontrado!" elseif type(presos) == "table" then msg = table.concat (presos, ", ") end outputChatBox ("[PRESOS] #FFFFFF"..msg, player, 255, 30, 30, true) end) function getPlayersByData (dataName) if dataName and type(dataName) == "string" then local playersTable = {} for _, v in ipairs(getElementsByType("player")) do if getElementData (v, dataName) then table.insert (playersTable, getPlayerName(v)) end end if #playersTable == 0 then return false end return playersTable end return false end 1
Renaz Posted May 27, 2019 Author Posted May 27, 2019 beleza funcionou e pra mostrar o tempo é so usar ..valTimer..?
DNL291 Posted May 27, 2019 Posted May 27, 2019 Edita o comando de prender e adiciona um setElementData para o tempo de prisão. No comando ficaria assim (assumindo que o element-data "prisao:tempo" exista) : addCommandHandler ("presos", function (player, cmd) if isPlayerInACL(player, "Admin") ~= true then return end local presos = getPlayersByData ("preso") if not presos then return outputChatBox( "Nenhum jogador preso encontrado!", player, 255, 30, 30) end local jailtime = function (player) return getElementData( player, "prisao:tempo" ) or "N/A" end for i, p in ipairs(presos) do outputChatBox ("[PRESOS] Nick: ".. getPlayerName(p):gsub("#%x%x%x%x%x%x", "") .." - Tempo: ".. tostring(jailtime(p)), player, 230, 230, 230, true) end end) function getPlayersByData (dataName) if dataName and type(dataName) == "string" then local playersTable = {} for _, v in ipairs(getElementsByType("player")) do if getElementData (v, dataName) then table.insert (playersTable, v) end end if #playersTable == 0 then return false end return playersTable end return false end function isPlayerInACL(player, acl) local accountName = getAccountName( getPlayerAccount(player) ) if accountName ~= "guest" and type( aclGetGroup(acl) ) == "userdata" then return isObjectInACLGroup( "user."..accountName, aclGetGroup(acl) ) end return false end 1
Renaz Posted May 27, 2019 Author Posted May 27, 2019 O código de prender está junto com o de ver os presos local DelegaciaPrender = createMarker (1535.8380126953, -1672.9124755859, 12.3828125, "cylinder", 5, 0, 0, 255, 0) local blipprender = createBlip(1535.8380126953, -1672.9124755859, 12.3828125,30,0,0,0,255) function prenderJogador(thePlayer, cmd, playerid, valTimer) local alvo = exports["[LusoRP](Sistema)ID_System"]:getPlayerID(tonumber(playerid)) if not alvo then return outputChatBox("[AVISO] Falta colocar o ID do jogador!",thePlayer , 255,0,0) end if not valTimer then return outputChatBox("[AVISO] Falta colocar o tempo de prisão!",thePlayer , 255,0,0) end if isObjectInACLGroup ("user."..getAccountName(getPlayerAccount (thePlayer)), aclGetGroup ("ComandosCorporacoes")) then if isElementWithinMarker (thePlayer, DelegaciaPrender) then setElementData (alvo, "preso", true) setElementPosition (alvo, 264.42120361328, 77.57405090332, 1001.0390625) setElementInterior (alvo, 6) setElementDimension (alvo, 1) takeAllWeapons (alvo) setPlayerWantedLevel (alvo,0) outputChatBox ("#4682B4*LusoRP* O Policia ' "..getPlayerName(thePlayer).." ' Prendeu o Cidadão ID ' "..playerid.." '!.", root, 100,100, 255, true) outputChatBox ("#4682B4*LusoRP* Pelo tempo de : "..valTimer.." minuto(s)", root, 100, 100, 255, true) setTimer (function () toggleAllControls (alvo, true) removeElementData (alvo, "preso") setPedAnimation (alvo, nil, nil) removeElementData (alvo,"Algemado") setElementPosition (alvo, 1542.0284423828, -1669.5544433594, 13.553701400757) setElementDimension (alvo, 0) setElementInterior (alvo, 0) outputChatBox ("#4682B4*LusoRP* O Cidadão ID ' "..playerid.." ' Foi solto da Prisão!", root, 0, 0, 255, true) end, (tonumber(valTimer)) * 60000, 1) else outputChatBox ("[AVISO] Você não está na frente da Delegacia para Prender o Sujeito!", thePlayer, 255,0,0) end end end addCommandHandler ("prender", prenderJogador) addCommandHandler ("presos", function (player, cmd) if isPlayerInACL(player, "Admin") ~= true then return end local presos = getPlayersByData ("preso") if not presos then return outputChatBox( "Nenhum jogador preso encontrado!", player, 255, 30, 30) end local jailtime = function (player) return getElementData( player, "prisao:tempo" ) or "N/A" end for i, p in ipairs(presos) do outputChatBox ("[PRESOS] Nick: ".. getPlayerName(p):gsub("#%x%x%x%x%x%x", "") .." - Tempo: ".. tostring(jailtime(p)), player, 230, 230, 230, true) end end) function getPlayersByData (dataName) if dataName and type(dataName) == "string" then local playersTable = {} for _, v in ipairs(getElementsByType("player")) do if getElementData (v, dataName) then table.insert (playersTable, v) end end if #playersTable == 0 then return false end return playersTable end return false end function isPlayerInACL(player, acl) local accountName = getAccountName( getPlayerAccount(player) ) if accountName ~= "guest" and type( aclGetGroup(acl) ) == "userdata" then return isObjectInACLGroup( "user."..accountName, aclGetGroup(acl) ) end return false end
Jonas^ Posted May 27, 2019 Posted May 27, 2019 (edited) Mano, você mal vê o código e faz de qualquer jeito em menos de 2 minutos. Você vai ter que setar em 1 element-data nesse tempo preso aí como já foi mostrado no código do DNL. Edited May 27, 2019 by Jonas^
DNL291 Posted May 27, 2019 Posted May 27, 2019 Onde está o setElementData no código que você mostrou @Renazz ?
Jonas^ Posted May 27, 2019 Posted May 27, 2019 Lhe damos 95% do código pronto, você é capaz de fazer isso, basta pensar um pouco.
Renaz Posted May 27, 2019 Author Posted May 27, 2019 local DelegaciaPrender = createMarker (1535.8380126953, -1672.9124755859, 12.3828125, "cylinder", 5, 0, 0, 255, 0) local blipprender = createBlip(1535.8380126953, -1672.9124755859, 12.3828125,30,0,0,0,255) function prenderJogador(thePlayer, cmd, playerid, valTimer) local alvo = exports["[LusoRP](Sistema)ID_System"]:getPlayerID(tonumber(playerid)) if not alvo then return outputChatBox("[AVISO] Falta colocar o ID do jogador!",thePlayer , 255,0,0) end if not valTimer then return outputChatBox("[AVISO] Falta colocar o tempo de prisão!",thePlayer , 255,0,0) end if isObjectInACLGroup ("user."..getAccountName(getPlayerAccount (thePlayer)), aclGetGroup ("ComandosCorporacoes")) then if isElementWithinMarker (thePlayer, DelegaciaPrender) then setElementData (alvo, "preso", true) setElementData (alvo, "prisao:tempo" ,true) setElementPosition (alvo, 264.42120361328, 77.57405090332, 1001.0390625) setElementInterior (alvo, 6) setElementDimension (alvo, 1) takeAllWeapons (alvo) setPlayerWantedLevel (alvo,0) outputChatBox ("#4682B4*LusoRP* O Policia ' "..getPlayerName(thePlayer).." ' Prendeu o Cidadão ID ' "..playerid.." '!.", root, 100,100, 255, true) outputChatBox ("#4682B4*LusoRP* Pelo tempo de : "..valTimer.." minuto(s)", root, 100, 100, 255, true) setTimer (function () toggleAllControls (alvo, true) removeElementData (alvo, "preso") setPedAnimation (alvo, nil, nil) removeElementData (alvo,"Algemado") removeElementData (alvo, "prisao:tempo") setElementPosition (alvo, 1542.0284423828, -1669.5544433594, 13.553701400757) setElementDimension (alvo, 0) setElementInterior (alvo, 0) outputChatBox ("#4682B4*LusoRP* O Cidadão ID ' "..playerid.." ' Foi solto da Prisão!", root, 0, 0, 255, true) end, (tonumber(valTimer)) * 60000, 1) else outputChatBox ("[AVISO] Você não está na frente da Delegacia para Prender o Sujeito!", thePlayer, 255,0,0) end end end addCommandHandler ("prender", prenderJogador) addCommandHandler ("presos", function (player, cmd) if isPlayerInACL(player, "Admin") ~= true then return end local presos = getPlayersByData ("preso") if not presos then return outputChatBox( "Nenhum jogador preso encontrado!", player, 255, 30, 30) end local jailtime = function (player) return getElementData( player, "prisao:tempo" ) or "N/A" end for i, p in ipairs(presos) do outputChatBox ("[PRESOS] Nick: ".. getPlayerName(p):gsub("#%x%x%x%x%x%x", "") .." - Tempo: ".. tostring(jailtime(p)), player, 230, 230, 230, true) end end) function getPlayersByData (dataName) if dataName and type(dataName) == "string" then local playersTable = {} for _, v in ipairs(getElementsByType("player")) do if getElementData (v, dataName) then table.insert (playersTable, v) end end if #playersTable == 0 then return false end return playersTable end return false end function isPlayerInACL(player, acl) local accountName = getAccountName( getPlayerAccount(player) ) if accountName ~= "guest" and type( aclGetGroup(acl) ) == "userdata" then return isObjectInACLGroup( "user."..accountName, aclGetGroup(acl) ) end return false end não notei , já arrumei
DNL291 Posted May 27, 2019 Posted May 27, 2019 (edited) Ok, tá sendo setado agora, mas pergunte-se: 1- O tempo pode ser uma boolean? (true/false) Edited May 27, 2019 by DNL291 1
Renaz Posted May 27, 2019 Author Posted May 27, 2019 Just now, DNL291 said: 1- O tempo pode ser uma boolean? (true/false) como assim? 1 minute ago, DNL291 said: 2 - Quando o jogador for liberado da prisão, ele deve perder as elements-data, certo? sim quando ele sair da prisão todas as datas são removidas.
DNL291 Posted May 27, 2019 Posted May 27, 2019 Just now, Renazz said: como assim? sim quando ele sair da prisão todas as datas são removidas. Não notei, já tem a removeElementData. Use a lógica, você quer mostrar o tempo da prisão ou um valor qualquer? Se for o tempo de prisão não vai outro valor ali? (dica: valtimer). 1
Renaz Posted May 27, 2019 Author Posted May 27, 2019 2 minutes ago, DNL291 said: você quer mostrar o tempo da prisão ou um valor qualquer? quero mostrar o tempo de prisão. 3 minutes ago, DNL291 said: Se for o tempo de prisão não vai outro valor ali? (dica: valtimer). acho que não.
DNL291 Posted May 27, 2019 Posted May 27, 2019 Acha que não vai outro valor? Então está conforme você disse aqui: 2 hours ago, Renazz said: aparecendo os presos e o tempo a element-data 'tempo' será true ?
Renaz Posted May 27, 2019 Author Posted May 27, 2019 acho que a data do tempo tem que ser bolean porém não estou entendo (porque)
DNL291 Posted May 27, 2019 Posted May 27, 2019 E se for uma boolean como vai retornar o tempo de prisão que tá na variável valtimer ?
Jonas^ Posted May 27, 2019 Posted May 27, 2019 Você sabe oque é um valor bool pelo menos @Renazz pode nos dizer oque é? esquecemos.
Renaz Posted May 27, 2019 Author Posted May 27, 2019 1 minute ago, Jonas^ said: Você sabe oque é um valor bool pelo menos @Renazz pode nos dizer oque é? esquecemos. não sei.
Jonas^ Posted May 27, 2019 Posted May 27, 2019 2 minutes ago, Renazz said: não sei. Então como você acha que tem que ser um valor bool sem nem saber oque é?
Renaz Posted May 27, 2019 Author Posted May 27, 2019 1 minute ago, Jonas^ said: Então como você acha que tem que ser um valor bool sem nem saber oque é? deu a parecer que teria que usar o bool
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