Jump to content

Ajuda Despawnar carros


Recommended Posts

Olá Bom Día/tarde/noite, Queria saber como faço para os carros dos player sumir quando ele sair do servidor [quit] ou até mesmo quando cai a net dele.

 


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 )

local screX, screY = guiGetScreenSize()

Window_VS = guiCreateWindow(373, 219, 557, 303,"Gerenciado De Seus Carros",false)
guiSetAlpha(Window_VS, 0.88)
guiWindowSetSizable(Window_VS, false)
guiSetVisible(Window_VS, false)
centerWindow(Window_VS)
Grid_VS = guiCreateGridList(10, 28, 361, 235, false, Window_VS)
guiGridListSetSelectionMode(Grid_VS, 1)
guiGridListAddColumn(Grid_VS, "Nome", 0.3)
guiGridListAddColumn(Grid_VS, "Valor", 0.2)
guiGridListAddColumn(Grid_VS, "Status", 0.2)
guiGridListAddColumn(Grid_VS, "Placa", 0.2)

Button_VS_sn_s = guiCreateStaticImage(381, 28, 166, 25, "images/button_standard.png", false, Window_VS)
Button_VS_sn_o = guiCreateStaticImage(381, 28, 166, 25, "images/button_mouse.png", false, Window_VS)
Button_VS_sn = guiCreateLabel(381, 28, 166, 25, "Spawnar", false, Window_VS)
guiSetFont(Button_VS_sn, "default-bold-small")
guiLabelSetColor(Button_VS_sn, 255, 255, 255)
guiLabelSetVerticalAlign(Button_VS_sn, "center")
guiLabelSetHorizontalAlign(Button_VS_sn, "center")
---remover abaixo
Button_VS_bp_s = guiCreateStaticImage(381, 63, 166, 25, "images/button_standard.png", false, Window_VS)
Button_VS_bp_o = guiCreateStaticImage(381, 63, 166, 25, "images/button_mouse.png", false, Window_VS)
Button_VS_bp = guiCreateLabel(381, 63, 166, 25, "Rastrear Auto", false, Window_VS)
guiSetFont(Button_VS_bp, "default-bold-small")
guiLabelSetColor(Button_VS_bp, 255, 255, 255)
guiLabelSetVerticalAlign(Button_VS_bp, "center")
guiLabelSetHorizontalAlign(Button_VS_bp, "center")

Button_VS_lk_s = guiCreateStaticImage(381, 168, 166, 25, "images/button_standard.png", false, Window_VS)
Button_VS_lk_o = guiCreateStaticImage(381, 168, 166, 25, "images/button_mouse.png", false, Window_VS)
Button_VS_lk = guiCreateLabel(381, 168, 166, 25, "Trancar - Destrancar", false, Window_VS)
guiSetFont(Button_VS_lk, "default-bold-small")
guiLabelSetColor(Button_VS_lk, 255, 255, 255)
guiLabelSetVerticalAlign(Button_VS_lk, "center")
guiLabelSetHorizontalAlign(Button_VS_lk, "center")

Button_VS_sl_s = guiCreateStaticImage(381, 203, 166, 25, "images/button_standard.png", false, Window_VS)
Button_VS_sl_o = guiCreateStaticImage(381, 203, 166, 25, "images/button_mouse.png", false, Window_VS)
Button_VS_sl = guiCreateLabel(381, 203, 166, 25, "Vender Veiculo", false, Window_VS)
guiSetFont(Button_VS_sl, "default-bold-small")
guiLabelSetColor(Button_VS_sl, 255, 255, 255)
guiLabelSetVerticalAlign(Button_VS_sl, "center")
guiLabelSetHorizontalAlign(Button_VS_sl, "center")

Button_VS_give_s = guiCreateStaticImage(381, 238, 166, 25, "images/button_standard.png", false, Window_VS)
Button_VS_give_o = guiCreateStaticImage(381, 238, 166, 25, "images/button_mouse.png", false, Window_VS)
Button_VS_give = guiCreateLabel(381, 238, 166, 25, "Vender Para Um Cidad�o", false, Window_VS)
guiSetFont(Button_VS_give, "default-bold-small")
guiLabelSetColor(Button_VS_give, 255, 255, 255)
guiLabelSetVerticalAlign(Button_VS_give, "center")
guiLabelSetHorizontalAlign(Button_VS_give, "center")

adLabel = guiCreateLabel(130, 269, 296, 24, "[BR] Brasil Vida Bela [ROLEPLAY]", false, Window_VS)  -------------- Nome do seu servidor
guiSetFont(adLabel, "default-bold-small")
guiLabelSetHorizontalAlign(adLabel, "center", false)
guiLabelSetVerticalAlign(adLabel, "center")

guiSetVisible(Button_VS_sn_o,false)--
guiSetVisible(Button_VS_lk_o,false)
guiSetVisible(Button_VS_sl_o,false)
guiSetVisible(Button_VS_give_o,false)

--Button_VS_Warp_info
--Button_VS_Fix_info


Window_CHK = guiCreateWindow(screX/2-155,screY/2-60,310,120,"Vender Para Loja",false)
guiSetVisible(Window_CHK, false)
guiSetProperty(Window_CHK, "AlwaysOnTop", "true")
guiWindowSetSizable(Window_CHK, false)
Label_CHK = guiCreateLabel(21,28,266,36,"",false,Window_CHK)
guiLabelSetColor(Label_CHK, 38, 122, 216)
guiLabelSetHorizontalAlign(Label_CHK,"center",true)
Button_CHK_Y = guiCreateButton(17,73,129,36,"Deseja Vender?",false,Window_CHK)
Button_CHK_N = guiCreateButton(161,73,129,36,"Cancelar",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 = customCarNames[ data['Model'] ] or getVehicleNameFromModel(data["Model"])
			local ID = data["ID"]
			local Cost = data["Cost"]
			local Placa = data["Placa"]
			local HP = math.floor(data["HP"])
			local PreCost = math.ceil(Cost*.9*HP/100/10)
			local row = guiGridListAddRow(Grid_VS)
			guiGridListSetItemText(Grid_VS, row, 1, carName, false, true)
			guiGridListSetItemData(Grid_VS, row, 1, ID)
			guiGridListSetItemText(Grid_VS, row, 2, PreCost, false, true)
			guiGridListSetItemText(Grid_VS, row, 3, HP.." HP", false, true)
			guiGridListSetItemText(Grid_VS, row, 4, Placa, false, true)
		end
		guiGridListSetSelectedItem(Grid_VS, rw, cl)
	end
end



bindKey("F6", "down",
function()
if getElementInterior(localPlayer) == 0 and getElementDimension(localPlayer) == 0 then
if getElementData(localPlayer, "MissionWarProtection") and getElementData(localPlayer, "MissionProtection")then return end
    guiSetVisible(Window_VS, not guiGetVisible(Window_VS))
	guiSetVisible (Window_CHK, false)
	showCursor(guiGetVisible(Window_VS))
	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, 1)
	if source == Button_VS_close then
		guiSetVisible(Window_VS, false)
		showCursor(false)
	end
	if (source == Grid_VS) then
		if id == -1 and idd then
			guiGridListSetSelectedItem(Grid_VS, idd, 1)
			return false
		else
			idd = guiGridListGetSelectedItem(Grid_VS)
		end
	elseif id == -1 then
	elseif (source == Button_VS_sn) then
	if not isInColExport () then
		triggerServerEvent("SpawnMyVehicle", localPlayer, ID)
                end
	elseif (source == Button_VS_dy) then
		triggerServerEvent("DestroyMyVehicle", localPlayer, ID)
	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), 2)
		guiSetText(Label_CHK, 'Voc� deseja realmente vender seu "'..carName..'" por $'..carprice)
	elseif source == Button_VS_give then
		createPlayersList(id)
	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
	elseif source == Button_VS_Fix then
		triggerServerEvent("FixMyVehicle", localPlayer, ID)
	elseif source == Button_VS_Warp then
	       if not isInColExport () then
		triggerServerEvent("WarpMyVehicle", localPlayer, ID)
                      end
	elseif source == Button_PLS_Y then
		local row = guiGridListGetSelectedItem ( playerList_PLS )
		if row and row ~= -1 then
			-- if guiGridListGetItemText ( playerList_PLS, row, 1 ) == getPlayerName ( localPlayer ) then
				-- return true
			-- end
			if (tonumber(guiGetText (edit_PLS_price)) or 0) >= 0 then
				outputMessage ( "#c1c1c1Esperar uma resposta do jogador.", 10, 250, 10,true )
				invitations_send = true
				triggerServerEvent ( 'inviteToBuyCarSended', localPlayer, guiGridListGetItemText ( playerList_PLS, row, 1 ), guiGetText (edit_PLS_price) or 0, guiGridListGetItemText(Grid_VS, id, 1), guiGridListGetItemData(Grid_VS, id, 1) )
				destroyElement ( Window_PLS )
			end
		end
	elseif source == Button_PLS_N then
		destroyElement ( Window_PLS)
	end
