en-consumables decides what eating, drinking and medicine actually do. When you use a food, drink, medical or armour item, you play an animation with a prop in hand and see a progress bar you can cancel. The item is only taken, and its effects applied, if the bar finishes.
Items can restore hunger and thirst, heal you, set armour, purge radiation, treat infection or boost immunity. They can also apply effects over time, like a course of antibiotics, give you a temporary stamina boost, or carry a risk of making you sick (murky water, dodgy burgers). The Medicine skill makes healing stronger, and the Iron Gut perk lowers the chance of getting sick.
At a glance
| Depends on | en-core, en-inventory |
| Start after | Both of the above |
| Database tables | None |
| Config files | config/shared.lua |
| Works with | en-skills (healing and foodRisk bonuses, Medicine XP) |
How it works
Using an item
Every key in Config.items is registered as a usable item in en-inventory. When a player uses one:
- The server checks the player isn't dead and isn't within
Config.cooldownof their last use. - The client plays the animation and progress bar. You can't use items while swimming, ragdolled or dead.
- If the bar completed, the server removes the item, then applies the effects. If the item is already gone, nothing happens.
The server rejects a "finished" reply that arrives in less than 80% of the item's duration, and gives up waiting after 30 s.
Effects
Effects change en-core's survival stats; see Survival system.
- Positive
healthis multiplied by1 + healing bonus. It's given on a 0–100 scale and converted to the ped's real health range on the client. armoursets armour to at least that value, scaled by the item'smetadata.durability.- Negative
hunger,thirst,radiationandinfectionvalues remove that amount.
Effects over time
An overTime block repeats its effects every interval seconds, ticks times. Using the same item again restarts the course rather than stacking it. A course stops if the player dies or unloads.
Risk
After use, a risk block rolls this chance:
chance = risk.chance * (1 - math.min(0.9, foodRiskBonus))If it hits, the player gets the listed infection or radiation and sees risk.message.
Configuration
| Key | Default | What it does |
|---|---|---|
Config.cooldown | 1.5 | Seconds between uses of any consumable |
Config.animations | drink, can, eat, eatCan, pill, bandage, medkit, armour | { dict, clip, flag, prop = { model, bone, pos = vec3, rot = vec3 } }; prop is optional |
Config.items | 14 items | Consumable definitions, keyed by item name |
Item fields
| Field | What it does |
|---|---|
label | Progress bar text |
duration | Milliseconds |
animation | Key in Config.animations |
walk | Allow walking while using (default true) |
effects | Applied once on finish: hunger, thirst, health, armour, radiation, infection, immunity |
overTime | { interval, ticks, radiation?, infection?, immunity?, health?, hunger?, thirst? } |
risk | { chance = 0..1, infection?, radiation?, message } |
stamina | { seconds }: keeps stamina topped up for that long |
Default items
| Item | What it does |
|---|---|
water, canned_soda, bread, canned_beans, mre | Hunger and thirst |
dirty_water | Thirst, with a 35% chance of +8 infection |
energy_drink | 90 s of stamina |
burger | Hunger, with an 8% chance of getting sick |
bandage | +15 health |
painkillers | +5 health, then +3 every 10 s, 6 times |
first_aid_kit | +50 health, -5 infection, no walking |
antibiotics | -10 infection, +5 immunity, then -6 infection every 30 s, 5 times |
rad_pills | -20 radiation, then -15 every 30 s, 4 times |
armour | 100 armour, no walking |
Adding consumables
Config.items.boiled_rice = {
label = 'Eating rice', duration = 5000, animation = 'eatCan',
effects = { hunger = 40, thirst = -8 },
}
Config.items.raw_meat = {
label = 'Eating raw meat', duration = 6000, animation = 'eat',
effects = { hunger = 25 },
risk = { chance = 0.5, infection = 12, message = 'You shouldn\'t have eaten that raw.' },
}
Config.items.morphine = {
label = 'Injecting morphine', duration = 4000, animation = 'pill', walk = false,
effects = { health = 20 },
overTime = { interval = 5, ticks = 10, health = 4 },
}Each item must also exist in en-inventory/data/items.lua, or players can never get or use it. See Add an item. Give medical items the medical category so they train the Medicine skill.
Exports
Server
| Export | Arguments | Returns |
|---|---|---|
ApplyEffects | source, effects, reason? | nil. Applies an effects table with the same keys as Config.items[*].effects |
IsConsumable | itemName | boolean |
Client
| Export | Returns |
|---|---|
IsBusy() | boolean: a consumable is being used |
Events
| Event | Side | Payload |
|---|---|---|
en-consumables:server:consumed | Server-local | source, itemName, definition |
en-consumables:client:effects | Client | { health?, armour? } |
en-consumables:client:stamina | Client | seconds |
en-skills uses en-consumables:server:consumed to award Medicine XP for medical items.
Examples
A medic NPC that patches players up without using an item:
-- server
AddEventHandler('mymedic:server:treat', function()
local source = source
exports['en-consumables']:ApplyEffects(source, { health = 60, infection = -25, immunity = 10 }, 'medic')
end)Stop players from opening your menu mid-bite:
-- client
RegisterCommand('mymenu', function()
if exports['en-consumables']:IsBusy() then return end
-- open the menu
end)Track what players eat:
AddEventHandler('en-consumables:server:consumed', function(source, itemName, definition)
if definition.risk then
print(('%s risked eating %s'):format(GetPlayerName(source), itemName))
end
end)