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

Learning from rope

Most of whip_rope is rope physics (client/physics.lua, client/collision.lua, client/contact.lua), which teaches nothing about WHIP. These are the smaller parts worth reading; for the patterns gunny shows, see Learning from gunny.

The game acts first, the server corrects it

Picking up or tying an end changes the rope on the player's game at once, so it feels instant at any ping, then asks the server through a SecureEvent. A refusal, in the handler or before it (through the schema's onReject), sends that game the rope as the server has it. Every end change goes through Rope.ApplyEnd, which skips an unchanged end, so the server's echo does nothing.

-- client/interaction.lua: the end in the hand at once, then the ask
Rope.ApplyEnd(rope, which, { type = 'held', heldBy = Rope.MyServerId() })
TriggerServerEvent('whip_rope:take', rope.serverRopeId, which)

-- server/main.lua: a refusal, in the handler or before it, sends their game the rope as the server has it
local function refuse(source, ropeId, why)
    Ropes.correct(source, ropeId)
    return false, why                                 -- WHIP shows `why` to the player
end
-- in the SecureEvent's schema; `raw` is what the game sent, not checked yet
onReject = function(src, _, raw) Ropes.correct(src, tonumber(type(raw) == 'table' and raw[1])) end,

What a game tells the server is a claim

A report about something the server can't see is checked against what it can.

Nothing a player owns is lost

A rope still out when its owner leaves, or whip_rope stops, is owed back to their character in whip_rope's resource KVP, and paid as that character loads. The debt comes off the books before the give, so two loads can't both be paid, and goes back on if the give fails.

-- server/item.lua
local function payOwed(source, charId)
    local owed = Ropes.takeOwed(charId)               -- off the books first
    if owed <= 0 then return end
    if not Ropes.giveItem(source, owed, 'ropes you had out') then
        Ropes.owe(charId, owed)                       -- the give failed: owed again
    end
end

A bar the server times, and a look after it

Coiling up runs the server Progress through Whip.core from a SecureEvent handler, which may wait (a SecureCallback may not). The bar takes seconds, so the handler looks again after it: the rope may be gone or in someone else's hands. Pockets that won't take the item make it owed instead.

-- server/main.lua, onCoil (trimmed)
local done = Whip.core:Progress(source, { label = 'Coiling up the rope', duration = Config.Item.CoilDuration or 3000, canCancel = true })
if done ~= true then return false end             -- cancelled, or they left
if Ropes.all[ropeId] ~= rope or Ropes.heldBy(source, true) ~= rope then return false end   -- still there, still theirs?
Ropes.remove(ropeId)
if not Ropes.giveItem(source, 1, 'rope coiled up') then Ropes.owe(player and player.charId, 1) end

A prompt where the player looks

The tie prompt is a whip_core action with aimBox (at: where it lives): it sits where the player's look meets a car, prop or the map, and ctx.coords is that point. An aimBox action casts a ray every frame while it exists, so whip_rope adds it only while an end is in the hand.

-- client/ui.lua (trimmed)
local TIE = {
    id = 'tie', group = 'whip_rope', label = 'Tie the rope here', reach = Config.Rules.Reach,
    at = { aimBox = { 'vehicle', 'object', 'world' } },   -- a car, a prop, or the map itself
    onSelect = function(ctx) Rope.TieHeldEnd(ctx.entity, ctx.coords, ctx.world, ctx.normal) end,
}
-- five times a second: up only while an end is in the hand
local wantTie = Rope.MyHeld() ~= nil
if wantTie ~= tieUp then
    if wantTie then tieUp = Whip.core:AddAction(TIE) == true
    else Whip.core:RemoveAction('tie'); tieUp = false end
end
Without dependency 'whip_core', reset the flag. The action lives in whip_core's memory. A resource that keeps running through a whip_core restart must reset its "prompt is up" flag in Whip.onCoreLost, or the prompt never comes back.

Where to look#

To see how toRead
Check what a game asks, and put it right on a refusalserver/main.lua: refuse, its Whip.register block
Change things on the player's game before the server repliesclient/interaction.lua: Rope.TakeEnd, Rope.TieHeldEnd, Rope.ApplyEnd
Put the game right when the server says noclient/sync.lua: whip_rope:correction
Check what a game tells you against what the server can seeserver/main.lua: believable, onShot; server/api.lua: onStretched, onEndBroken
Let go of what a player had when they die, log out or leaveserver/main.lua: its last event handlers; server/state.lua: Ropes.playerGone
Owe an item back, kept on diskserver/state.lua: Ropes.owe; server/item.lua: payOwed
Register an item whose use puts something in the worldserver/item.lua: registerItem, onUse
Run a bar the server timesserver/main.lua: onCoil
Prompts, wheel entries and the hint capsuleclient/ui.lua
A settings page that changes things at onceshared/settings.lua: Whip.configPage, Whip.onConfigChanged
Hold the player's ped and slow their walkclient/interaction.lua: HangPedOn, applyHoldWalk (HoldPlayerPed, BlockControls)
Offer an API to other resources, each owning what it madeserver/api.lua (keyed to GetInvokingResource(), cleaned up in onResourceStop); client/api.lua
Use the rope API from your own resourcewhip_fuel/server/hose.lua: draw; whip_fuel/client/pumps.lua
Loops that rest while there's nothing to doclient/main.lua, client/ui.lua (Rope.Const.IDLE_MS)