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.
| End | Fields |
|---|---|
{ 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 |
GetRope before you rely on it.Server
Makes a rope between two things, built on every game near it.
| spec field | Type | Description |
|---|---|---|
| origin, tail | table | Its two ends. At least one must be held, fixed, or tied to a car or prop |
| length | number? | Metres, 0.5 to 100 (default: the item rope's length setting). Fixed for the rope's life |
| link | number? | Metres between nodes (default: the item rope's). At most 64 nodes: past that, links are made longer |
| player | number? | The player it's for: their game always has the rope |
| kind | string? | A tag of your own, up to 32 characters, returned by GetRope |
| locked | boolean? | 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, hang | boolean? | On an unlocked rope: take = false, nobody picks up or unties its ends; hang = false, nobody hangs off it. Change with SetRopeRules |
| look | table? | { 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 |
| collide | table? | { 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 |
| heldAt | table? | { 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 |
| watch | table? | { 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 |
| maxStretch | number? | 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 |
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.
Moves one end of a rope your resource made. Every game is told.
| Param | Type | Description |
|---|---|---|
| id | number | The rope's id |
| which | string | 'origin' or 'tail' |
| end | table | Where it goes: an end |
true, or false, reason: 'not your rope' (another resource's, or gone), a bad which, or what's wrong with the endexports.whip_rope:SetRopeEnd(id, 'tail', { type = 'held', heldBy = source })
whip_core:player:died, whip_core:player:logout and playerDropped, as whip_rope's server/main.lua does.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.
| Param | Type | Description |
|---|---|---|
| id | number | The rope's id |
| rules | table | { take?, hang?, stretch? }: take and hang as CreateRope takes them; stretch is its watch.stretch, or false to stop it |
true, or false, reason: 'not your rope', or a rule it can't readexports.whip_rope:SetRopeRules(id, { take = false }) -- the winch is set: nobody unhooks it now
Removes a rope your resource made, on every game.
true, or false when it's another resource's or already goneAny rope's tag, ends and length, a player's or a resource's.
local rope = exports.whip_rope:GetRope(id)
if rope and rope.tail.type == 'held' then print(rope.tail.heldBy, rope.length) end
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.
| Param | Type | Description |
|---|---|---|
| id | number | The rope's id |
| which | string | 'origin' or 'tail' |
nil: not tied to one, not streamed in yet, or no such rope hereThe notices#
Every resource hears every rope's notices: check that resource is yours.
| Event | Side | Args | When |
|---|---|---|---|
whip_rope:ropeStretched | Server | id, resource | Pulled 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:ropeEndBroken | Server | id, which, resource | A map prop that end is tied to was blown up (watch.broken), with an explosion the server saw |
whip_rope:ropeRemoved | Server | id, resource, why | whip_rope removed it (/clearropes): forget the id. Not sent for your own RemoveRope or when your resource stops |
whip_rope:pulledFromHand | Client | id, which, resource | Locked 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)onResourceStop, and make them again on its onResourceStart, as whip_fuel's hoses do.