ESX Vending Machines

Allow people to purchase specific items from vending machines. The default vending machine object is prop_vend_snak_01

Requirements:

es_extended

Installation:

  • Get esx_tgo_vendingmachines folder and place it inside [ESX] directory folder.

  • Open server.cfg and add start esx_tgo_vendingmachines

https://github.com/Nosmakos/ESX-VENDINGMACHINES

TEBEX (PAID SCRIPTS)

9 Likes

Config Position??..

There is no position for the vending machines, it works based on objects. If you spawn prop_vend_snak_01 anywhere, it will do the action.

1 Like

Excellent resource! I notice one thing thou. You are letting the client set the values and total cost of the sell. The server is not validating any of this, which means the client can inject a $0.00 into the sell and get free stuff.

2 Likes

I dont really understand what do you mean, can you please explain? Are you talking about injection cheat?

Pretty much yes. Your server event handler is taking totalBuyPrice from the client instead of calculating that server-side. Someone could set that value to 0.0 in their client and buy stuff for free.

I agree with that but its very easy to be protected from an injection in this case. I can add a protection if you really want that wouldnt let them get any item.

There are many ways since the script is very simple but in order to use this event, they should have your scripts if you are about to change the script name, script eventhandler names and everything. In this case, if they have your scripts you can simply create an access system that allows you to use this event only from the vending machine and the injection wouldnt be able to do anything.

1 Like

Why wasting time just protecting the damn event, just make it server side. You should all learn to do this automatically, this is a big part in game/web dev with client-server communication.

What do you mean by making it server side since it is server side? There are some hacks that can also trigger serverside events as far i know.

@Nosmakos can you go check pr’s? Thanks

If someone want to use items from default config add this code into “server/main.lua”

ESX.RegisterUsableItem('ruffles_baked', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)
	xPlayer.removeInventoryItem('ruffles_baked', 1)

	TriggerClientEvent('esx_status:add', source, 'hunger', 100000)
	TriggerClientEvent('esx_basicneeds:onEat', source)
	xPlayer.showNotification("You have used ~y~1x~s~ ~b~RUFFLES® Baked~s~")
end)

ESX.RegisterUsableItem('lays_cream', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)
	xPlayer.removeInventoryItem('lays_cream', 1)

	TriggerClientEvent('esx_status:add', source, 'hunger', 100000)
	TriggerClientEvent('esx_basicneeds:onEat', source)
	xPlayer.showNotification("You have used ~y~1x~s~ ~b~Lays® Sour Cream & Onion~s~")
end)

ESX.RegisterUsableItem('3bit', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)
	xPlayer.removeInventoryItem('3bit', 1)

	TriggerClientEvent('esx_status:add', source, 'hunger', 100000)
	TriggerClientEvent('esx_basicneeds:onEat', source)
	xPlayer.showNotification("You have used ~y~1x~s~ ~b~3Bit~s~")
end)

ESX.RegisterUsableItem('maltesers', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)
	xPlayer.removeInventoryItem('maltesers', 1)

	TriggerClientEvent('esx_status:add', source, 'hunger', 100000)
	TriggerClientEvent('esx_basicneeds:onEat', source)
	xPlayer.showNotification("You have used ~y~1x~s~ ~b~Maltesers~s~")
end)

ESX.RegisterUsableItem('kitkat', function(source)
	local xPlayer = ESX.GetPlayerFromId(source)
	xPlayer.removeInventoryItem('kitkat', 1)

	TriggerClientEvent('esx_status:add', source, 'hunger', 100000)
	TriggerClientEvent('esx_basicneeds:onEat', source)
	xPlayer.showNotification("You have used ~y~1x~s~ ~b~KitKat~s~")
end)

and create these items in database

INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('ruffles_baked', 'RUFFLES® Baked', '1', '0', '1');

INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('lays_cream', 'Lays® Sour Cream & Onion', '1', '0', '1');

INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('3bit', '3Bit', '1', '0', '1');

INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('maltesers', 'Maltesers', '1', '0', '1');

INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('kitkat', 'KitKat', '1', '0', '1');
2 Likes

Thank you for sharing this, i havent added those since i just placed a custom ones that ive made. You guys can always add any kind of item.

What is prs?

Git(Hub) Pull Requests

Thanks for sharing that, Without this code the items were NOT usable.

1 Like

You can always add your own items inside.

ok, i’m going to try to generate the props to see how it is

You can add as many props you want, any vending machine from https://plebmasters.de/?search=&app=objects

Thank you for sharing this its helped with making things useable the only downfall i seen was it removes bread and not each item thats there so for example KitKat you have put it to remove bread from inventory. Thank you

1 Like

I make mistake and forgot to change name of item being removed from inventory.
#fixed

Awesome

1 Like

You should better use, onEatChocolate

RegisterNetEvent('esx_basicneeds:onEatChocolate')
AddEventHandler('esx_basicneeds:onEatChocolate', function(prop_name)
	if not IsAnimated then
		prop_name = prop_name or 'prop_choc_ego'
		IsAnimated = true

		Citizen.CreateThread(function()
			local playerPed = PlayerPedId()
			local x,y,z = table.unpack(GetEntityCoords(playerPed))
			local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
			local boneIndex = GetPedBoneIndex(playerPed, 18905)
			AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.035, 0.009, -30.0, -240.0, -120.0, true, true, false, true, 1, true)

			ESX.Streaming.RequestAnimDict('mp_player_inteat@burger', function()
				TaskPlayAnim(playerPed, 'mp_player_inteat@burger', 'mp_player_int_eat_burger_fp', 8.0, -8, -1, 49, 0, 0, 0, 0)

				Citizen.Wait(3000)
				IsAnimated = false
				ClearPedSecondaryTask(playerPed)
				DeleteObject(prop)
			end)
		end)

	end
end)

prop_choc_ego prop_choc_meto prop_choc_pq

You can create random props using different chocolate prop each time on eating too.