[Release] [ESX] Sell to NPC

Hi there. I’ve been looking for a good script that allows you to sell drugs or any items to NPC. I couldn’t find one that was well optimized and didn’t cause hitch threads. I’ve been doing Lua for quite some time, and have learned a couple of things during the process. I went ahead and made my own version of the sell to NPC script.

This version is well optimized for the client, uses 0.01ms (thanks to @IB1G) whilst not next to a ped, and uses 0.12ms whilst you have the item and are next to a ped. It does not cause server hitch thread warnings, but I have not done intensive testing. I have knifed a ped, checked on dead peds, etc…

I used [Release] [ESX] NPC Drug Sales (Optimized) for some parts. I utilized some awesome Google skills to optimize the checks for NPC. I copied the way esx_outlawalerts handles police notifications.

Features

  • Optimised both server and client-side.
  • Ability to sell all drugs to NPC, with a configurable price.
  • Random chance for sell success.
  • Police notifications if the Ped decides to call the police.
  • Check for old Ped.
  • Animations when drugs are sold to NPC.
  • Config file to allow you to modify the script
  • Most drugs supported.

Keep in mind…

  • This doesn’t have a bunch of features, but as time goes on I will add some nice, unique features to it.
  • You can create pull requests if you want to add features for the community to use.
  • Use the forum thread or Github for issues.

Download

For the single item version (weed) use the following:


If you have a powerful server and are able to handle hitch threads and need multiple items support, use the following:

Dependencies

Thank you,
Flawws.

17 Likes

Very nice release, i have a similiar version but that works differently, never toud about making it the way you made, but its very simple and it works, congrats !

I also made a pull request, i made some extra otimization, please test it live before merge it and check if everything is as you like :wink:

Keep going

3 Likes

Appreciate the reply. I’ve seen the changes and tested them. You didn’t make a pull request, if you want I’ll wait for you to make the PR and then I’ll merge. Unless you want me to just do it.

Just do it ahah, if it works, good eheh, enjoy

very beautiful and without failures, it would be good if you could choose locations where drugs are going to be sold…
and by the way, where proggresbar works I don’t see

I don’t think I’d add the setting sales to a specific area as I don’t see it as being necessary. You can add it yourself though.

This is me being super lazy but could you create a config for adding multiple drugs to it easily? I assume it’d be much easier for you to do than myself because you wrote the script. If not it’s cool I’ll fuck around with it til I do it.

I’d really appreciate if someone could send a template on how to add drugs thanks.

1 Like

Sure, I’ll set it up when I have the time.

1 Like

Update 1.0.1

  • Fixed mythic notify alert types
  • Moved working out money to server-side
  • Setup a very basic config

Really? Damn dude, very much appreciated. I checked out the code, looks really neat. I’m impressed.

1 Like

Apologies, fixed.

Thanks for sharing your script. But i cant sell weed. I get this error in F8
https://gyazo.com/22df8709c6401386c3914379b496af2d

The Press E message does show up. But when i hit E the npc stops moving and does not start moving after hitting E. Nothing else happens.

This is a dependency: https://github.com/torpidity/progressBars

I got that running on the server. It loads before this script.

Check the __resource.lua for that progressBars you have.
Last line should say export "startUI"

Did not change anything.

resource_manifest_version ‘77731fab-63ca-442c-a67b-abc70f28dfa5’
ui_page ‘h.html’

client_scripts {
‘client.lua’
}

files {
‘h.html’
}

export “startUI”

make sure that you activate the sale by a menu of the krz-personal menu type and that it is the pnj which requests the drug by stopping randomly with a colored circle which appears on the pnj which requests the drug (a can like when we do taxi missions and wait for a customer to request a taxi) I hope it’s clear XD (a bit like on the GTA Life server, it’s an en server)

if you can do it you’re the best even if you already are :wink:

I have progressBars starting after the resource.