end
addEventHandler("onClientGUIClick", resourceRoot, WINDOW_CLICK_VEHICLE)

function invitationsClickVehicle ()
	if source == Button_ABC_Y then
		showCursor ( false )
		destroyElement ( Window_ABC )
		if getPlayerMoney () >= ( tonumber(inv_price) or 0 ) then
			triggerServerEvent ("invitationBuyCarAccepted",localPlayer, inv_player, inv_acc, inv_price, inv_veh_name, inv_veh_id)
		else
			triggerServerEvent ("invitationBuyCarNotAccepted",localPlayer, inv_player )
		end
		if #listOfInvitations > 0 then
			createAcceptBuyCarWindow (listOfInvitations[1][1],listOfInvitations[1][2],listOfInvitations[1][3],listOfInvitations[1][4] )
			table.remove (listOfInvitations,1)
		end
	elseif source == Button_ABC_N then
		showCursor ( false )
		triggerServerEvent ("invitationBuyCarNotAccepted",localPlayer, inv_player )
		destroyElement ( Window_ABC )
		if #listOfInvitations > 0 then
			createAcceptBuyCarWindow (listOfInvitations[1][1],listOfInvitations[1][2],listOfInvitations[1][3],listOfInvitations[1][4] )
			table.remove (listOfInvitations,1)
		end
	end
end

addEventHandler("onClientGUIClick", resourceRoot, invitationsClickVehicle)

function createPlayersList (row_id)
	showCursor ( true )
	Window_PLS = guiCreateWindow(screX/2-155,screY/2-220,310,420,"Venda de carros!",false)
	guiSetVisible(Window_PLS, true)
	guiSetProperty(Window_PLS, "AlwaysOnTop", "true")
	guiWindowSetSizable(Window_PLS, false)
	Label_PLS_info = guiCreateLabel(21,28,266,36,"Digite o preco dos carros:",false,Window_PLS)
	edit_PLS_price = guiCreateEdit ( 110,58,90,36, guiGridListGetItemText(Grid_VS, row_id, 2) or 0, false, Window_PLS )
	guiLabelSetColor(Label_PLS_info, 38, 122, 216)
	guiLabelSetHorizontalAlign(Label_PLS_info,"center",true)
	Button_PLS_Y = guiCreateButton(17,379,129,36,"Vender",false,Window_PLS)
	Button_PLS_N = guiCreateButton(161,379,129,36,"Fechar",false,Window_PLS)
	addEventHandler("onClientGUIChanged", edit_PLS_price, function(element)
		guiSetText ( edit_PLS_price, string.gsub (guiGetText( edit_PLS_price ), "%a", "") )
	end)
	playerList_PLS = guiCreateGridList ( 21, 100, 268, 265, false, Window_PLS )
	local column = guiGridListAddColumn( playerList_PLS, "Cidadao", 0.85 )
	if ( column ) then
		for id, player in ipairs(getElementsByType("player")) do
			local row = guiGridListAddRow ( playerList_PLS )
			guiGridListSetItemText ( playerList_PLS, row, column, getPlayerName ( player ), false, false )
		end
	end

end

--createPlayersList ()

listOfInvitations = {}
inv_player, inv_acc, inv_price, inv_veh_name, inv_veh_id = nil, nil, nil, nil, nil


addEvent("recieveInviteToBuyCar", true)
addEventHandler("recieveInviteToBuyCar", root,
function(player, acc, price, veh_name, veh_id)
	if player and price and acc and veh_name and veh_id then
		if getPlayerFromName ( player ) then
			if not isElement ( Window_ABC ) then
				createAcceptBuyCarWindow (player,acc,price, veh_name, veh_id)
			else
				table.insert ( listOfInvitations, {player,acc,price, veh_name, veh_id})
			end
		else
			outputMessage ( "#c1c1c1Cidad�o n�o pode ser encontrado", source, 250, 10, 10,true)
		end
	end
end)

addEvent("cleanCarInvitations", true)
addEventHandler("cleanCarInvitations", root,
function()
	invitations_send = false
end)

function createAcceptBuyCarWindow(player,acc,price, veh_name, veh_id)
	showCursor ( true )
	inv_player, inv_acc, inv_price, inv_veh_name, inv_veh_id = player,acc,price, veh_name, veh_id
	Window_ABC = guiCreateWindow(screX/2-155,screY/2-220,410,100,"Venda de carros",false)
	guiSetVisible(Window_ABC, true)
	guiSetProperty(Window_ABC, "AlwaysOnTop", "true")
	guiWindowSetSizable(Window_ABC, false)
	Label_ABC_info = guiCreateLabel(10,28,390,36,player.." Te ofereceu o "..veh_name.." por "..price.."$ (o seu dinheiro: "..getPlayerMoney() .."$)",false,Window_ABC)
	guiLabelSetColor(Label_ABC_info, 38, 216, 38)
	guiLabelSetHorizontalAlign(Label_ABC_info,"center",true)
	Button_ABC_Y = guiCreateButton(17,70,129,36,"Comprar",false,Window_ABC)
	Button_ABC_N = guiCreateButton(264,70,129,36,"Cancelar",false,Window_ABC)
end

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

ShopMarkersTable = {}

