Jump to content

[Ajuda]Painel de Veículos


Recommended Posts

Olá, sou novo no forum e sou iniciante em programação, eu sei apenas algumas lógicas, mas gostaria da ajuda de alguém pra editar esse script, ele é um script de concessionaria e tem um painel de f2 que mostra todos os veículos comprados na mesma, e eu gostaria de saber se tem como fazer esse painel abri apenas ao passar por um marker, e tirar a bind do f2.

Essa é o codigo do script:

Eu tirei dele apenas um botão de desespawnar, mas eu irei colocar novamente se o sistema de abrir apenas no marker funcionar

 






setTimer ( function ()

local theCol = getElementData(root, "BlockExportCol")
    
function isInColExport ()
    if isElement(theCol) and isElementWithinColShape(localPlayer,theCol) then
        return true else return false
    end
end

function ClientExplosionCFunction()
 if isInColExport ()  then
  cancelEvent ()
 end
end
addEventHandler("onClientExplosion", root, ClientExplosionCFunction)

end , 1000, 1 )
setElementData(localPlayer,"spawnedcars",{})
----------------------------------------------
local screenW, screenH = guiGetScreenSize()
----------------------------------------------
Window_VS = guiCreateStaticImage ((screenW - 428) / 2, (screenH - 300) / 2, 428, 300, "imagens/fundo.png", false)
guiSetAlpha(Window_VS, 0.95)
guiSetVisible(Window_VS, false)
Grid_VS = guiCreateGridList(0.02, 0.03, 0.95, 0.65, true, Window_VS)
guiGridListSetSelectionMode(Grid_VS, 1)
guiGridListAddColumn(Grid_VS,"Veículos",0.3)
guiGridListAddColumn(Grid_VS,"Marca",0.2)
guiGridListAddColumn(Grid_VS,"Tipo",0.259)
guiGridListAddColumn(Grid_VS,"Dano",0.3)
guiGridListAddColumn(Grid_VS,"Original",0.38)
guiGridListAddColumn(Grid_VS,"Preço",0.38)


Button_VS_lk = guiCreateStaticImage(0.02, 0.86, 0.30, 0.11, "imagens/bt-trancar.png", true, Window_VS)

Button_VS_bp = guiCreateStaticImage(0.68, 0.86, 0.30, 0.11, "imagens/bt-rastrear.png", true, Window_VS)
Button_VS_sn = guiCreateStaticImage(0.02, 0.72, 0.30, 0.11, "imagens/bt-spawn.png", true, Window_VS)

Button_VS_sl = guiCreateStaticImage(0.35, 0.86, 0.30, 0.11, "imagens/bt-vender.png", true, Window_VS)



Window_CHK = guiCreateStaticImage((screenW-310)/2,(screenH-120)/2,310,120,"imagens/fundo.png",false)
guiSetVisible(Window_CHK, false)
guiSetProperty(Window_CHK, "AlwaysOnTop", "true")
Label_CHK = guiCreateLabel(21,28,266,36,"",false,Window_CHK)
myFont = guiCreateFont( "fontes/ebrimabd.ttf", 10 )
guiSetFont ( Label_CHK, myFont )
guiSetAlpha(Window_CHK, 0.95)
guiLabelSetColor(Label_CHK, 150, 150, 150)
guiLabelSetHorizontalAlign(Label_CHK,"center",true)
Button_CHK_Y = guiCreateButton(17,73,129,36,"Sim",false,Window_CHK)
Button_CHK_N = guiCreateButton(161,73,129,36,"Não",false,Window_CHK)

