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
| Fact | Value |
|---|---|
| Resource | esx_optionalneeds |
| Side | Server (usable item) and client (status and effects) |
| Manifest dependencies | esx_lib, es_extended |
| Needs at runtime | esx_status (not listed in the manifest) |
| SQL | esx_optionalneeds.sql adds the beer item |
Installation
Import the item
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
ensure esx_status
ensure esx_optionalneedsConfiguration
| Key | Default | Description |
|---|---|---|
Config.TickTime | 100 | Not used by the current code. |
Config.UpdateClientTime | 5000 | Not used by the current code. |
Config.Locale | GetConvar('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
- Using
beerremoves one beer, adds250000todrunkon the client, plays a drinking scenario and shows a notification. - On
esx_status:loadedthe client registersdrunkwith default0, color#8F15A5, visible only while above zero, and a tick that removes1500per esx_status tick (1 second by default). - A loop checks the status every second and applies a drunk level:
| Drunk value | Level | Walk style |
|---|---|---|
| 1 to 250000 | 0 | move_m@drunk@slightlydrunk |
| 250001 to 500000 | 1 | move_m@drunk@moderatedrunk |
| above 500000 | 2 | move_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:
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)-- 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
drunkwas 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.
Related
Frequently asked questions
Independent documentation
Last updated on
esx_mechanicjob
Install and configure esx_mechanicjob for ESX Legacy. Repair kits, crafting, NPC towing missions, billing, config keys, server events and known issues.
esx_pausemenu
esx_pausemenu replaces the GTA pause screen with a branded ESX Legacy NUI menu showing character, money, job and links. Install and config guide.