local ShopTable = {
	[1] = {ID = {{405, 10000}
            ,{560, 13000}
            ,{516, 55000}
            ,{415, 99000}
            ,{547, 58000}
            ,{422, 55000}
            ,{602, 93000}
            ,{579, 125000}
            ,{554, 15000}
            ,{542, 165000}
            ,{411, 7500000}
            ,{491, 16750}
            ,{502, 20522000}
            ,{600, 58000}
}, vPosX = 2134, vPosY = -1170, vPosZ = 28.15, PosX = 2133, PosY = -1149, PosZ = 23.4, CamX = 2134.1, CamY = -1160, CamZ = 35, lookAtX = 2133.3, lookAtY = -1168, lookAtZ = 28},
	[2] = {ID = {{462, 1500}
            ,{581, 5000}
            ,{461, 10000}
            ,{522, 20000}
            ,{468, 30000}
            ,{586, 40000}
            ,{521, 50000}
            ,{463, 60000}
            ,{461, 33900}
}, vPosX = 552, vPosY = -1288, vPosZ = 18, PosX = 562, PosY = -1270, PosZ = 16, CamX = 552, CamY = -1275.82, CamZ = 21.61, lookAtX = 552, lookAtY = -1276.77, lookAtZ = 21.29},
	[3] = {ID = {{410, 7000}
	    ,{422, 25000}
            ,{585, 35000}
            ,{546, 50000}
            ,{492, 60000}
            ,{404, 70000}
            ,{458, 90000}
            ,{445, 100000}
            ,{579, 120000}
            ,{405, 150000}
            ,{475, 200000}
            ,{480, 300000}
            ,{602, 700000}
}, vPosX = 1942.5, vPosY = 2052, vPosZ = 11, PosX = 1946, PosY = 2068, PosZ = 10, CamX = 1930.36, CamY = 2052.78, CamZ = 14.71, lookAtX = 1931.36, lookAtY = 2052.78, lookAtZ = 14.43},
	[4] = {ID = {{400, 500000}
            ,{429, 500000}
            ,{479, 500000}
            ,{567, 500000}
}, vPosX = -1950, vPosY = 266, vPosZ = 36.2, PosX = -1935, PosY = 247, PosZ = 34, CamX = -1960.18, CamY = 266.06, CamZ = 37.94, lookAtX = -1959.2, lookAtY = 266.06, lookAtZ = 37.73},
	[5] = {ID = {{410, 7000}
	    ,{422, 25000}
            ,{585, 35000}
            ,{546, 50000}
            ,{492, 60000}
            ,{404, 70000}
            ,{458, 90000}
            ,{445, 100000}
            ,{579, 120000}
            ,{405, 150000}
            ,{475, 200000}
            ,{480, 300000}
            ,{602, 700000}
}, vPosX = -1660, vPosY = 1213, vPosZ = 7, PosX = -1634, PosY = 1199, PosZ = 6, CamX = -1648.9, CamY = 1212.27, CamZ = 10.16, lookAtX = -1649.88, lookAtY = 1212.27, lookAtZ = 9.94}
}

VehicleShop_Window = guiCreateWindow(screX-350,screY-450, 343, 436, "VENDA DE VEICULOS", false)
guiSetVisible(VehicleShop_Window, false)
guiWindowSetSizable(VehicleShop_Window , false)
guiSetAlpha(VehicleShop_Window, 0.8)
carGrid = guiCreateGridList(9, 20, 324, 329, false, VehicleShop_Window)
guiGridListSetSelectionMode(carGrid, 0)
carColumn = guiGridListAddColumn(carGrid, "Nome", 0.5)
costColumn = guiGridListAddColumn(carGrid, "Valor", 0.4)


carButton_s = guiCreateStaticImage(14, 355, 86, 56, "images/button_standard.png", false, VehicleShop_Window)
carButton_o = guiCreateStaticImage(14, 355, 86, 56, "images/button_mouse.png", false, VehicleShop_Window)

carButton = guiCreateLabel(14, 355, 86, 56, "Comprar", false, VehicleShop_Window)
guiSetFont(carButton, "default-bold-small")
guiLabelSetColor(carButton, 255, 255, 255)
guiLabelSetVerticalAlign(carButton, "center")
guiLabelSetHorizontalAlign(carButton, "center")




carColorButton_s = guiCreateStaticImage(128, 355, 86, 56, "images/button_standard.png", false, VehicleShop_Window)
carColorButton_o = guiCreateStaticImage(128, 355, 86, 56, "images/button_mouse.png", false, VehicleShop_Window)

carColorButton = guiCreateLabel(128, 355, 86, 56, "Cor", false, VehicleShop_Window)
guiSetFont(carColorButton, "default-bold-small")
guiLabelSetColor(carColorButton, 255, 255, 255)
guiLabelSetVerticalAlign(carColorButton, "center")
guiLabelSetHorizontalAlign(carColorButton, "center")


closeButton_s = guiCreateStaticImage(237, 355, 86, 56, "images/button_standard.png", false, VehicleShop_Window)
closeButton_o = guiCreateStaticImage(237, 355, 86, 56, "images/button_mouse.png", false, VehicleShop_Window)

closeButton = guiCreateLabel(237, 355, 86, 56, "Sair", false, VehicleShop_Window)
guiSetFont(closeButton, "default-bold-small")
guiLabelSetColor(closeButton, 255, 255, 255)
guiLabelSetVerticalAlign(closeButton, "center")
guiLabelSetHorizontalAlign(closeButton, "center")




guiSetVisible(carButton_o,false)
guiSetVisible(closeButton_o,false)
guiSetVisible(carColorButton_o,false)


addEventHandler( "onClientMouseLeave", root,
function()
	if source == Button_VS_sn then
		guiSetVisible(Button_VS_sn_s,true)
		guiSetVisible(Button_VS_sn_o,false)
	elseif source == Button_VS_dy then
		guiSetVisible(Button_VS_dy_s,true)
		guiSetVisible(Button_VS_dy_o,false)
	elseif source == Button_VS_Warp then
		guiSetVisible(Button_VS_Warp_s,true)
		guiSetVisible(Button_VS_Warp_o,false)
		guiSetVisible(Button_VS_Warp_info,false)
	elseif source == Button_VS_Fix then
		guiSetVisible(Button_VS_Fix_s,true)--Button_VS_Fix_info
		guiSetVisible(Button_VS_Fix_o,false)
		guiSetVisible(Button_VS_Fix_info,false)
	elseif source == Button_VS_lk then
		guiSetVisible(Button_VS_lk_s,true)
		guiSetVisible(Button_VS_lk_o,false)
	elseif source == Button_VS_sl then
		guiSetVisible(Button_VS_sl_s,true)
		guiSetVisible(Button_VS_sl_o,false)
	elseif source == Button_VS_give then
		guiSetVisible(Button_VS_give_s,true)
		guiSetVisible(Button_VS_give_o,false)

	elseif source == carButton then
		guiSetVisible(carButton_s,true)
		guiSetVisible(carButton_o,false)
	elseif source == closeButton then
		guiSetVisible(closeButton_s,true)
		guiSetVisible(closeButton_o,false)
	elseif source == carColorButton then
		guiSetVisible(carColorButton_s,true)
		guiSetVisible(carColorButton_o,false)
	end
end)

addEventHandler( "onClientMouseEnter", root,
function()
	if source == Button_VS_sn then
		guiSetVisible(Button_VS_sn_s,false)
		guiSetVisible(Button_VS_sn_o,true)
	elseif source == Button_VS_dy then
		guiSetVisible(Button_VS_dy_s,false)
		guiSetVisible(Button_VS_dy_o,true)
	elseif source == Button_VS_Warp then
		guiSetVisible(Button_VS_Warp_s,false)
		guiSetVisible(Button_VS_Warp_o,true)
		guiSetVisible(Button_VS_Warp_info,true)
	elseif source == Button_VS_Fix then
		guiSetVisible(Button_VS_Fix_s,false)--Button_VS_Fix_info
		guiSetVisible(Button_VS_Fix_o,true)
		guiSetVisible(Button_VS_Fix_info,true)
	elseif source == Button_VS_lk then
		guiSetVisible(Button_VS_lk_s,false)
		guiSetVisible(Button_VS_lk_o,true)
	elseif source == Button_VS_sl then
		guiSetVisible(Button_VS_sl_s,false)
		guiSetVisible(Button_VS_sl_o,true)
	elseif source == Button_VS_give then
		guiSetVisible(Button_VS_give_s,false)
		guiSetVisible(Button_VS_give_o,true)
	elseif source == Button_VS_give then
		guiSetVisible(Button_VS_give_s,false)
		guiSetVisible(Button_VS_give_o,true)

	elseif source == carButton then
		guiSetVisible(carButton_s,false)
		guiSetVisible(carButton_o,true)
	elseif source == closeButton then
		guiSetVisible(closeButton_s,false)
		guiSetVisible(closeButton_o,true)
	elseif source == carColorButton then
		guiSetVisible(carColorButton_s,false)
		guiSetVisible(carColorButton_o,true)
	end
end)



