Jump to content

Duvida sobre Vehicle


Recommended Posts

Bom dia, estou fazendo um script que é o seguinte:
Você tem o painel para spawnar as viaturas, e quero colocar um Guardar Veículo, que se o veh estiver no marker "destroy", e o player apertar em guardar veículo, o veículo sumiria, segue uma print de exemplo: https://imgur.com/UDOecOr

Resumindo, quero deixar a viatura no marker, sair dela, ir no marker do painel e apertar guardar veículo..
O client já está arrumado, falta o server:
 

Client Side:

local check = 0; 
local check1 = 0; 

butao1 = "k"
butao2 = "f"


rt1 = 180
rt2 = 0
rt3 = 0
rt4 = 0
rt5 = 0



local arsenal = createMarker(2912.4116210938,-1960.0969238281,11.00625038147-1, "cylinder", 2, 255, 0, 0, 180)
local destroy = createMarker(2912.2587890625,-1969.0013427734,11.00625038147-1, "cylinder", 2, 255, 0, 0, 180)



addEventHandler( "onClientRender", root, function()
       local x, y, z = getElementPosition( arsenal )
       local Mx, My, Mz = getCameraMatrix(   )
        if ( getDistanceBetweenPoints3D( x, y, z, Mx, My, Mz ) <= 20 ) then
           local WorldPositionX, WorldPositionY = getScreenFromWorldPosition( x, y, z +1, 0.07 )
            if ( WorldPositionX and WorldPositionY ) then
			    dxDrawText("Viaturas", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(255, 255, 255, 255), 2.52, "default-bold", "center", "center", false, false, false, false, false)
			--    dxDrawText("Alugue Bikes Aqui!", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(255, 255, 255, 255), 2.50, "default-bold", "center", "center", false, false, false, false, false)
            end
      end
  end)

addEventHandler( "onClientRender", root, function()
       local x, y, z = getElementPosition( destroy )
       local Mx, My, Mz = getCameraMatrix(   )
        if ( getDistanceBetweenPoints3D( x, y, z, Mx, My, Mz ) <= 20 ) then
           local WorldPositionX, WorldPositionY = getScreenFromWorldPosition( x, y, z +1, 0.07 )
            if ( WorldPositionX and WorldPositionY ) then
			    dxDrawText("Destruir", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(255, 255, 255, 255), 2.52, "default-bold", "center", "center", false, false, false, false, false)
			--    dxDrawText("Alugue Bikes Aqui!", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(255, 255, 255, 255), 2.50, "default-bold", "center", "center", false, false, false, false, false)
            end
      end
  end)







