[Release] [ESX] Sell to NPC

This isn’t my script.

ok I will check it, it should be another script. I put key “G” for the action .

Hello, this script presents the following problem if you stay still next to the NPC and do not press E to sell it.

It is the script of multiple drugs, I only use two of them.

I can’t get the zone coordinates to work, the script without modifying it works for me, any help please?

how do i make it work

He literally tells you how to do it man, you can literally copy and paste what @jonare said here.

I did everything written, we basically did copy paste, srry my english

Could you send me the code to put the coordinates, I would appreciate it because maybe it is updated or something, thanks in advance

The code is literally above man, i don’t know what else to tell you. It works fine.

Maybe check your console for errors? if you have errors arise, then post them here so i can attempt to point you in the right direction.

1 Like

Sorry, maybe I explained myself wrong, so I realized that if there is an errorunknown , I subscribe that this only happens to me when I change the code so that the coordinates work for me, and srry me english is translate, thanks

in case it doesn’t look good put this: attempt to concatenate a nil value (upvalue ‘drugtype’)

image

Change weed_pooch for your weed item name. For example my weed item name is “marijuana”. Check your database.

is there a way to make it so you cant sell to certain NPCs?

I updated the code of jonare for the last version.

In client.lua replace the function:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(5)
		if ped ~= 0 and not IsPedDeadOrDying(ped) and not IsPedInAnyVehicle(ped) then 
            local pedType = GetPedType(ped)
			if ped ~= oldped and not selling and (IsPedAPlayer(ped) == false and pedType ~= 28) then
				TriggerServerEvent('checkD')
				if drugtype ~= nil then
						
					if Config.NumberOfCops > 0 then
						TriggerServerEvent('checkC')
					end
						
					if numberofcops >= Config.NumberOfCops then
						local pos = GetEntityCoords(ped)
						DrawText3Ds(pos.x, pos.y, pos.z, 'Press E to sell ' .. drugtype)
						if IsControlJustPressed(1, 86) then
							interact(drugtype)
						end
					end
				else
					Wait(5000)
				end
			else
				Citizen.Wait(500)
			end
		end
	end
end)

To this:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(5)
		if ped ~= 0 and not IsPedDeadOrDying(ped) and not IsPedInAnyVehicle(ped) then 
		
		local player = GetPlayerPed(-1)
		local playerloc = GetEntityCoords(player, 0)
		local distanceFromCity = GetDistanceBetweenCoords(Config.CityPoint.x, Config.CityPoint.y, Config.CityPoint.z, playerloc['x'], playerloc['y'], playerloc['z'], true)
		
            local pedType = GetPedType(ped)
			if ped ~= oldped and not selling and (IsPedAPlayer(ped) == false and pedType ~= 28) then
			if distanceFromCity < Config.DistanceFromCity then
				TriggerServerEvent('checkD')
				if drugtype ~= nil then
						
					if Config.NumberOfCops > 0 then
						TriggerServerEvent('checkC')
					end
						
					if numberofcops >= Config.NumberOfCops then
						local pos = GetEntityCoords(ped)
						DrawText3Ds(pos.x, pos.y, pos.z, 'Presiona E para vender ' .. drugtype)
						if IsControlJustPressed(1, 86) then
							interact(drugtype)
						end
					end
				else
					Wait(5000)
			end
				end
			else
				Citizen.Wait(500)
			end
		end
	end
end)

Now add this to the config file:

Config.DistanceFromCity = 370 -- set distance Radius
Config.CityPoint = {x= -1687.68, y= -1055.75, z= 13.09} -- Pier location
1 Like

So i get this error on multiple drug scripts i attempt to use. It worked then i restarted my server and got this in my console. https://prnt.sc/vmehx6

I have the items set up correctly to my Database (weed_pooch) - Marijuana (Item i use) https://prnt.sc/vmeiw2

Any help would be appreciated thanks

Are you running ESX 1.0?

Im not 100% sure. I attempted to update to the newest essentials mode and it broke my server. Is there a command i could use to see my version? Is there a way i could change this to work with a older ESX?

Hello ! :slight_smile:
I wanna change line 40 in the server.lua which is this one:
xPlayer.addAccountMoney(‘black_money’, moneyamount)

so that when people sell they get regular money in their pockets. I tried to change it to
xPlayer.addMoney(payment)

but it doesnt seem to work. Any idea what i should replace this line with ? :slight_smile:

help me mark this error when approaching an npc