Jump to content

Problema com loja de carros


Recommended Posts

Eu de novo aqui kkk, Bom, o sistema de carro esta perfeitamente bem, todas as Keys funcionam e não apresenta absolutamente NENHUM erro, o que dificulta. Resumindo, ao apertar a Bind Key que deveria confirmar a compr ado veiculo, nao acontece absolutamente NADA, no entanto as outras binds como de passar os carros, mudar cor, etc, Funcionam perfeitamente, alguma solução rápida ?

server:

addEvent("onClientBuyVehicle", true)
addEventHandler("onClientBuyVehicle", root, function(playerSource, model, price, r, g, b, r1, g1, b1)		if setElementData(playerSource, "char.money", getElementData(playerSource, "char.money") - price) then	local regiertek = getElementData(playerSource, "char.money")	local ujertek = getElementData(playerSource, "char.money") + price	exports["vz_vehicle"]:createShopVehicle(playerSource, model, r, g, b, r1, g1, b1)		exports["vz_info"]:showBoxS(playerSource,"Compra efetuada com sucesso","info")
	outputChatBox("#4169E1[SERVER NAME]: #ffffffLembre-se de estacionar seu veiculo para que ele sejá salvo em nosso sistema", playerSource, 255, 255, 255, true)	
end
end)

addEvent("onClientBuyVehiclePP", true)
addEventHandler("onClientBuyVehiclePP", root, function(playerSource, model, pp, r, g, b, r1, g1, b1)		if setElementData(playerSource, "char.diamante", getElementData(playerSource, "char.diamante") - pp) then	local regipp = getElementData(playerSource, "char.diamante")	local ujpp = getElementData(playerSource, "char.diamante") - pp
	exports["vz_vehicle"]:createShopVehicle(playerSource, model, r, g, b, r1, g1, b1)	
	exports["vz_info"]:showBoxS(playerSource,"Compra efetuada com sucesso","info")
	outputChatBox("#4169E1[SERVER NAME]: #ffffffLembre-se de estacionar seu veiculo para que ele sejá salvo em nosso sistema", playerSource, 255, 255, 255, true)
	end
end)

Client:

local screenSize = {guiGetScreenSize()}
local currSelected = 1
local isShopActive = false
local left, top = screenSize[1]/2 - 414/2, screenSize[2]/2 - 163/2 - 30
local dataFont = dxCreateFont("files/font.ttf", 19, false, "cleartype")

local sellVehicles = 	
{-- [ID DO VEICULO], [NOME DO VEICULO], [VALOR EM DINHEIRO], [KM/H], [VALOR EM DIAMANTE], [UNIDADES DISPONIVEIS]
    {600, "SAVEIRO CROSS", 1000, 180, 800, 21},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
    {586, "NOME DO CARRO", 3200, 50, 800, 0},
}
local blip = createBlip(1329.7835693359, -877.1875, 39.578125,55)

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function()
	shopPickup = createPickup(1329.7835693359, -877.1875, 39.578125, 3, 1274)
end)

addEventHandler("onClientPickupHit", root, function(playerSource)
	if source == shopPickup and playerSource == localPlayer then
		cancelEvent()
		fadeCamera(false)
		setElementFrozen(localPlayer, true)
		isShopActive = true
		setElementData(localPlayer, "showOOC", 0)
        setElementData(localPlayer, "showHUD", 0)
		setElementData(localPlayer, "showRadar", 0)
		setTimer(function()
			fadeCamera(true)
			setCameraMatrix(1317.8608398438, -867.76007080078, 41.221599578857, 1317.7788085938, -866.78424072266, 41.019165039063)
			shopVehicle = createVehicle(sellVehicles[currSelected][1], 1317.5485839844, -854.9912109375, 39.096145629883)
			addEventHandler("onClientRender", root, vehicleRotation)
			addEventHandler("onClientGUIClick", root, colorButtonFunctions)
			updateCarColor()
		end, 2000, 1)
		showChat(false)
		currSelected = 1
	end
end)

function exitShop()
	if isShopActive then
		setElementFrozen(localPlayer, false)
		setElementDimension(localPlayer, 0)
		setCameraTarget(localPlayer)
		setElementData(localPlayer, "showOOC", 1)
        setElementData(localPlayer, "showHUD", 1)
		setElementData(localPlayer, "showRadar", 1)
		isShopActive = false
		destroyElement(shopVehicle)
		setElementPosition(localPlayer, 1333.9366455078, -875.04479980469, 39.578125)
		removeEventHandler("onClientRender", root, vehicleRotation)
		removeEventHandler("onClientGUIClick", root, colorButtonFunctions)
		showChat(true)
		currSelected = 1
		updateCarColor()
	end
end
addEvent("backToCharacter",true)
addEventHandler("backToCharacter",getRootElement(),exitShop)

