Shopping Cart
FiveM script Buy GCPhone from shop Modding Tutorials

Buy GCPhone from shop – Modding Tutorials

FiveM Modding Tutorial

GCPhone in store
Hello!
I have started a tutorial to help newbies make the GCPhone an buyable item.
If you haven´t purchased the phone you won´t be able to open the phone which is exactly what this guide will make you accomplish.
So to start with i want you to download the latest resource GCPhone which you can find here: https://github.com/N3MTV/gcphone



Adding phone as an item
So to start with you need to add the phone into the database to make it an item.
To accomplish this you need to add ´´phone´´ under name. [THE NAME MUST BE PHONE]
Then you need to add the label which is what the in-game name is going to be. [Name can be whatever]
On the third row you have the limit which is the amount you can carry in-game. [-1= Unlimited amount.
1= 1 phone max. 2= 2 phones max that a player can carry etc.]
Then we have the other 2 rows which i suggest you leave as mine.
527295a62bbbe56dd298de08823e5f2b
OR JUST DOWNLOAD THIS IF YOU ARE USING ESX_SHOPS:

INSERT INTO `items` (`name`, `label`, `limit`) VALUES  
    ('phone', 'Phone', 1)
;
INSERT INTO shops (id, name, item, price) VALUES (98, 'TwentyFourSeven', 'phone', 175), (99, 'RobsLiquor', 'phone', 175), (100, 'LTDgasoline', 'phone', 175);

Modifying the GCPhone code to make it look for the phone in players inventory
First navigate to GCPhone then go into client/main.lua
In main.lua add this on top of the lua:

ESX              = nil

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end
end)


Then search(CTRL+F) for these lines in main.lua:

Citizen.CreateThread(function()

        while true do
            Citizen.Wait(0)
            if IsControlJustPressed(1, KeyOpenClose) and GetLastInputMethod( 0 ) then
                TooglePhone()
            end
            if menuIsOpen == true then
                for _, value in ipairs(KeyToucheCloseEvent) do
                    if IsControlJustPressed(1, value.code) then
                        SendNUIMessage({keyUp = value.event})
                    end
                end
            end
        end
end)

And replace them with the following:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if IsControlJustPressed(1, KeyOpenClose) and GetLastInputMethod( 0 ) then
			ESX.TriggerServerCallback('gcphone:getItemAmount', function(qtty)
				if qtty > 0 then
					TooglePhone()
				else
					TriggerEvent('esx:showNotification', "You don´t have a ~r~phone~s~")
				end
			end, 'phone')
		end
		if menuIsOpen == true then
			for _, value in ipairs(KeyToucheCloseEvent) do
				if IsControlJustPressed(1, value.code) then
					SendNUIMessage({keyUp = value.event})
				end
			end
		end
	end
end)


Now we are done in client/main.lua. Go to server/main.lua and ADD this code as high up as you can:

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj)
    ESX = obj
end)

ESX.RegisterServerCallback('gcphone:getItemAmount', function(source, cb, item)
    local xPlayer = ESX.GetPlayerFromId(source)
    local qtty = xPlayer.getInventoryItem(item).count
    cb(qtty)
end)


Restart GCPhone and you should now have phone as an item on your server.
For any problems just comment on this topic and i will try to help you the best i can :smiley:



Original source: https://forum.cfx.re/t/buy-gcphone-from-shop/1026111

Leave a Reply
FiveM ESX Scripts

The best scripts and maps

Best support

Problems? We are there to help!

Wide range of products

We have a wide range of products

100% Secure Checkout

Stripe