function updateGridList()
	local data = getElementData(localPlayer, "VehicleInfo")
	if data then
		local rw, cl = guiGridListGetSelectedItem(Grid_VS)
		guiGridListClear(Grid_VS)
		for i, data in ipairs (data) do
			local carName = getVehicleNameFromModel(data["Model"])		
            local ID = data["ID"]
            local Cost = tonumber(data["Cost"]) or 0
            local HP = math.floor(data["HP"])
            
            local row = guiGridListAddRow(Grid_VS)
			if carName then
			local id = getVehicleModelFromName(carName)
			local nome,marca,tipo = getVehicleRealPropriedadesFromID(tonumber(id))
			guiGridListSetItemText(Grid_VS, row, 1, nome, false, true)
			guiGridListSetItemText(Grid_VS, row, 2, marca, false, true)
			guiGridListSetItemText(Grid_VS, row, 3, tipo, false, true)							
			end				
			local PreCost = math.ceil(Cost*.9*HP/100/10) or 0
            guiGridListSetItemText(Grid_VS, row, 5, carName, false, true)
            guiGridListSetItemData(Grid_VS, row,5, ID)
			guiGridListSetItemText(Grid_VS, row, 4, HP.." HP", false, true)
			guiGridListSetItemText(Grid_VS, row, 6, PreCost, false, true)			
		end
		guiGridListSetSelectedItem(Grid_VS, rw, cl)
	end
end


bindKey("F2", "down",
function()
if (getElementInterior(localPlayer) == 0) and (getElementDimension(localPlayer) == 0) then
if ( not getElementData(localPlayer,"prison") ) then
             if not isInColExport () then
                guiSetVisible(Window_VS, not guiGetVisible(Window_VS))
    guiSetVisible (Window_CHK, false)
	playSound(":EQPsons/open.wav")
    showCursor(guiGetVisible(Window_VS))
	vehsa = getElementData(localPlayer,"spawnedcars") or {}
vehs = ""
for ind,veh in ipairs(vehsa) do
if vehs ~= "" then 
vehs = vehs..", "..veh.."" 
else 
vehs = vehs..""..veh.."" 
 end
end
            end
end
end
end)
triggerServerEvent("onOpenGui", localPlayer)


addEventHandler("onClientElementDataChange", root,
function(dd)
    if getElementType(source) == "player" and source == localPlayer and dd == "VehicleInfo" then
        local data = getElementData(source, dd)
        if data then
            updateGridList()
        end
    end
end)

function WINDOW_CLICK_VEHICLE (button, state, absoluteX, absoluteY)
	local id = guiGridListGetSelectedItem(Grid_VS)
	local ID = guiGridListGetItemData(Grid_VS, id, 5)	
	if source == Button_VS_close then
		guiSetVisible(Window_VS, false)
		showCursor(false)
	end
	if (source == Grid_VS) then
		if id == -5 and idd then
			guiGridListSetSelectedItem(Grid_VS, idd, 5)
			return false
		else
			idd = guiGridListGetSelectedItem(Grid_VS)
		end
	elseif id == -5 then
	
	elseif (source == Button_VS_sn) then
		if not isInColExport () then
			triggerServerEvent("SpawnMyVehicle", localPlayer, ID)
        end
	elseif (source == Button_VS_lt) then 
		triggerServerEvent("LightsMyVehicle", localPlayer, ID)
	elseif (source == Button_VS_bp) then 
		triggerServerEvent("BlipMyVehicle", localPlayer, ID)
	elseif (source == Button_VS_lk) then 
		triggerServerEvent("LockMyVehicle", localPlayer, ID)
	elseif (source == Button_VS_sl) then 
		guiSetVisible(Window_CHK, true)
        local carName = guiGridListGetItemText(Grid_VS, guiGridListGetSelectedItem(Grid_VS), 1)
        local carprice = guiGridListGetItemText(Grid_VS, guiGridListGetSelectedItem(Grid_VS), 6)
        guiSetText(Label_CHK, 'Tem certeza de que quer vender o seu "'..carName..'" por R$'..carprice)
	elseif source == Button_CHK_Y then
		triggerServerEvent("SellMyVehicle", localPlayer, ID)
		guiSetVisible(Window_VS, false)
		guiSetVisible(Window_CHK, false)
		showCursor(false)
	elseif source == Button_CHK_N then
		guiSetVisible (Window_CHK, false)
	elseif source == Button_VS_Spc then
		if getElementInterior(localPlayer) == 0 then
			if getElementData(localPlayer,"Stats") < 2 then
				SpecVehicle(ID)
			end
		end
	end