for i, M in ipairs(ShopTable) do
	ShopMarker = createMarker(M["PosX"], M["PosY"], M["PosZ"], "cylinder", 2, 38, 122, 216)
	ShopMarkerShader = createMarker(M["PosX"], M["PosY"], M["PosZ"], "cylinder", 2, 38, 122, 216)
	ShopMarkersTable[ShopMarker] = true
	setElementData ( ShopMarker, "shopID", i )
	setElementID(ShopMarker, tostring(i))
	createBlipAttachedTo(ShopMarker, 55, 2, 255, 255, 255, 255, 0, 400)
end

function getVehicleModelFromNewName (name)
	for i,v in pairs ( customCarNames ) do
		if v == name then
			return i
		end
	end
	return false
end

addEventHandler("onClientGUIClick", resourceRoot,
function()
	if (source == carGrid) then
		local carName = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 1)
		local carprice = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 2)
		if guiGridListGetSelectedItem(carGrid) ~= -1 then
			guiSetText(CarName, carName)
			guiSetText(CarPrice, "$"..carprice)
			local carID = getVehicleModelFromNewName(carName) or getVehicleModelFromName(carName)
			if isElement(veh) then
				setElementModel(veh, carID)
			return end
			veh = createVehicle(carID, ShopTable[i]["vPosX"], ShopTable[i]["vPosY"], ShopTable[i]["vPosZ"])
			setVehicleDamageProof(veh, true)
			setElementFrozen(veh, true)
			setVehicleColor(veh, r1, g1, b1, r2, g2, b2)
			timer = setTimer(function() local x, y, z = getElementRotation(veh) setElementRotation(veh, x, y, z+3) end, 50, 0)
		else
			guiSetText(CarName, "Noun")
			guiSetText(CarPrice, "Noun")
			r1, g1, b1, r2, g2, b2 = math.random(0, 255), math.random(0, 255), math.random(0, 255), math.random(0, 255), math.random(0, 255), math.random(0, 255)
			if isElement(veh) then
				destroyElement(veh)
			end
			if isTimer(timer) then
				killTimer(timer)
			end
		end
		elseif (source == carColorButton) then
		openColorPicker()
	elseif (source == carButton) then
		if guiGridListGetSelectedItem(carGrid) then
			local carName = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 1)
			local carID = getVehicleModelFromNewName(carName) or getVehicleModelFromName(carName)
			local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem(carGrid), 2)
			local r1, g1, b1, r2, g2, b2 = getVehicleColor(veh, true)
			triggerServerEvent("onBuyNewVehicle", localPlayer, carID, carCost, r1, g1, b1, r2, g2, b2)
			outputMessage("#c1c1c1Voc� Acabou De Adquirir: #00FF66"..carName, 38, 122, 216, true)
			guiSetVisible(VehicleShop_Window, false)
			showCursor(false)
			setElementFrozen(localPlayer, false)
			fadeCamera(false, 1.0)
			setTimer(function() fadeCamera(true, 0.5) setCameraTarget(localPlayer) end, 1000, 1)
			if isElement(veh) then
				destroyElement(veh)
			end
			if isTimer(timer) then
				killTimer(timer)
			end
		end
	elseif (source == closeButton) then
		if guiGetVisible(VehicleShop_Window) then
			guiSetVisible(VehicleShop_Window, false)
			showCursor(false)
			setElementFrozen(localPlayer, false)
			fadeCamera(false, 1.0)
			setElementData ( localPlayer, "atVehShop", false)
			setTimer(function() fadeCamera(true, 0.5) setCameraTarget(localPlayer) end, 1000, 1)
			if isElement(veh) then
				destroyElement(veh)
			end
			if isTimer(timer) then
				killTimer(timer)
			end
		end
	end
end)

function openColorPicker()
	if (colorPicker.isSelectOpen) or not isElement(veh) then return end
	colorPicker.openSelect(colors)
end

function closedColorPicker()
end

function updateColor()
	if (not colorPicker.isSelectOpen) then return end
	local r, g, b = colorPicker.updateTempColors()
	if (veh and isElement(veh)) then
		r1, g1, b1, r2, g2, b2 = getVehicleColor(veh, true)
		if (guiCheckBoxGetSelected(checkColor1)) then
			r1, g1, b1 = r, g, b
		end
		if (guiCheckBoxGetSelected(checkColor2)) then
			r2, g2, b2 = r, g, b
		end
		setVehicleColor(veh, r1, g1, b1, r2, g2, b2)
	end
end
addEventHandler("onClientRender", root, updateColor)

--[[addCommandHandler("xx", function()
	local x, y, z, lx, ly, lz = getCameraMatrix()
	setCameraMatrix(x, y, z, lx, ly, lz)
	outputChatBox(x..", "..y..", "..z..", "..lx..", "..ly..", "..z)
end)]]

addEventHandler("onClientMarkerHit", resourceRoot,
function(player)
	if getElementType(player) ~= "player" or player ~= localPlayer or isPedInVehicle(player) then return end
	if ShopMarkersTable[source] then
		i = tonumber(getElementID(source))
		guiGridListClear(carGrid)
		for i, v in ipairs(ShopTable[i]["ID"]) do
			local carName = customCarNames[ v[1] ] or getVehicleNameFromModel(v[1])
			local row = guiGridListAddRow(carGrid)
			guiGridListSetItemText(carGrid, row, 1, carName, false, true)
			guiGridListSetItemText(carGrid, row, 2, tostring(v[2]), false, true)
		end
		setCameraMatrix(ShopTable[i]["CamX"], ShopTable[i]["CamY"], ShopTable[i]["CamZ"], ShopTable[i]["lookAtX"], ShopTable[i]["lookAtY"], ShopTable[i]["lookAtZ"])
		guiSetVisible(VehicleShop_Window, true)
		showCursor(true)
		setElementData ( player, "atVehShop", getElementData ( source, "shopID"))
		guiGridListSetSelectedItem(carGrid, 0, 1)
		setTimer(function()
			setElementFrozen(localPlayer, true)
			local carName = guiGridListGetItemText(carGrid, 0, 1)
			local carID = getVehicleModelFromNewName(carName) or getVehicleModelFromName(carName)
			local x, y, z = ShopTable[i]["vPosX"], ShopTable[i]["vPosY"], ShopTable[i]["vPosZ"]
			if isElement(veh) then
				destroyElement(veh)
			end
			if isTimer(timer) then
				killTimer(timer)
			end
			r1, g1, b1, r2, g2, b2 = math.random(0, 255), math.random(0, 255), math.random(0, 255), math.random(0, 255), math.random(0, 255), math.random(0, 255)
			veh = createVehicle(carID, x, y, z)
			setVehicleDamageProof(veh, true)
			setElementFrozen(veh, true)
			setVehicleColor(veh, r1, g1, b1, r2, g2, b2)
			timer = setTimer(function() local x, y, z = getElementRotation(veh) setElementRotation(veh, x, y, z+3) end, 50, 0)
		end, 100, 1)
	end
end)

