Jump to content

Ver presos.


Recommended Posts

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 by Renazz
Link to comment
  • Moderators

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.

Link to comment
  • Moderators

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

 

  • Thanks 1
Link to comment

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

 

  • Thanks 1
Link to comment
  • Moderators

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

 

  • Thanks 1
Link to comment

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

 

Link to comment

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 by Jonas^
Link to comment
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

Link to comment
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.

Link to comment
  • Moderators
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).

  • Thanks 1
Link to comment
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.

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