Jump to content

[AJUDA] Ajuda em relação ifElse


Recommended Posts

Bom dia, boa tarde, boa noite. Estou fazendo um painel de alugar carros. Porém quando adicionei as funções de verificar se o player tem dinheiro suficiente , apenas o primeiro carro funciona. O que eu fiz de errado? 

Codigo:

 

Server Side

function spawn(player)
	if player then
		local carselected = getElementData(player, "CARSelect")
		if vehSpawn[player] then
			destroyElement(vehSpawn[player])
		end
		if carselected then
			if carselected == 1 then
					local Money = getPlayerMoney(player)
	                local Valor = 5000 
	                if Money >= Valor then
	            exports.Gunner_MensagensDX:outputDx ( player, "Carro alugado com sucesso!", "success" )
				vehSpawn[player] = createVehicle(car1, 262.19952, -3096.83765, 6.45605)
				takePlayerMoney(player, 5000)
			else
			exports.Gunner_MensagensDX:outputDx ( player, "Dinheiro insuficinete!", "error" )
		end
			elseif carselected == 2 then
				if Money >= Valor then
				exports.Gunner_MensagensDX:outputDx ( player, "Carro alugado com sucesso!", "success" )
				vehSpawn[player] = createVehicle(car2, 262.19952, -3096.83765, 6.45605)
				takePlayerMoney(player, 5000)
			else
			exports.Gunner_MensagensDX:outputDx ( player, "Dinheiro insuficinete!", "error" )
		end
			elseif carselected == 3 then
				if Money >= Valor then
				exports.Gunner_MensagensDX:outputDx ( player, "Carro alugado com sucesso!", "success" )
				vehSpawn[player] = createVehicle(car3, 262.19952, -3096.83765, 6.45605)
				takePlayerMoney(player, 5000)
			else
			exports.Gunner_MensagensDX:outputDx ( player, "Dinheiro insuficinete!", "error" )
			end
		end
	end
end
end
addEvent("GiveCAR", true)
addEventHandler("GiveCAR", getRootElement(), spawn)

 

Link to comment

Tente: 

function spawn(player)
	if player then
		local carselected = getElementData(player, "CARSelect")
		if vehSpawn[player] then
			destroyElement(vehSpawn[player])
		end
		local Money = getPlayerMoney(player)
	    local Valor = 5000 
		if Money >= Valor then
		if not carselected then return end -- SE NÃO EXISTIR carselected A FUNÇÃO RETORNARÁ AO FIM!
			if carselected == 1 then
	            exports.Gunner_MensagensDX:outputDx ( player, "Carro alugado com sucesso!", "success" )
				vehSpawn[player] = createVehicle(car1, 262.19952, -3096.83765, 6.45605)
				takePlayerMoney(player, 5000)
			elseif carselected == 2 then
				exports.Gunner_MensagensDX:outputDx ( player, "Carro alugado com sucesso!", "success" )
				vehSpawn[player] = createVehicle(car2, 262.19952, -3096.83765, 6.45605)
				takePlayerMoney(player, 5000)
			elseif carselected == 3 then
				exports.Gunner_MensagensDX:outputDx ( player, "Carro alugado com sucesso!", "success" )
				vehSpawn[player] = createVehicle(car3, 262.19952, -3096.83765, 6.45605)
				takePlayerMoney(player, 5000)
		end
		else 
		exports.Gunner_MensagensDX:outputDx ( player, "Dinheiro insuficiente!", "error" )
	end
end 
end
addEvent("GiveCAR", true)
addEventHandler("GiveCAR", getRootElement(), spawn)

 

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