addEventHandler("onClientRender", getRootElement(), function()
	local x2, y2, z2 = getElementPosition(localPlayer)
	for index, car in pairs(getElementsByType('vehicle')) do
			local x, y, z = getElementPosition(car)
			z = z+1
			local sx, sy = getScreenFromWorldPosition(x, y, z)
			if(sx) and (sy) then
				local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
				if(distance < 10) then
					local fontbig = 1-(distance/10)
					local owner = getElementData(car,"Placa") or getVehiclePlateText(car)
					local id = getElementData(car,"ID")
					local fria = getVehiclePlateText(car)
					if(owner) then
						dxDrawBorderedCarText(""..(owner), sx, sy+20, sx, sy, tocolor(0, 0, 0),1.5, fontbig, "", "center")
						dxDrawBorderedCarText(""..(owner), sx+2, sy+22, sx, sy, tocolor(255, 255, 255),1.5, fontbig, "", "center")
				end
			end
		end
	end

	for i, v in ipairs ( ShopTable ) do
		local sx, sy = getScreenFromWorldPosition(v.PosX, v.PosY, v.PosZ+1)
		if(sx) and (sy) then
			local distance = getDistanceBetweenPoints3D ( x2, y2, z2,v.PosX, v.PosY, v.PosZ )
			if distance < 30 then
				local fontbig = 3-(distance/10)
				--dxDrawBorderedCarText("", sx, sy, sx, sy, tocolor(212, 179, 17, 200), fontbig, "default-bold", "center")
			end
		end
	end

end)

function dxDrawBorderedCarText( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI )
	dxDrawText ( text, x - 1, y - 1, w - 1, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x + 1, y - 1, w + 1, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x - 1, y + 1, w - 1, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x + 1, y + 1, w + 1, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x - 1, y, w - 1, h, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x + 1, y, w + 1, h, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x, y - 1, w, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x, y + 1, w, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI )
end


function outputMessage (text, r, g, b)
	return exports["scr-Lib"]:outputMessage(text, r, g, b);
end

--[[
SISTEMA REESTRUTURADO

		POR

	 Baron_Scr*
  AL.LobaoAS*#6049

--]]








local customCarNames =

{
    [516] = 'Saveiro';
    [545] = 'Fusca';
    [560] = 'Gol G3';
    [415] = 'Jetta TSI';
    [405] = 'Cruze';
    [586] = 'Kawasaki VN900';
    [448] = 'Pegeot 103' ;
    [461] = 'CBR 1000rr' ;
    [468] = 'XT600' ;
    [522] = 'XJ6 Turbo' ;
    [462] = 'Honda Vario' ;
    [581] = 'Honda Twister' ;
    [463] = 'Harley Davidson' ;
    [521] = 'Kawasaki Ninja H2R' ;
    [547] = 'Sonata' ;
    [422] = 'Saveiro com som' ;
    [602] = 'Mitsubishi' ;
    [579] = 'Santa Fé' ;
    [554] = 'Chevette' ;
    [542] = 'Opala SS' ;
    [550] = 'CELTA' ;
    [411] = 'MClaren P1' ;
    [424] = 'Bandito';
    [477] = 'Nissan Drift Monster';
    [409] = 'Minigin Limousine';
    [400] = 'Insurgent';



}


function getVehicleRealName(model)
	for k, v in ipairs(customCarNames) do
		if v[1] == model then
			return v[2]
		end
	end
	return "Desconhecido"
end

shopsVehSpawns = {
	[1] = { 2131, -1133, 25.6, 0,0,359 },
	[2] = { 555, -1278, 18, 0,0,100 },
	[3] = { 1941, 2097, 10.8, 0,0,350 },
	[4] = { -1988, 272, 36, 0,0,259 },
	[5] = { -1642, 1213, 7.17, 0,0, 227 },
}

function getFreeID()
	local result = dbPoll(dbQuery(db, "SELECT ID FROM VehicleList ORDER BY ID ASC"), -1)
	newID = false
	for i, id in pairs (result) do
		if id["ID"] ~= i then
			newID = i
			break
		end
	end
	if newID then return newID else return #result + 1 end
end

