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

Rope API

Make ropes from your own resource (a tow line, a winch, a hose) with exports.whip_rope. New to ropes? Read Rope System first.

Add dependency 'whip_rope', or, if you can work without ropes, check GetResourceState('whip_rope') == 'started' before a call. whip_fuel's pump hose (whip_fuel/server/hose.lua) uses everything here.

Your ropes#

Only your resource can move a rope it made with SetRopeEnd, or remove it. It stays when its player leaves, goes when your resource stops, is never an item and never counts against a player's ropes. Its length is fixed: for another, remove it and create it again.

With locked = true, nobody else moves it, and holding its end isn't holding a rope. Unlocked, players handle it like any rope and you aren't told (read GetRope): put its end in a player's hand and whip_rope's tie prompt lets them hook it to any car.

A rope's ends#

Each end is a table, in the same shape for CreateRope, SetRopeEnd and GetRope.

EndFields
{ type = 'held' }heldBy: a player's server id. It ends at their right hand (or at heldAt's prop)
{ type = 'fixed' }pos: a spot in the world; tied = true: tied to the map there (players see Untie), not put down
{ type = 'vehicle' }netId: a networked car; offset: where on it, in the car's space (default its middle), or edge = 'front' / 'back'
{ type = 'object' }netId: a networked prop, or 0 for a map prop, which then needs model (a hash: `prop_gas_pump_1a`) and worldPos, and may give point (where it's tied, default worldPos); offset; still = true: never pulled loose; mass in kg (otherwise guessed from its size)
{ type = 'free' }Loose. GetRope also gives at, where it was let go, when the server knows
An end can come loose with no notice. On any rope when the car or prop it's tied to goes (garaged, deleted, despawned); on an unlocked rope also when its holder dies or leaves, or a player unties it. Check GetRope before you rely on it.

Server

CreateRope(spec)SERVER#

Makes a rope between two things, built on every game near it.

spec fieldTypeDescription
origin, tailtableIts two ends. At least one must be held, fixed, or tied to a car or prop
lengthnumber?Metres, 0.5 to 100 (default: the item rope's length setting). Fixed for the rope's life
linknumber?Metres between nodes (default: the item rope's). At most 64 nodes: past that, links are made longer
playernumber?The player it's for: their game always has the rope
kindstring?A tag of your own, up to 32 characters, returned by GetRope
lockedboolean?true: nobody can grab, tie, put down, coil or hang off it. Left out, players handle it like any rope but can't coil it (locked or not)
take, hangboolean?On an unlocked rope: take = false, nobody picks up or unties its ends; hang = false, nobody hangs off it. Change with SetRopeRules
looktable?{ model, modelNoShadow, thickness }: its own rope pieces, modelled as whip_rope_seg (whip_rope/docs/whip_rope_seg.txt). Models are hashes; a quoted name is dropped
collidetable?{ spacing, vehicles, props }: every spacing'th node is checked (default 2), and whether cars and props count (default: the Rope settings). The map always counts
heldAttable?{ model, offset }: a held end sits at offset on the prop of that model in the hand (a pump's nozzle). This model may be a name or a hash
watchtable?{ stretch, holdMs, broken }: whip_rope:ropeStretched when pulled stretch past its length (0.35: 35%) for holdMs (default 250); broken = true: whip_rope:ropeEndBroken when a map prop it's tied to is blown up
maxStretchnumber?A hard length, 0 to 2 (0.2: 20% past it): past it, one pull draws both ends together, each moved by its weight. Left out, the rope is elastic with no hard end
Returns: number: the rope's id, or false, reason: what's wrong with an end ('tail: a vehicle end names netId'), or 'neither end is anywhere yet'
-- A 6 m tow line from a truck's back to the car behind it, that players can't take off
local id, why = exports.whip_rope:CreateRope({
    origin = { type = 'vehicle', netId = NetworkGetNetworkIdFromEntity(truck), offset = vector3(0.0, -3.2, 0.6) },
    tail   = { type = 'vehicle', netId = NetworkGetNetworkIdFromEntity(car),   offset = vector3(0.0, 2.1, 0.3) },
    length = 6.0, locked = true, kind = 'towline',
})
if not id then print('no tow line: ' .. why) return end
How maxStretch holds

The pull is at most a very strong hose's: a snag jolts the car, and the rope stretches for a moment up to twice maxStretch (Config.Coupling.HardCeiling), where it holds. A car driving away from something that doesn't move is never held back. With watch.stretch above maxStretch, the notice comes only when neither end can follow: whip_fuel's hose (0.3 and 0.35) is told only when a car drives off with the nozzle in.

SetRopeEnd(id, which, end)SERVER#

Moves one end of a rope your resource made. Every game is told.

ParamTypeDescription
idnumberThe rope's id
whichstring'origin' or 'tail'
endtableWhere it goes: an end
Returns: true, or false, reason: 'not your rope' (another resource's, or gone), a bad which, or what's wrong with the end
exports.whip_rope:SetRopeEnd(id, 'tail', { type = 'held', heldBy = source })
A locked rope's held end is yours to move. whip_rope never lets it go for you: move it on whip_core:player:died, whip_core:player:logout and playerDropped, as whip_rope's server/main.lua does.
SetRopeRules(id, rules)SERVER#

Changes what players may do with a rope your resource made, and its stretch notice, from now on. A field left out stays as it was.

ParamTypeDescription
idnumberThe rope's id
rulestable{ take?, hang?, stretch? }: take and hang as CreateRope takes them; stretch is its watch.stretch, or false to stop it
Returns: true, or false, reason: 'not your rope', or a rule it can't read
exports.whip_rope:SetRopeRules(id, { take = false })   -- the winch is set: nobody unhooks it now
RemoveRope(id)SERVER#

Removes a rope your resource made, on every game.

Returns: true, or false when it's another resource's or already gone
GetRope(id)SERVER#

Any rope's tag, ends and length, a player's or a resource's.

Returns: { kind, origin, tail, length } (its ends as the server keeps them), or nil
local rope = exports.whip_rope:GetRope(id)
if rope and rope.tail.type == 'held' then print(rope.tail.heldBy, rope.length) end

Client

GetRopeEndEntity(id, which)CLIENT#

The car or prop a rope's end is tied to on this game. A SetRopeEnd move has reached this game once this returns the new one.

ParamTypeDescription
idnumberThe rope's id
whichstring'origin' or 'tail'
Returns: the entity, or nil: not tied to one, not streamed in yet, or no such rope here

The notices#

Every resource hears every rope's notices: check that resource is yours.

EventSideArgsWhen
whip_rope:ropeStretchedServerid, resourcePulled past watch.stretch for watch.holdMs, and again every 3 seconds while it stays so: act once. Believed only when the ends really are far apart and the reporting player is near
whip_rope:ropeEndBrokenServerid, which, resourceA map prop that end is tied to was blown up (watch.broken), with an explosion the server saw
whip_rope:ropeRemovedServerid, resource, whywhip_rope removed it (/clearropes): forget the id. Not sent for your own RemoveRope or when your resource stops
whip_rope:pulledFromHandClientid, which, resourceLocked ropes only, on the holder's game: the other end dragged them and they let go, or died. The end stays theirs until your server moves it
-- Client: a locked line pulled from this player's hand
AddEventHandler('whip_rope:pulledFromHand', function(id, which, resource)
    if resource ~= GetCurrentResourceName() then return end
    TriggerServerEvent('mytow:dropLine', id)
end)

-- Server, inside Whip.register: drop it at their feet
Whip.core:SecureEvent('mytow:dropLine', { params = { { 'id', 'id', 1, 2147483647 } } }, function(source, player, id)
    local rope = exports.whip_rope:GetRope(id)
    if not rope or rope.tail.type ~= 'held' or rope.tail.heldBy ~= source then return end   -- theirs to drop
    exports.whip_rope:SetRopeEnd(id, 'tail', { type = 'fixed', pos = GetEntityCoords(GetPlayerPed(source)) })
end)
When whip_rope restarts, your ropes go with it. No notice is sent, and ids start again from 1. Forget yours on its onResourceStop, and make them again on its onResourceStart, as whip_fuel's hoses do.