FiveM Docs
Addons

esx_optionalneeds

esx_optionalneeds adds a drunk status and a usable beer item to ESX Legacy, with three drunk levels, walk styles and screen effects. Setup and API.

esx_optionalneeds adds alcohol to ESX Legacy. It registers a drunk status in esx_status and a usable beer item. While the status is above zero the player walks drunk, gets motion blur and a screen filter; when it drops back to zero the effects fade out.

Overview

FactValue
Resourceesx_optionalneeds
SideServer (usable item) and client (status and effects)
Manifest dependenciesesx_lib, es_extended
Needs at runtimeesx_status (not listed in the manifest)
SQLesx_optionalneeds.sql adds the beer item

Installation

Import the item

esx_optionalneeds.sql
INSERT INTO `items` (`name`, `label`, `weight`) VALUES
	('beer', 'Beer', 1)
;

The localization/ folder has translated variants. Some of them, such as en_esx_optionalneeds.sql, also insert beer into a shops table. Only use those if your shop resource uses that table.

Start it after esx_status

server.cfg
ensure esx_status
ensure esx_optionalneeds

Configuration

KeyDefaultDescription
Config.TickTime100Not used by the current code.
Config.UpdateClientTime5000Not used by the current code.
Config.LocaleGetConvar('esx:locale', 'en')Language of the "you drank a beer" notification.

The drunk values are hard-coded in client/main.lua and server/main.lua.

How it works

  1. Using beer removes one beer, adds 250000 to drunk on the client, plays a drinking scenario and shows a notification.
  2. On esx_status:loaded the client registers drunk with default 0, color #8F15A5, visible only while above zero, and a tick that removes 1500 per esx_status tick (1 second by default).
  3. A loop checks the status every second and applies a drunk level:
Drunk valueLevelWalk style
1 to 2500000move_m@drunk@slightlydrunk
250001 to 5000001move_m@drunk@moderatedrunk
above 5000002move_m@drunk@verydrunk

Every level also sets the spectator5 timecycle, motion blur and SetPedIsDrunk. When the value reaches 0, the screen fades and everything is reset.

Events

esx_optionalneeds:onDrink (client, net)

Plays the WORLD_HUMAN_DRINKING scenario for one second. Harmless if triggered by anyone.

TriggerClientEvent('esx_optionalneeds:onDrink', playerId)

Making players drunk from your own script

drunk is a custom (client-owned) status, so use the client events of esx_status:

server/main.lua
ESX.RegisterUsableItem('vodka', function(source)
    local xPlayer = ESX.Player(source)
    xPlayer.removeInventoryItem('vodka', 1)

    TriggerClientEvent('esx_status:add', source, 'drunk', 400000)
    TriggerClientEvent('esx_optionalneeds:onDrink', source)
end)
client/main.lua
-- sober up instantly, for example after a hospital visit
TriggerEvent('esx_status:set', 'drunk', 0)

Common issues

  • Beer does nothing: esx_status is not started, or started after esx_optionalneeds, so drunk was never registered.
  • "Item beer does not exist": the SQL was not imported, or you use an inventory with its own item list (see ox_inventory).
  • Effects stay after relog: the drunk value is saved with the other custom statuses and continues after reconnect. It decays as usual.

Frequently asked questions

Independent documentation

esx-fivem.com is a community project and is not affiliated with the ESX Framework team. Facts on this page were checked against the upstream source. Official resources: docs.esx-framework.org and github.com/esx-framework.
Edit on GitHub

Last updated on

On this page