end
addEventHandler("onClientGUIClick", resourceRoot, WINDOW_CLICK_VEHICLE)


function SpecVehicle(id)
	if spc then 
		removeEventHandler("onClientPreRender", root, Sp)
		setCameraTarget(localPlayer)
		if isTimer(freezTimer) then killTimer(freezTimer) end
		freezTimer = setTimer(function() setElementFrozen(localPlayer, false) end, 2500, 1)
		spc = false
	return end
	for i, vehicle in ipairs(getElementsByType("vehicle")) do
		if getElementData(vehicle, "Owner") == localPlayer and getElementData(vehicle, "ID") == id then
			cVeh = vehicle
			spc = true
			addEventHandler("onClientPreRender", root, Sp)
			guiSetVisible(Window_VS, false)
			showCursor(false)
			break
		  end
                        
	end
end

function Sp()
	if isElement(cVeh) then
		local x, y, z = getElementPosition(cVeh)
		setElementFrozen(localPlayer, true)
		setCameraMatrix(x, y-1, z+15, x, y, z)

	else
		removeEventHandler("onClientPreRender", root, Sp)
		setCameraTarget(localPlayer)
		if isTimer(freezTimer) then killTimer(freezTimer) end
		freezTimer = setTimer(function() setElementFrozen(localPlayer, false) end, 2500, 1)
		spc = false
      end
end





addEventHandler (  "onClientGUIClick" , Button_VS_lk  , function()
if source == Button_VS_lk then
playSoundFrontEnd (10)   
		   guiSetProperty(Button_VS_lk , "ImageColours", "tl:FF787878 tr:FF787878 bl:FF787878 br:FF787878") 
		   setTimer ( function ()	guiSetProperty(Button_VS_lk , "ImageColours", "tl:FFFEFBFC tr:FFFEFBFC bl:FFFEFBFC br:FFFEFBFC")  end, 60, 1)
	end	end
)

addEventHandler (  "onClientGUIClick" , Button_VS_bp   , function()
if source == Button_VS_bp then
playSoundFrontEnd (10)   
		   guiSetProperty(Button_VS_bp, "ImageColours", "tl:FF787878 tr:FF787878 bl:FF787878 br:FF787878") 
		   setTimer ( function ()	guiSetProperty(Button_VS_bp  , "ImageColours", "tl:FFFEFBFC tr:FFFEFBFC bl:FFFEFBFC br:FFFEFBFC")  end, 60, 1)
	end	end
)

addEventHandler (  "onClientGUIClick" , Button_VS_sn    , function()
if source == Button_VS_sn then
playSoundFrontEnd (10)   
		   guiSetProperty(Button_VS_sn , "ImageColours", "tl:FF787878 tr:FF787878 bl:FF787878 br:FF787878") 
		   setTimer ( function ()	guiSetProperty(Button_VS_sn   , "ImageColours", "tl:FFFEFBFC tr:FFFEFBFC bl:FFFEFBFC br:FFFEFBFC")  end, 60, 1)
	end	end
)

addEventHandler (  "onClientGUIClick" , Button_VS_sl  , function()
if source == Button_VS_sl then
playSoundFrontEnd (10)   
		   guiSetProperty(Button_VS_sl  , "ImageColours", "tl:FF787878 tr:FF787878 bl:FF787878 br:FF787878") 
		   setTimer ( function ()	guiSetProperty(Button_VS_sl, "ImageColours", "tl:FFFEFBFC tr:FFFEFBFC bl:FFFEFBFC br:FFFEFBFC")  end, 60, 1)
	end	end
)