function vehicleRotation()
	local x, y, z = getElementRotation(shopVehicle)
	setElementRotation(shopVehicle, x, y, z + 0.5)
	panelImage = dxDrawImage(left-50, top * 2, 566, 245, "files/carshop.png")
	
	dxDrawText(sellVehicles[currSelected][2], left + 58, top * 2 + 31, 269, 10, tocolor(65, 105, 225,204), 0.5, dataFont)
	dxDrawText(sellVehicles[currSelected][4].. "#4169E1 km/h", left + 89.1, top * 2 + 55, 269, 10, tocolor(255,255,255,204), 0.5, dataFont, "left", "top", false, false, false, true)
	dxDrawText("#4169E1$#ffffff" ..sellVehicles[currSelected][3], left + 70, top * 2 + 165, 269, 10, tocolor(255,255,255,190), 0.5, dataFont, "left", "top", false, false, false, true)
	dxDrawText("#4169E1$#ffffff"..sellVehicles[currSelected][5].."", left + 80, top * 2 + 194, 269, 10, tocolor(255,255,255,190), 0.5, dataFont, "left", "top", false, false, false, true)
	if sellVehicles[currSelected][6] > 0 then
		dxDrawText((#getPremiumVehicles(sellVehicles[currSelected][1]) or 0).."#ffffff/#4169E1"..sellVehicles[currSelected][6], left + 58, top * 2 + 82, 269, 10, tocolor(65, 105, 225,204), 0.5, dataFont, "left", "top", false, false, false, true)
		else
		dxDrawText("Não", left + 58, top * 2 + 82, 269, 10, tocolor(65, 105, 225,204), 0.5, dataFont, "left", "top", false, false, false, true)
	end
end



addEventHandler("onClientKey", root, function(key, source)
	if not source or not isShopActive then return end
    	if key == "backspace" then
		exitShop()
	elseif key == "arrow_l" then
		if sellVehicles[currSelected - 1] then
			currSelected = currSelected - 1
			setElementModel(shopVehicle, sellVehicles[currSelected][1])
		else
			currSelected = #sellVehicles
			setElementModel(shopVehicle, sellVehicles[currSelected][1])
		end
	elseif key == "arrow_r" then
		if sellVehicles[currSelected + 1] then
			currSelected = currSelected + 1
			setElementModel(shopVehicle, sellVehicles[currSelected][1])
		else
			currSelected = 1
			setElementModel(shopVehicle, sellVehicles[currSelected][1])
        end
	elseif key == "enter" then

	if sellVehicles[currSelected][6] > 0 then
        if (#getPremiumVehicles(sellVehicles[currSelected][1]) or 0) >= sellVehicles[currSelected][6] then exports["vz_info"]:showBox("A loja atingiu o limite maximo desse veiculo","error") return end
	end

		if sellVehicles[currSelected][3] > tonumber(getElementData(localPlayer, "char.money")) then
			exports["vz_info"]:showBox("Dinheiro insuficiente","error")
			else
			local r,g,b,r1,g1,b1 = getVehicleColor(shopVehicle, true)	
			triggerServerEvent("onClientBuyVehicle", localPlayer, localPlayer, sellVehicles[currSelected][1], sellVehicles[currSelected][3], r, g, b, r1, g1, b1)
			exitShop()
		end
	elseif key == "d" then
	    if sellVehicles[currSelected][5] > tonumber(getElementData(localPlayer, "char.diamante")) then
            exports["vz_info"]:showBox("Diamante insuficiente","error")
	    else
	local r,g,b,r1,g1,b1 = getVehicleColor(shopVehicle, true)	
	triggerServerEvent("onClientBuyVehiclePP", localPlayer, localPlayer, sellVehicles[currSelected][1], sellVehicles[currSelected][5], r, g, b, r1, g1, b1)
	exitShop()
	  end
	end
end)

function updateCarColor()
if isShopActive then
    orange = guiCreateButton(left+8, top * 2 + 123, 15, 15, "o", false)
        guiSetAlpha(orange, 0)
    red = guiCreateButton(left+28, top * 2 + 123, 15, 15, "r", false)
        guiSetAlpha(red, 0)
    black = guiCreateButton(left+48, top * 2 + 123, 15, 15, "b", false)
        guiSetAlpha(black, 0)
	white = guiCreateButton(left+68, top * 2 + 123, 15, 15, "w", false)
        guiSetAlpha(white, 0)	
	blue = guiCreateButton(left+88, top * 2 + 123, 15, 15, "b", false)
        guiSetAlpha(blue, 0)	
    green = guiCreateButton(left+108, top * 2 + 123, 15, 15, "g", false)
        guiSetAlpha(green, 0)
	else
	destroyElement(orange)
	destroyElement(red)
	destroyElement(black)
	destroyElement(white)
	destroyElement(blue)
	destroyElement(green)
  end
end

function colorButtonFunctions(button,state)
	if source == orange then
        setVehicleColor(shopVehicle, 219, 105, 13, 255, 255, 255)
	elseif source == red then
        setVehicleColor(shopVehicle, 157, 37, 37, 255, 255, 255)
	elseif source == black then
        setVehicleColor(shopVehicle, 0, 0, 0, 255, 255, 255)
	elseif source == white then
	    setVehicleColor(shopVehicle, 255, 255, 255, 255, 255, 255)
	elseif source == blue then
	    setVehicleColor(shopVehicle, 9, 53, 93, 255, 255, 255)
	elseif source == green then
	    setVehicleColor(shopVehicle, 10, 55, 27, 255, 255, 255)
	end
end

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

function getVehiclePrice(model)
	for k, v in ipairs(sellVehicles) do
		if v[1] == model then
			return v[3]
		end
	end
	return 5000
end

function getPremiumVehicles(id)
	local have = {}
	for k, v in ipairs(getElementsByType("vehicle")) do 
	    if getElementData(v, "veh.owner") and getElementData(v, "veh.owner") > 0 then
			if id == getElementModel(v) then
				have[#have + 1] = v
			end
		end
	end
	return have
end

 

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