function getFreePlate(vehicle, NewID, source)
	local str = "ABCDEFGHIJKLMNPQRSTUVXWYZ"
    local plate = ""
    for index = 1, 3 do
        plate = plate .. string.char(str:byte(math.random(1, #str)))
    end
	plate = string.upper(plate)
    plate = plate .. ""
	for index = 1, 1 do
        plate = plate .. math.random(1, 9)
    end
    for index = 1, 1 do
        plate = plate .. string.char(str:byte(math.random(1, #str)))
    end
	for index = 1, 2 do
        plate = plate .. math.random(1, 9)
    end

	setVehiclePlateText(vehicle, plate)
	setElementData(vehicle,"Placa",plate)
	dbExec(db, "UPDATE VehicleList SET Placa=? WHERE Account=? AND ID=?", plate, getAccountID(getPlayerAccount(source)),tonumber(NewID))
end

function getFreePlate2(source)
  local theVehicle = getPedOccupiedVehicle ( source )
   if theVehicle then
	local str = "ABCDEFGHIJKLMNPQRSTUVXWYZ"
    local plate = ""
    for index = 1, 3 do
        plate = plate .. string.char(str:byte(math.random(1, #str)))
    end
	plate = string.upper(plate)
    plate = plate .. ""
	for index = 1, 1 do
        plate = plate .. math.random(1, 9)
    end
    for index = 1, 1 do
        plate = plate .. string.char(str:byte(math.random(1, #str)))
    end
	for index = 1, 2 do
        plate = plate .. math.random(1, 9)
    end

	setVehiclePlateText(theVehicle, plate)
		end
	end
addEventHandler("onVehicleEnter",getRootElement(), getFreePlate2)

function getVehicleByID(id)
	v = false
	for i, veh in ipairs (getElementsByType("vehicle")) do
		if getElementData(veh, "ID") == id then
			v = veh
			break
		end
	end
	return v
end

function getVehicleByPlate(Placa)
	v = false
	for i, veh in ipairs (getElementsByType("vehicle")) do
		if getElementData(veh, "Placa") == Placa then
			v = veh
			break
		end
	end
	return v
end

function updateVehicleInfo(player)
	if isElement(player) then
		local result = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ?", getAccountID(getPlayerAccount(player))), -1)
		if type(result) == "table" then
			setElementData(player, "VehicleInfo", result)
		end
	end
end

addEventHandler("onResourceStart", resourceRoot,
function()
	db = dbConnect("sqlite", "database.db")
	dbExec(db, "CREATE TABLE IF NOT EXISTS VehicleList (ID, Placa, Account, Model, X, Y, Z, RotZ, Colors, Upgrades, Paintjob, Cost, HP, new_hydr)")
	for i, player in ipairs(getElementsByType("player")) do
		updateVehicleInfo(player)
	end
end)

addEvent("onOpenGui", true)
addEventHandler("onOpenGui", root,
function()
	updateVehicleInfo(source)
end)



addEvent("onBuyNewVehicle", true)
addEventHandler("onBuyNewVehicle", root,
function(Model, cost, r1, g1, b1, r2, g2, b2)
	abc = false
	local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ?", getAccountID(getPlayerAccount(source))), -1)
	for i, data in ipairs (data) do
		if data["Model"] == Model then
			abc = true
			break
		end
	end
	if #data >= 20 then outputMessage("#838B83[#FFFF00BcV#838B83]#FFFF00 Voce Pode Comprar Apenas 20 Veiculos.", source, 38, 122, 216, true) return end
	if abc then outputMessage("#c1c1c1Você já tem este veiculo.", source, 38, 122, 216, true) return end
	if getPlayerMoney(source) >= tonumber(cost) then
		takePlayerMoney ( source, cost )
		local x, y, z = getElementPosition(source)
		local _, _, rz = getElementRotation(source)
		local shopID = getElementData ( source, "atVehShop")
		local color = r1..","..g1..","..b1..","..r2..","..g2..","..b2
		if shopID and shopsVehSpawns[shopID] then
			vehicle = createVehicle(Model, shopsVehSpawns[shopID][1], shopsVehSpawns[shopID][2], shopsVehSpawns[shopID][3], shopsVehSpawns[shopID][4], shopsVehSpawns[shopID][5], shopsVehSpawns[shopID][6])
		else
			vehicle = createVehicle(Model, x-5, y+5, z, 0, 0, rz)
		end
		setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2)
		setElementData(vehicle, "Owner", source)
		local NewID = getFreeID()
		setElementData(vehicle, "ID", NewID)
		local NewPlate = getFreePlate(vehicle,NewID, source)
		local Placa = getElementData(vehicle,"Placa")
		dbExec(db, "INSERT INTO VehicleList VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", NewID, Placa, getAccountID(getPlayerAccount(source)), Model, x-5, y+5, z, rz, color, "", 3, cost, 1000, 0)
		outputMessage("#c1c1c1Por: #00FF66$"..cost, source, 38, 122, 216, true)
		updateVehicleInfo(source)
		setElementData(vehicle, "ownercar", getAccountID(getPlayerAccount(source)))
		warpPedIntoVehicle ( source, vehicle )
		vv[vehicle] = setTimer(function(source)
			if not isElement(source) then killTimer(vv[source]) vv[source] = nil end
			if isElement(source) and getElementHealth(source) <= 255 then
				setElementHealth(source, 255.5)
				setVehicleDamageProof(source, true)
				setVehicleEngineState(source, false)
			end
		end, 150, 0, vehicle)
		addEventHandler("onVehicleDamage", vehicle,
		function(loss)
			local account = getAccountID(getPlayerAccount(getElementData(source, "Owner")))
			setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source)
		end)
		addEventHandler("onVehicleEnter", vehicle,
		function(player)
			if getElementHealth(source) <= 255.5 then
				setVehicleEngineState(source, false)
			else
				if isVehicleDamageProof(source) then
					setVehicleDamageProof(source, false)
				end
			end
		end)
	else
		exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00BvB#838B83]#FFFF00 Voce Não Tem Dinheiro Pra Comprar Esse Veiculo", source, 38, 122, 216, true)
	end
end)

vv = {}

addEvent("SpawnMyVehicle", true)
addEventHandler("SpawnMyVehicle", root,
function(id)
	local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountID(getPlayerAccount(source)), id), -1)
	if type(data) == "table" and #data ~= 0 then
		if getVehicleByID(id) then
			outputMessage("#c1c1c1O seu veiculo #00FF66"..(customCarNames[data[1]["Model"]] or getVehicleNameFromModel(data[1]["Model"])).." #c1c1c1já está spawnado.", source, 38, 122, 216, true)
		else
			local color = split(data[1]["Colors"], ',')
			r1 = color[1] or 255
			g1 = color[2] or 255
			b1 = color[3] or 255
			r2 = color[4] or 255
			g2 = color[5] or 255
			b2 = color[6] or 255
			vehicle = createVehicle(data[1]["Model"], data[1]["X"], data[1]["Y"], data[1]["Z"], 0, 0, data[1]["RotZ"])
			setElementData(vehicle, "ID", id)
			local upd = split(tostring(data[1]["Upgrades"]), ',')
			for i, upgrade in ipairs(upd) do
				addVehicleUpgrade(vehicle, upgrade)
			end
			local Paintjob = data[1]["Paintjob"] or 3
			setVehiclePaintjob(vehicle, Paintjob)
			setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2)
			if tonumber(data[1]["HP"]) <= 255.5 then data[1]["HP"] = 255 end
			if data[1]["new_hydr"] and data[1]["new_hydr"] == 1 then
				setElementData(vehicle, "NewHydr", true)
			else
				setElementData(vehicle, "NewHydr", false)
			end
			setElementData(vehicle, "ownercar", getAccountID(getPlayerAccount(source)))
			Placa = data[1]["Placa"]
			setElementData(vehicle, "Placa",Placa)
			setElementHealth(vehicle, data[1]["HP"])
			setElementData(vehicle, "Owner", source)
			vv[vehicle] = setTimer(function(source)
				if not isElement(source) then killTimer(vv[source]) vv[source] = nil end
				if isElement(source) and getElementHealth(source) <= 255 then
					setElementHealth(source, 255.5)
					setVehicleDamageProof(source, true)
					setVehicleEngineState(source, false)
				end
			end, 50, 0, vehicle)
			addEventHandler("onVehicleDamage", vehicle,
			function(loss)
				local account = getAccountID(getPlayerAccount(getElementData(source, "Owner")))
				setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source)
			end)
			addEventHandler("onVehicleEnter", vehicle,
			function(player)
				if getElementHealth(source) <= 255.5 then
					setVehicleEngineState(source, false)
				else
					if isVehicleDamageProof(source) then
						setVehicleDamageProof(source, false)
					end
				end
			end)
			exports.Scripts_Dxmessages:outputDx(source, "#c1c1c1O seu veiculo #00FF66"..(customCarNames[data[1]["Model"]] or getVehicleNameFromModel(data[1]["Model"])).." #c1c1c1foi spawnado.", source, 38, 122, 216, true)
		end
	else
		outputMessage("#c1c1c1Há um problema com o veiculo, notifique o administrador.", source, 38, 122, 216, true)
	end
end)

addEvent("DestroyMyVehicle", true)
addEventHandler("DestroyMyVehicle", root,
function(id)
	local vehicle = getVehicleByID(id)
	if isElement(vehicle) then
		local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountID(getPlayerAccount(source)), id), -1)
		if type(data) == "table" and #data ~= 0 then
			destroyVehicle(vehicle)
			outputMessage ("#c1c1c1O seu veiculo #00FF66"..(customCarNames[data[1]["Model"]] or getVehicleNameFromModel(data[1]["Model"])).." #c1c1c1foi removido.", source, 38, 122, 216, true)
		else
			outputMessage("#c1c1c1Selecione um veiculo.", source, 38, 122, 216, true)
		end
	else
		outputMessage("#c1c1c1O seu veiculo não foi spawnado.", source, 38, 122, 216, true)
	end
end)

addEvent("LightsMyVehicle", true)
addEventHandler("LightsMyVehicle", root,
function(id)
	local vehicle = getVehicleByID(id)
	if isElement(vehicle) then
		local Vehicle = getPedOccupiedVehicle(source)
		if Vehicle == vehicle then
			if getVehicleOverrideLights(vehicle) ~= 2 then
				setVehicleOverrideLights(vehicle, 2)
				outputMessage("#c1c1c1Seu veiculo #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1teve as luzes acesas.", source, 38, 122, 216, true)
			elseif getVehicleOverrideLights(vehicle) ~= 1 then
				setVehicleOverrideLights(vehicle, 1)
				outputMessage("#c1c1c1Seu veiculo #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1teve as luzes apagadas.", source, 38, 122, 216, true)
			end
		else
			outputMessage("#838B83[#FFFF00ATRP#838B83]#FFFF00 Voce Não Está no Veiculo!", source, 38, 122, 216, true)
		end
	else
		outputMessage("#838B83[#FFFF00ATRP#838B83]#FFFF00 Seu Veiculo Não Está Spawnado", source, 38, 122, 216, true)
	end
end)

addEvent("LockMyVehicle", true)
addEventHandler("LockMyVehicle", root,
function(id)
	local vehicle = getVehicleByID(id)
	if isElement(vehicle) then
		if not isVehicleLocked(vehicle) then
			setVehicleLocked(vehicle, true)
			setVehicleDoorsUndamageable(vehicle, true)
			setVehicleDoorState(vehicle, 0, 0)
			setVehicleDoorState(vehicle, 1, 0)
			setVehicleDoorState(vehicle, 2, 0)
			setVehicleDoorState(vehicle, 3, 0)
			exports.Scripts_Dxmessages:outputDx(source, "#c1c1c1O seu transporte #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1foi #00FF66fechado.", source, 38, 122, 216, true)
		elseif isVehicleLocked(vehicle) then
			setVehicleLocked(vehicle, false)
			setVehicleDoorsUndamageable(vehicle, false)
			exports.Scripts_Dxmessages:outputDx(source, "#c1c1c1O seu transporte #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1foi #00FF66aberto.", source, 38, 122, 216, true)
		end
	else
		exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00ATRP#838B83]#FFFF00 Seu Veiculo Não Foi Spawnado", source, 38, 122, 216, true)
	end
end)

addEvent("BlipMyVehicle", true)
addEventHandler("BlipMyVehicle", root,
function(id)
	local vehicle = getVehicleByID(id)
	if isElement(vehicle) then
		if not getElementData(vehicle, "ABlip") then
			setElementData(vehicle, "ABlip", true)
			createBlipAttachedTo(vehicle, 41, 2, 255, 0, 0, 255, 0, 65535, source)
			exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Seu veículo Foi Marcado no Mapa, Aperte F11 Pra Encontra-lo.", source, 38, 122, 216, true)
		else
			local attached = getAttachedElements(vehicle)
			if (attached) then
				for k,element in ipairs(attached) do
					if getElementType(element) == "blip" then
						destroyElement(element)
					end
				end
			end
			setElementData(vehicle, "ABlip", false)
			exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Seu veículo Foi Desmarcado do Mapa.", source, 38, 122, 216, true)
		end
	else
		exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Seu Veiculo Não foi Spawnado.", source, 38, 122, 216, true)
	end
end)

addEvent("FixMyVehicle", true)
addEventHandler("FixMyVehicle", root,
function(id)
	if getPlayerMoney(source) >= tonumber(500) then
		takePlayerMoney ( source, 500 )
		local vehicle = getVehicleByID(id)
		if isElement(vehicle) then
			fixVehicle(vehicle)
			setVehicleEngineState(vehicle, true)
			if isVehicleDamageProof(vehicle) then
				setVehicleDamageProof(vehicle, false)
			end
		end
		dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND ID = ?", 1000, getAccountID(getPlayerAccount(source)), id)
		updateVehicleInfo(source)
		outputMessage ("#c1c1c1O seu transporte foi reparado.", source, 38, 122, 216, true)
	else
		outputMessage("#c1c1c1Você não tem dinheiro suficiente para reparar.", source, 38, 122, 216, true)
		outputMessage("#c1c1c1Preço: #00FF66$500.", source, 38, 122, 216, true)
	end
end)

addEvent("WarpMyVehicle", true)
addEventHandler("WarpMyVehicle", root,
function(id)
    if not isPedInVehicle (source) then
	if getElementInterior(source) == 0 then
		if getPlayerMoney(source) >= tonumber(500) then
			local vehicle = getVehicleByID(id)
			if isElement(vehicle) then
				takePlayerMoney ( source, 500 )
				local x, y, z = getElementPosition(source)
				setElementPosition(vehicle, x, y, z)
				warpPedIntoVehicle ( source, vehicle )
				exports.Scripts_Dxmessages:outputDx(source, "#c1c1c1O seu veiculo #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1foi entregue a você.", source, 38, 122, 216, true)
			else
				exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00ATRP#838B83]#FFFF00 Seu Veiculo Não Está Spawnado.", source, 38, 122, 216, true)
			end
		else
			exports.Scripts_Dxmessages:outputDx(source, "#c1c1c1Você não tem os meios de se teletransportar para o veiculo.", source, 38, 122, 216, true)
		end
	else
		exports.Scripts_Dxmessages:outputDx(source, "#c1c1c1Você só poderá mudar de veiculo se sair do atual.", source, 38, 122, 216, true)
	end
     else
exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00BvB#838B83]#FFFF00 Nós não podemos dirigir seu veiculo. Por favor, sair do outro veiculo.", source, 38, 122, 216, true)
    end
end)

addEvent("SellMyVehicle", true)
addEventHandler("SellMyVehicle", root,
function(id)
	local vehicle = getVehicleByID(id)
	local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountID(getPlayerAccount(source)), id), -1)
	if type(data) == "table" and #data ~= 0 then
		local Money = math.ceil((data[1]["Cost"]*.9)*math.floor(data[1]["HP"])/100/10)
		givePlayerMoney (source, Money)
		if isElement(vehicle) then destroyElement(vehicle) end
		dbExec(db, "DELETE FROM VehicleList WHERE Account = ? AND ID = ?", getAccountID(getPlayerAccount(source)), id)
		updateVehicleInfo(source)
		exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Voce Vendeu Seu Veiculo por R$:"..Money, source, 38, 122, 216, true)
	end
end)

function getDataOnLogin(_, account)
	updateVehicleInfo(source)
end
addEventHandler("onPlayerLogin", root, getDataOnLogin)

addEvent("inviteToBuyCarSended", true)
addEventHandler("inviteToBuyCarSended", root,
function(player, price, veh_name, veh_id)
	if player and price and veh_name and veh_id then
		local pl = getPlayerFromName ( player )
		if pl then
			triggerClientEvent ( pl, "recieveInviteToBuyCar", pl, getPlayerName (source), getAccountID(getPlayerAccount(source)), price, veh_name, veh_id )
		else
			exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Jogador Não Encontrado", source, 250, 10, 10, true)
			triggerClientEvent ( source, "cleanCarInvitations", source )
		end
	end
end)


addEvent("invitationBuyCarNotAccepted", true)
addEventHandler("invitationBuyCarNotAccepted", root,
function(player, acc, price, veh_name, veh_id)
	local pl = getPlayerFromName ( player )
	if pl then
		triggerClientEvent ( pl, "cleanCarInvitations", pl )
		exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 o Jogador Recusou a Oferta", pl, 250, 10, 10,true)
	end
end)

addEvent("invitationBuyCarAccepted", true)
addEventHandler("invitationBuyCarAccepted", root,
function(player, acc, price, veh_name, veh_id)
	local pl = getPlayerFromName ( player )
	local avail = false
	if pl and getAccountID ( getPlayerAccount (pl)) == acc then
		avail = true
		triggerClientEvent ( pl, "cleanCarInvitations", pl )
		--outputMessage ( "????? ????????? ???????? ???? ????", pl, 250, 10, 10)
	else
		for i, v in ipairs( getElementsByType ( 'player' ) ) do
			if getAccountID(getPlayerAccount ( v )) == acc then
				avail = true
				pl = v
				break
			end
		end
	end
	price = tonumber(price) or 0
	if avail then
		if isGuestAccount ( getPlayerAccount ( source ) ) then
			triggerClientEvent ( pl, "cleanCarInvitations", pl )
			outputMessage ( "#838B83[#FFFF00 ATRP#838B83 ]#FFFF00 Voce Não Está Logado em Sua Conta", source, 250, 10, 10,true )
			outputMessage ( "#838B83[#FFFF00 ATRP#838B83 ]#FFFF00 o Jogador Não Está Logado", pl, 250, 10, 10,true )
			return true
		end
		if getPlayerMoney ( source ) >= price then
			local vehicle = getVehicleByID(tonumber(veh_id))
			local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountID(getPlayerAccount(pl)), veh_id), -1)
			if type(data) == "table" and #data ~= 0 and isElement ( vehicle ) then
				givePlayerMoney ( pl, price )
				takePlayerMoney ( source, price )
				dbExec(db, "UPDATE VehicleList SET Account = ? WHERE Account = ? AND ID = ?", getAccountID(getPlayerAccount(source)), getAccountID(getPlayerAccount(pl)), veh_id)
				updateVehicleInfo(source)
				updateVehicleInfo(pl)
				setElementData(vehicle, "Owner", source)
				setElementData(vehicle, "ownercar", getAccountID(getPlayerAccount(source)))
				exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Voce Vendeu Seu Veiculo Por R$:"..price, pl, 38, 122, 216, true)
				exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Comprou Um Veiculo Por R$:"..price, source, 38, 122, 216, true)
				triggerClientEvent ( pl, "cleanCarInvitations", pl )
			else
				outputMessage ( "#838B83[#FFFF00 ATRP#838B83 ]#FFFF00 o Veiculo Não Está Spawnado", source, 250, 10, 10,true )
				outputMessage ( "#838B83[#FFFF00 ATRP#838B83 ]#FFFF00 o Veiculo Não Está Spawnado", pl, 250, 10, 10,true )
				triggerClientEvent ( pl, "cleanCarInvitations", pl )
			end
		else
			exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Voce Não Tem Dinheiro Suficiente", source, 250, 10, 10,true )
		end
	else
		exports.Scripts_Dxmessages:outputDx(source, "#838B83[#FFFF00 BvB#838B83 ]#FFFF00 Jogador Não Encontrado", source, 250, 10, 10,true)
	end
end)