function btsyn()
	if source == Button_CHK_Y then
		playSoundFrontEnd (10)   
		guiSetProperty(Button_CHK_Y, "ImageColours", "tl:FF787878 tr:FF787878 bl:FF787878 br:FF787878") 
		setTimer ( function ()	guiSetProperty(Button_CHK_Y, "ImageColours", "tl:FFFEFBFC tr:FFFEFBFC bl:FFFEFBFC br:FFFEFBFC")  end, 60, 1)
	end
	if source == Button_CHK_N then
		playSoundFrontEnd (10)   
		guiSetProperty(Button_CHK_N  ,"ImageColours", "tl:FF787878 tr:FF787878 bl:FF787878 br:FF787878") 
		setTimer ( function ()	guiSetProperty(Button_CHK_N , "ImageColours", "tl:FFFEFBFC tr:FFFEFBFC bl:FFFEFBFC br:FFFEFBFC")  end, 60, 1)
	end
end
addEventHandler (  "onClientGUIClick" , root  , btsyn)

 
addEventHandler (  "onClientGUIClick" , Grid_VS, function()
if source == Grid_VS then
playSoundFrontEnd (10)   
		   guiSetProperty(Grid_VS,"ImageColours", "tl:FF787878 tr:FF787878 bl:FF787878 br:FF787878") 
		   setTimer ( function ()	guiSetProperty(Grid_VS, "ImageColours", "tl:FFFEFBFC tr:FFFEFBFC bl:FFFEFBFC br:FFFEFBFC")  end, 60, 1)
	end	end
)



function getVehicleOwner(veh)
sowner = getElementData(veh,"Owner")
return sowner
end

 

Edited by PauloWillami
Link to comment
  • Moderators
addEventHandler( "onClientMarkerHit", marker,
	function ( p, md )
		if p == localPlayer and md and ( not getElementData(localPlayer,"prison") ) then
			if not isInColExport () then
				guiSetVisible(Window_VS, not guiGetVisible(Window_VS))
				guiSetVisible (Window_CHK, false)
				playSound(":EQPsons/open.wav")
				showCursor(guiGetVisible(Window_VS))
				vehsa = getElementData(localPlayer,"spawnedcars") or {}
				vehs = ""
				for ind,veh in ipairs(vehsa) do
					if vehs ~= "" then 
						vehs = vehs..", "..veh.."" 
					else 
						vehs = vehs..""..veh.."" 
					end
				end
			end
		end
	end
)

'marker' deve ser a variável da função createMarker

  • Like 1
Link to comment

Amigo sou leigo ainda, mas onde vc pos marker depois do OnClientMarkerHit seria pra eu colocar as coordenadas do marker? Desculpa se falei bobagens mas realmente sou iniciante no assunto rsrs, e se sim, essa linha de código eu poderia fazer como um script separado e ela irá funcionar normalmente ou eu devo substituir ela em algo na linha de código que eu pus acima?

Link to comment

Amigo, como disse eu ainda sou leigo, poderia me explicar melhor?

No caso eu crio o marker e onde tem marker no script eu coloco as coordenadas x,y,z, cylinder que seria o tipo de marker, e o tamanho e o rgb? 

De vdd desculpa mas como disse sou mt novato no assunto ksks

Eu li a wiki mas nn entendi mt bem

Edited by PauloWillami
Link to comment
  • Other Languages Moderators

Assim:

-- theMarker é a variável local onde vc vai colocar o marker. Dai no script vc usa essa variável.
local theMarker = createMarker (cordX, cordY, cordZ, "cylinder", tamanho, red, green, blue, alpha) -- Coloque as coordenadas ali nos campos cordX, cordY e cordZ.
-- No tamanho pode ser qualquer valor numérico, por padrão é 4.
-- Em red, green, blue e alpha são as cores e transparência do marker, pode ser de 0 até 255. Por exemplo: 255, 255, 0, 150 fará um marker amarelo semi-transparente.