function moverrt()
dxDrawRectangle(386, 221, 298, 499, tocolor(62, 64, 66, 255), false)
dxDrawRectangle(386, 222, 298, 75, tocolor(255, 0, 0, rt1), true) -- FECHAR
dxDrawRectangle(386, 313, 298, 75, tocolor(255, 0, 0, rt2), true) -- TRIAL BLAZER
dxDrawRectangle(386, 404, 298, 75, tocolor(255, 0, 0, rt3), true) -- BLAZER
dxDrawRectangle(386, 495, 298, 75, tocolor(255, 0, 0, rt4), true) -- GUARDAR
dxDrawText("FECHAR", 420, 250, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
dxDrawText("TRIAL BLAZER", 420, 330, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
dxDrawText("BLAZER", 420, 330+80, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
dxDrawText("GUARDAR VEICULO", 420, 330+180, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
end




function moverrt2()
if rt1 == 180 then
rt1 = 0
rt2 = 180
elseif rt1 == 0 and rt2 == 180 then
rt2 = 0
rt3 = 180
elseif rt1 == 0 and rt2 == 0 and rt3 == 180 then
rt3 = 0
rt4 = 180
end
end

function moverrt3()
if rt4 == 180 then
rt4 = 0 
rt3 = 180
elseif rt3 == 180 and rt4 == 0 then
rt3 = 0
rt2 = 180
elseif rt3 == 0 and rt2 == 180 then
rt2 = 0
rt1 = 180
elseif rt4 == 180 and rt3 == 0 then
rt4 = 0
rt3 = 180
end
end

bindKey ( "arrow_d", "down", moverrt2 )
bindKey ( "arrow_u", "down", moverrt3)

function tsstar()
local mark = isElementWithinMarker
if rt1 == 180 then
if mark(getLocalPlayer(),arsenal) then
removeEventHandler('onClientRender',root,moverrt);
toggleAllControls(true)
end
end
if mark(getLocalPlayer(),arsenal) then
if rt3 == 180 then
triggerServerEvent("blazer",getLocalPlayer())
removeEventHandler('onClientRender',root,moverrt);
toggleAllControls(true)
end
end
if mark(getLocalPlayer(),arsenal) then
if rt2 == 180 then
triggerServerEvent("trialblazer",getLocalPlayer())
removeEventHandler('onClientRender',root,moverrt);
toggleAllControls(true)
if mark(getLocalPlayer(),arsenal) then
if rt4 == 180 then
triggerServerEvent("guardar",getLocalPlayer())
removeEventHandler('onClientRender',root,moverrt);
toggleAllControls(true)
end
end
end
end
end



bindKey ( "enter", "down", tsstar)

function openAndClose(thePlayer)
if thePlayer == getLocalPlayer() then
if check == 0 then
check = 1;
rt1 = 180
rt2 = 0
rt3 = 0
addEventHandler('onClientRender',root,moverrt)
toggleAllControls(false)
else 
removeEventHandler('onClientRender',root,moverrt)
toggleAllControls(true)
check = 0;
 end
end
end

addEventHandler("onClientMarkerHit",arsenal,openAndClose)




Server side:


local destroy = createMarker(2912.2587890625,-1969.0013427734,11.00625038147-1, "cylinder", 2, 255, 0, 0, 180)

 
 
 function movingMyGateBack ()
local accName = getAccountName(getPlayerAccount(source))
if ( isObjectInACLGroup ("user."..accName, aclGetGroup ( "Policial" ) ) ) then
--if aberto == true then
 moveObject (myGate1, 400, 1566.5546875, -1675.19140625, 16.589937210083 )
 end
 end
 --end
addEvent("abrir2",true)
addEventHandler("abrir2",root,movingMyGateBack)

 -----------------------------------------------------------------------------------------------------------------
 
 -- parte2 ARSENAL
 
 -----------

addEvent("trialblazer",true) 
addEventHandler("trialblazer",root, 
function()
local accName = getAccountName(getPlayerAccount(source))
if ( isObjectInACLGroup ("user."..accName, aclGetGroup ( "Policial" ) ) ) then
veh = createVehicle ( 445,2906.423828125,-1948.9193115234,11.00625038147, -0, 0, 266.15621948242 )
warpPedIntoVehicle ( source, veh )
end
end)

addEvent("blazer",true) 
addEventHandler("blazer",root, 
function()
local accName = getAccountName(getPlayerAccount(source))
if ( isObjectInACLGroup ("user."..accName, aclGetGroup ( "Policial" ) ) ) then
vehs = createVehicle ( 458,2906.423828125,-1950.9193115234,11.00625038147, -0, 0, 266.15621948242 )
warpPedIntoVehicle ( source, vehs )
end
end)

 

Link to comment

Correção: Consegui fazer com que o veículo se destrua, mas quero que apenas dê se o player estiver a pé. Pois o painel funciona com toggleAllControls..
Se eu colocar o seguinte o painel so aparece 1 vez e depois não aparece mais..

   local theVehicle = getPedOccupiedVehicle ( thePlayer )

if not theVehicle then

Segue o codigo do Client:

 

local check = 0; 
local check1 = 0; 

butao1 = "k"
butao2 = "f"


rt1 = 180
rt2 = 0
rt3 = 0
rt4 = 0




local arsenal = createMarker(2912.4116210938,-1960.0969238281,11.00625038147-1, "cylinder", 2, 255, 0, 0, 20)




addEventHandler( "onClientRender", root, function()
       local x, y, z = getElementPosition( arsenal )
       local Mx, My, Mz = getCameraMatrix(   )
        if ( getDistanceBetweenPoints3D( x, y, z, Mx, My, Mz ) <= 10 ) then
           local WorldPositionX, WorldPositionY = getScreenFromWorldPosition( x, y, z +1, 0.07 )
            if ( WorldPositionX and WorldPositionY ) then
			    dxDrawText("Viaturas", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(255, 255, 255, 255), 2.52, "default-bold", "center", "center", false, false, false, false, false)
			--    dxDrawText("Alugue Bikes Aqui!", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(255, 255, 255, 255), 2.50, "default-bold", "center", "center", false, false, false, false, false)
            end
      end
end) 







function moverrt()
dxDrawRectangle(386, 221, 298, 499, tocolor(62, 64, 66, 255), false)
dxDrawRectangle(386, 222, 298, 75, tocolor(255, 0, 0, rt1), true)
dxDrawRectangle(386, 313, 298, 75, tocolor(255, 0, 0, rt2), true)
dxDrawRectangle(386, 404, 298, 75, tocolor(255, 0, 0, rt3), true)
dxDrawRectangle(386, 495, 298, 75, tocolor(255, 0, 0, rt4), true)
dxDrawText("FECHAR", 420, 250, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
dxDrawText("TRIAL BLAZER", 420, 330, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
dxDrawText("BLAZER", 420, 330+80, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
dxDrawText("GUARDAR VEICULO", 420, 330+180, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
dxDrawText("(Use as setas para mover)", 750, 330+180, 563, 355, tocolor(255, 255, 255, 255), 2.00, "sans", "left", "top", false, false, false, false, false)
end




function moverrt2()
if rt1 == 180 then
rt1 = 0
rt2 = 180
elseif rt1 == 0 and rt2 == 180 then
rt2 = 0
rt3 = 180
elseif rt1 == 0 and rt2 == 0 and rt3 == 180 then
rt4 = 180
rt3 = 0
elseif rt1 == 0 and rt2 == 0 and rt3 == 0 and rt4 == 180 then
rt4 = 0
rt1 = 180
end
end

function moverrt3()
if rt4 == 180 then
rt4 = 0 
rt3 = 180
elseif rt3 == 180 and rt4 == 0 then
rt3 = 0
rt2 = 180
elseif rt3 == 0 and rt2 == 180 then
rt2 = 0
rt1 = 180
end
end

bindKey ( "arrow_d", "down", moverrt2 )
bindKey ( "arrow_u", "down", moverrt3)

function tsstar()
local mark = isElementWithinMarker
if rt1 == 180 then
if mark(getLocalPlayer(),arsenal) then
removeEventHandler('onClientRender',root,moverrt);
toggleAllControls(true)
end
end
if mark(getLocalPlayer(),arsenal) then
if rt3 == 180 then
triggerServerEvent("blazer",getLocalPlayer())
removeEventHandler('onClientRender',root,moverrt)
toggleAllControls(true)
end
end
if mark(getLocalPlayer(),arsenal) then
if rt2 == 180 then
triggerServerEvent("trialblazer",getLocalPlayer())
removeEventHandler('onClientRender',root,moverrt)
toggleAllControls(true)
end
end
if mark(getLocalPlayer(),arsenal) then
if rt4 == 180 then
triggerServerEvent("destroy",getLocalPlayer())
removeEventHandler('onClientRender',root,moverrt)
toggleAllControls(true)
end
end
end



bindKey ( "enter", "down", tsstar)
   
   local theVehicle = getPedOccupiedVehicle ( thePlayer )

function notvehicle(thePlayer)
   	if thePlayer == getLocalPlayer() then
		if check == 0 then
		check = 1;
		rt1 = 180
		rt2 = 0
		rt3 = 0
		rt4 = 0 
   	addEventHandler('onClientRender',root,moverrt)
if not theVehicle then
	toggleAllControls(false)
	else
	removeEventHandler('onClientRender',root,moverrt)
	toggleAllControls(true)
	check = 0;
end
end
end
end
addEventHandler("onClientMarkerHit",arsenal,notvehicle)


 

Link to comment

Faça no lado server uma tabela com todos veículos de cada jogador spawnados, gerencie o spawn/despawn por ela.

O recomendado é você usar SQL para o salvamento dos veículo na conta do jogador, daí quando ele logar no jogo você carrega os dados e manda para o lado client para a lista no painel.

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