function consultarPlaca(source, Command, Placa)
local accName = getAccountName(getPlayerAccount(source))
if not isObjectInACLGroup("user."..accName,aclGetGroup("Policial")) then return
outputChatBox( "Você não tem permissão para este comando.", source, 250, 10, 10,true)
end
local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Placa = ?", Placa), -1)
if not getVehicleByPlate(Placa) then
outputChatBox( "Prenda o condutor Imediatamente.#FFFF00 Placa Fria", source, 250, 10, 10,true)
	return
end
if type(data) == "table" and #data ~= 0 then
local dono = data[1]["Account"]
local modelo = data[1]["Model"]
outputChatBox( "#FFFF00*________________________*", source, 255,255,255,true)
outputChatBox( "#FFFF00*__Banco de Dados DETRAN__*", source, 255,255,255,true)
outputChatBox( "Nome Do Veículo:#FFFF00"..getVehicleRealName(modelo), source, 255,255,255,true)
outputChatBox( "ID Proprietário:#FFFF00"..dono, source, 255,255,255,true)
getnick(tonumber(dono))
outputChatBox( "Placa Consultada:#FFFF00"..Placa, source, 255,255,255,true)
outputChatBox( "#FFFF00*________________________*", source, 255,255,255,true)
else
outputChatBox( "Veículo não spawnado ou inexistente", source, 250, 10, 10,true)
	end