addEventHandler ("onClientMarkerHit" , theMarker, function (thePlayer, matchingDimension) -- Parâmetros da função, thePlayer = jogador que colidiu no marker | matchingDimension = true, se o jogador está na mesma dimensão que o marker, false se não estiver.
	if thePlayer == localPlayer and matchingDimension and (not getElementData (localPlayer, "prison")) then -- Se o jogador que colidiu é o localPlayer (este cliente) e ele está na mesma dimensão que o marker e ele não está com status de preso, então:
		if not isInColExport () then -- O resto aqui é o seu script, não entendi...
			guiSetVisible(Window_VS, not guiGetVisible(Window_VS))
			guiSetVisible (Window_CHK, false)
			playSound(":EQPsons/open.wav")
			showCursor(guiGetVisible(Window_VS))
			vehsa = getElementData(localPlayer,"spawnedcars") or {}
			vehs = ""
			for ind,veh in ipairs(vehsa) do
				if vehs ~= "" then 
					vehs = vehs..", "..veh.."" 
				else 
					vehs = vehs..""..veh.."" 
				end
			end
		end
	end
end) -- O theMarker que aparece depois do "onClientMarkerHit" é o marker que vc criou antes, essa função só funciona se colidir naquele marker.

 

Edited by Lord Henry
Link to comment

Obrigado por ajudar amigo, vou explicar pra vocês o que eu estou tentando fazer, seguinte, eu estou com um script de concessionaria e nele tem um painel que mostra os veículos que você tem, porém o que eu quero fazer é criar uma garagem que consiste em abrir esse painel somente em um lugar específico como no caso eu irei colocar no estacionamento ao lado da concessionaria, por isso queria desbindar o F2 e colocar pra abrir somente nesse marker no estacionamento, seria mais ou menos igual a garagem do fivem entende? Esse script eu posso colocar ele direto com as coordenadas certinho que ele irá funcionar?

Link to comment

Amigo eu puz de inicio o codigo no arquivo client.lua que era onde tinha a bind porém o marker não foi criado, daí eu resolvi colar o codigo no server.lua ai o marker criou, porém não abriu o painel, simplesmente não ocorre nada

local theMarker = createMarker (2154.4814453125, -1146.4481201172, 23, "cylinder", 2, 255, 255, 0, 150)
addEventHandler ("onClientMarkerHit" , theMarker, function (thePlayer, matchingDimension)
	if thePlayer == localPlayer and matchingDimension and (not getElementData (localPlayer, "prison")) then
		if not isInColExport () then
			guiSetVisible(Window_VS, not guiGetVisible(Window_VS))
			guiSetVisible (Window_CHK, false)
			playSound(":EQPsons/open.wav")
			showCursor(guiGetVisible(Window_VS))
			vehsa = getElementData(localPlayer,"spawnedcars") or {}
			vehs = ""
			for ind,veh in ipairs(vehsa) do
				if vehs ~= "" then 
					vehs = vehs..", "..veh.."" 
				else 
					vehs = vehs..""..veh.."" 
				end
			end
		end
	end
end)

 

@DNL291Eu usei a sua linha de código funcionou mano porém ele não fecha saca, tem como por pra fechar de alguma forma?

Link to comment
  • Moderators

O código do createMarker está certo, deveria funcionar no client, mostre o seu meta.xml.

4 hours ago, PauloWillami said:

@DNL291Eu usei a sua linha de código funcionou mano porém ele não fecha saca, tem como por pra fechar de alguma forma?

A maneira mais lógica que eu faria pra fechar seria com um Botão. Você também pode usar o onClientMarkerLeave pra isso.

Edit: lembre-se de usar o comando debugscript 3 para ver se mostra erros.

Edited by DNL291
Link to comment
19 hours ago, DNL291 said:

O código do createMarker está certo, deveria funcionar no client, mostre o seu meta.xml.

A maneira mais lógica que eu faria pra fechar seria com um Botão. Você também pode usar o onClientMarkerLeave pra isso.

Edit: lembre-se de usar o comando debugscript 3 para ver se mostra erros.

exatamente o que eu queria era esse painel fechar ao passar por cima do marker, pode me passar a linha de codigo? eu me perco totalmente nisso rsrs desculpa incomodar mais uma vez

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