Esc to clear, Enter to open the best match, click an export to open it in its page
Get Started

Your First Resource

Build a coffee stand in about 30 minutes: a counter you walk up to, a purchase the server checks and charges for, and a coffee that takes four seconds to drink. Each step is something every WHIP resource does.

You need a server running WHIP (Quick Start) and the whip.devtools ACE, so /w and /whip open.

The finished stand is in whip_core/docs/examples/whip_cafe_example, line for line. Compare yours with it when a step doesn't work. It uses the same names as yours, so run one or the other.

1. The folder

Make a folder called mycafe in your resources, with fxmanifest.lua, shared.lua, server.lua and client.lua:

fx_version 'cerulean'
game 'gta5'
lua54 'yes'

dependency 'whip_core'
whip_requires '1.0'

shared_scripts {
    '@whip_core/lib/satellite.lua',   -- WHIP's helper: gives you Whip.register and Whip.core
    'shared.lua',
}
server_script 'server.lua'
client_script 'client.lua'

Add ensure mycafe to server.cfg, below WHIP's lines. dependency 'whip_core' starts whip_core first, and restarts your resource whenever whip_core restarts. whip_requires makes the setup report flag an older whip_core.

Set up autocomplete first. Copy whip_core/types/luarc.template.json into mycafe as .luarc.json and open the folder in VS Code with the Lua extension (sumneko). Every export then shows its parameters and return values, and typos are underlined.

2. Where the counter is

Both sides need the counter's position: the client to show the prompt, the server to refuse anyone standing elsewhere. Put it in shared.lua:

Config = {
    Counter = vector3(-361.0, 49.0, 54.4),   -- just in front of where new characters spawn
    Price   = 15,
}

For your own spot, stand there in game, open /w → Coords and press G to copy vector4(x, y, z, heading).

3. The item, and the one rule#

whip_core keeps everything you declare (items, use handlers, events, prompts) in memory, and forgets it when it restarts. So declare in Whip.register: it runs your function once whip_core is ready and again after every restart. In server.lua:

Whip.register(function()
    Whip.core:RegisterItem('mycafe_coffee', {
        name     = 'Coffee',
        desc     = 'Hot and black. Quenches thirst.',
        weight   = 0.3,
        type     = 'consumable',
        stack    = true,
        maxStack = 10,
        usable   = true,
    })
end)

Running it twice is safe: registering the same thing again changes nothing (the registration rule). Every item field is under Item Definition. A refusal is printed in the server console, with the reason.

Call whip_core through Whip.core in there, so a refusal is printed for you. One function can hold every declaration, a loop over your Config too (The satellite helper).

Don't wait and hope. CreateThread(function() Wait(1000) … end) registers once, so a whip_core restart silently strips your items. Watching onResourceStart misses the first start. Use Whip.register.

4. Drinking it

Below it, say what using the coffee does. Passing RegisterUseHandler a table makes it a timed use: WHIP shows the bar, plays the animation and props, and times it on the server so a modified client can't skip it. When the bar ends, WHIP takes the coffee and runs onComplete.

Whip.register(function()
    Whip.core:RegisterUseHandler('mycafe_coffee', {
        label    = 'Drinking coffee...',
        duration = 4000,
        anim     = { dict = 'amb@world_human_drinking@coffee@male@idle_a', clip = 'idle_c' },
        prop     = { model = 'p_amb_coffeecup_01', bone = 28422 },
        disable  = { move = false },

        -- Return AddStat's result: if it fails, WHIP gives the coffee back
        onComplete = function(source)
            return exports.whip_core:AddStat(source, 'thirst', 20, 'item:mycafe_coffee')
        end,
    })
end)

Thirst runs from 100 (full) down to 0, and new characters start full (Stats & Effects). Every field is on the timed use card.

Try it: in the server console, refresh then ensure mycafe (later, restart mycafe). In game, /whip → Economy → Items, give yourself a coffee, press F2, right-click it and choose Use.

5. Selling it

A SecureEvent is RegisterNetEvent with the checks built in. Also in server.lua:

-- The client sends nothing: not the price, not the item
Whip.register(function()
    Whip.core:SecureEvent('mycafe:buy', {
        rateLimit = 1000,   -- one purchase a second per player
        near = { at = Config.Counter, range = 3.0, message = 'Walk up to the counter' },
    }, function(source)
        local receipt, err = exports.whip_core:ChargePlayer(source, Config.Price, { reason = 'Coffee' })
        if not receipt then
            return false, err            -- couldn't pay: WHIP shows them why
        end

        local given, why = exports.whip_core:AddItem(source, 'mycafe_coffee', 1)
        if not given then
            exports.whip_core:RefundPlayer(receipt)   -- paid but got nothing: money back
            return false, why
        end

        exports.whip_core:NotifyPlayer(source, 'Enjoy your coffee', 'success')
    end)
end)

Inside a handler whip_core runs, call exports directly. In your own code (a thread, a command, a timer), use Whip.core:ChargePlayer(...), which returns false, why instead of erroring when whip_core isn't running (Calling whip_core).

6. The counter

In client.lua, put a prompt at the counter. Walk up and press E to send the event:

Whip.register(function()
    Whip.core:AddAction({
        id       = 'counter',
        at       = { coords = Config.Counter },
        label    = ('Buy coffee ($%d)'):format(Config.Price),
        icon     = 'cash',
        onSelect = function()
            TriggerServerEvent('mycafe:buy')
        end,
    })
end)

The same call puts an option on an entity, a car part or the F1 wheel (AddAction). It's removed automatically when your resource stops.

7. Try it

  1. restart mycafe, walk to the counter and press E. $15 goes, a coffee arrives.
  2. Open /whip → System → Monitor: each mycafe:buy is listed, accepted or refused, with the reason.
  3. Drink the coffee: the bar runs with the cup in your hand.

If nothing happens, check the server console and F8 for errors, and check each call's return values: a refusal returns false and a reason (Return values). To give the coffee a picture, add html/img/items/mycafe_coffee.webp and files { 'html/img/items/*.webp' } to the manifest (Item icons).

Next

ToRead
Staff the stand: a job, a duty prompt, payYour First Job
Accept a value from the client safelyChecking the values
Ask the server something and wait for the answerSecureCallback
Stock, shelves and staffShops and Jobs
See whole resources built this wayLearning from gunny, whip_autos, rope