end
addCommandHandler("consultar",consultarPlaca)


function getPlayerID(id)
	v = false
	for i, player in ipairs (getElementsByType("player")) do
		if getElementData(player, "ID") == id then
			v = player
			break
		end
	end
	return v
end


function getnick(dono)
    if(dono) then
        local playerID = tonumber(dono)
		if(playerID) then
			local Player2 = getPlayerID(playerID)
			if(Player2) then
				outputChatBox ( "Nome do Proprietário:#FFFF00" .. getPlayerName(Player2) .."", player, 255,255,255,true)
			else
				outputChatBox ( "Nome do Proprietário( " .. dono .. " ) #ffffffOFFLINE!", player, 255,255,255,true)
			end
		end
	end
end





function outputMessage (text, player, r, g, b)
	return exports["scr-Lib"]:outputMessage(player, text, r, g, b);
end

Sistema é da net.

Link to comment

Apenas Destruir / Sem Salvar Dados do Veiculo :

addEventHandler("onPlayerQuit", root, function ( )
   for i, veh in ipairs (getElementsByType("vehicle")) do
      if getElementData(veh, "Owner") == source then
         destroyVehicle ( veh )
      end
   end
end)

function destroyVehicle ( theVehicle )
   if isElement( theVehicle ) then
      destroyElement( theVehicle )
   end
end

Destruir & Salvar Dados ( Normalmente vem no resource da concessionaria ) 

function destroyVehicle(theVehicle)
   if isElement(theVehicle) then
      local Owner = getElementData(theVehicle, "Owner")
      if Owner then
         local id = getElementData(theVehicle, "ID")
         local x, y, z = getElementPosition(theVehicle)
         local _, _, rz = getElementRotation(theVehicle)
         local r1, g1, b1, r2, g2, b2 = getVehicleColor(theVehicle, true)
         local color = r1..","..g1..","..b1..","..r2..","..g2..","..b2
         upgrade = ""
         for _, upgradee in ipairs (getVehicleUpgrades(theVehicle)) do
            if upgrade == "" then
               upgrade = upgradee
            else
               upgrade = upgrade..","..upgradee
            end
         end 

         local account_id = getElementData(theVehicle, "ownercar") 
         local Paintjob = getVehiclePaintjob(theVehicle) or 3
         dbExec(db, "UPDATE VehicleList SET X = ?, Y = ?, Z = ?, RotZ = ?, HP = ?, Colors = ?, Upgrades = ?, Paintjob = ?, new_hydr = ? WHERE Account = ? AND ID = ?", x, y, z, rz, getElementHealth(theVehicle), color, upgrade, Paintjob, getElementData ( theVehicle, "NewHydr") and 1 or 0, account_id, id)
         updateVehicleInfo(Owner)
         local attached = getAttachedElements(theVehicle)
         if (attached) then
            for k,element in ipairs(attached) do
               if getElementType(element) == "blip" then
                  destroyElement(element)
               end
            end
         end
      end
      destroyElement(theVehicle)
   end
end

addEventHandler("onPlayerQuit", root, function ( )
   for i, veh in ipairs (getElementsByType("vehicle")) do
      if getElementData(veh, "Owner") == source then
         destroyVehicle ( veh )
      end
   end
end)

OBS [1] : Caso der erro, foi, pelo motivo de alguma modificação feita pelo responsável pela editação.

OBS [2] : Deixe o erro do debugscript 3, caso tiver algum erro ocorrido em algum dos dois processos.

Edited by Angelo Pereira
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...