- Documentation
- Elements
Category
Elements
All Lua functions and events in the Elements category, on the server and the client.
Server functions 30
addSubscribes a player to changes of one element data value. Works with values set inElement Data Subscriber "subscribe"mode: only subscribed players receive them, which saves network traffic.cloneCreates a copy of an element (vehicle, object, ped, marker and so on) at the given place.Element getReturns the element's rotation speed around the X, Y and Z axes.Element Angular Velocity getThe same asElement Bone Attachment Details getElementBoneAttachment(another name for compatibility with scripts).getReturns the n-th element of a type (from 0).Element By Index getReturns the n-th child of an element (from 0).Element Child getReturns an element's children in the tree, optionally only of one type.Element Children getReturns the number of an element's children.Element Children Count getReturns the collision shape assigned to a marker or pickup.Element Col Shape getReturns the players subscribed to an element data value.Element Data Subscribers getReturns the element's parent in the element tree.Element Parent getReturns the player who computes the element's physics (vehicle, object, ped) and sends its state to others.Element Syncer getReturns the name of the map zone where the element is (e.g. "Ganton"), or just the city.Element Zone Name hasChecks whether a player is subscribed to an element data value.Element Data Subscriber isChecks whether function calls on the element propagate to its children (yes by default).Element Call Propagation Enabled isChecks whether the element's model faces are drawn on both sides.Element Double Sided isChecks whether an element is a low-LOD object (a simplified model seen from afar).Element Low LOD isChecks whether an element is on fire.Element On Fire isChecks whether an element is visible to a player (seeElement Visible To setElementVisibleTo).removeUnsubscribes a player from an element data value.Element Data Subscriber setSets the element's rotation speed around the X, Y and Z axes.Element Angular Velocity setTurns on or off passing function calls from the element to its children.Element Call Propagation Enabled setAssigns a collision shape to a marker or pickup.Element Col Shape nilremoves the assignment.setTurns on drawing the model's faces on both sides.Element Double Sided setMarks an object as a low-LOD model.Element Low LOD setSets an element on fire or puts it out. With a duration in milliseconds the fire goes out by itself.Element On Fire setChanges the element's parent in the tree. Destroying the parent destroys the children too.Element Parent setSets the element's bounding radius used in geometry queries (e.g. line of sight, zones).Element Radius setChooses the player who computes the element's physics.Element Syncer trueornilrestores automatic choice.setShows or hides an element for a chosen player. Applies to blips, markers, text displays and similar.Element Visible To
Client functions 14
getReturns a ped bone's position in the world.Element Bone Position getReturns the box surrounding the element's model, relative to its centre.Element Bounding Box getReturns the distance from the element's centre of mass to the bottom of its model. Useful for placing elements on the ground.Element Distance From Centre Of Mass To Base Of Model getReturns the glow set withElement Highlight setElementHighlight.getReturns how strongly the element is lit (0 dark, 1 bright).Element Lighting isChecks whether two elements can collide.Element Collidable With isChecks whether an element exists only for this player (created by a client script, unknown to the server).Element Local isChecks whether an element is visible on the player's screen.Element On Screen isChecks whether an element may disappear when the player moves away (streaming).Element Streamable isChecks whether an element is loaded for this player.Element Streamed In isChecks whether the local player computes the element's physics.Element Syncer isChecks whether an element is waiting for the ground below to load (it is held in the air meanwhile).Element Waiting For Ground To Load setTurns collision between two elements on or off, only for this player and both ways. Handy for a ghost mode: your car passes through other players' cars but still hits walls, barrels and the rest of the map.Element Collidable With setTints an element's whole model with a glow colour for this player only: an NPC, a player (including your own character), a vehicle or an object. Called withElement Highlight falseinstead of a colour it removes the glow.
Shared functions 54
attachAttaches an element to another. The attached element moves and rotates together with the one it is attached to. An object attached to a vehicle is carried by the game in the same frame as the vehicle physics, so it stays exactly in place even at high speed and in turns.Elements createCreates an element of your own type, e.g.Element "house"or"zone". It sits under the current resource root and disappears when the resource stops. Useful for grouping elements and storing data.destroyDestroys an element together with its children. On the client it also destroys GUI elements.Element detachDetaches an element from the one it was attached to.Elements getReturns the elements attached to an element.Attached Elements getReturns the element's alpha (0 invisible, 255 opaque).Element Alpha getReturns the attached element's offset and rotation relative to the one it is attached to.Element Attached Offsets getReturns the element this one is attached to.Element Attached To getReturns the data of an element attached to a ped's bone.Element Bone Attachment getReturns the offset of an element attached to a bone.Element Bone Position Offset getReturns the rotation of an element attached to a bone (in degrees).Element Bone Rotation Offset getFinds an element by its text ID (from aElement By ID .mapfile orsetElementID).getChecks whether an element has collisions enabled (yes by default).Element Collisions Enabled getReturns an element's data value under a key. Data is set withElement Data setElementData; broadcast data is visible on the client too.getReturns the element's dimension. Elements in different dimensions cannot see each other.Element Dimension getReturns an element's health: peds 0-100 (up to 176 with full stamina), vehicles 0-1000 (below 250 it burns).Element Health getReturns the element's text ID.Element ID getReturns the element's interior number (0 is the outside world).Element Interior getReturns the element's matrix (position and rotation). By default a 4x4 table; withElement Matrix legacy = falseaMatrixobject.getReturns the element's model. For a playerElement Model -1means CJ in the outfit chosen in the launcher, and0plain CJ.getReturns an element's position in the world: a player, vehicle, object or marker.Element Position getReturns the element's bounding radius (the default for its type when not set).Element Radius getReturns the element's rotation in degrees.Element Rotation getReturns all elements of a type, optionally only under a given element (e.g.Elements By Type resourceRoot).getReturns the elements inside a collision shape, optionally of one type only.Elements Within Col Shape getReturns the elements that are inside a marker right now: players, vehicles, peds, objects, pickups and other markers. AElements Within Marker checkpointmarker is a circle with no height limit, the other types are a sphere with a radius equal to the marker size. The result can be limited to one type.getReturns elements within a radius of a point, optionally only of a given type and dimension.Elements Within Range getReturns the element type, e.g.Element Type "player","vehicle","ped","object". GUI elements have types prefixed with"gui-".getReturns the element's velocity. Units: 1 is 50 m/s, so km/h is the vector length times 180.Element Velocity hasChecks whether an element has a value under a key. UnlikeElement Data getElementData, it tells a missing value apart fromfalse.isChecks whether a value is an existing element. Use it before acting on an element that may have been destroyed.Element isChecks whether an element is attached to another.Element Attached isChecks whether an element is attached to a ped's bone.Element Attached To Bone isChecks whether an element is frozen (does not move).Element Frozen isChecks whether an element is in water.Element In Water isChecks whether an element is currently inside a collision shape.Element Within Col Shape isChecks whether an element is inside a marker.Element Within Marker removeRemoves an element data value under a key (for all players).Element Data setSets an element's alpha (0 invisible, 255 opaque). Works on players, peds, objects and vehicles (a vehicle together with its wheels).Element Alpha setChanges the offset and rotation of an attached element.Element Attached Offsets setChanges the offset of an element attached to a bone, without re-attaching it. The element moves relative to the bone right away.Element Bone Position Offset setChanges the rotation of an element attached to a bone, without re-attaching it.Element Bone Rotation Offset setTurns an element's collisions on or off.Element Collisions Enabled setStores a value under a key on an element. By default the value is sent to all players, which firesElement Data onElementDataChange.setMoves an element to another dimension. Elements in different dimensions cannot see each other.Element Dimension setFreezes or unfreezes an element. A frozen element does not move.Element Frozen setSets an element's health.Element Health 0kills a player or ped and firesonPlayerWasted/onPedWasted.setSets an element's text ID.Element ID setMoves an element to an interior. A player in an interior only sees buildings and elements with the same number.Element Interior setSets the element's position and rotation from a matrix (a 4x4 table or aElement Matrix Matrixobject).setChanges the element's model. For players and peds you can also pass the clothing and skin variant (0-3); without them the server picks one so everyone sees the same.Element Model setMoves an element to the given place. On the server it works for any element. On the client it moves your own character (up to 50 m it is a plain move in the same frame andElement Position getElementPositionreturns the new place right away, so it can be called every frame, e.g. for noclip; farther it is a teleport that loads the area), as well as client objects, sounds and collision shapes. An object moved every frame inonClientPreRenderis drawn in its new place in the same frame.setSets the element's rotation in degrees. On the client it turns your own character in the same frame (no teleport) and client objects.Element Rotation setSets the element's velocity (1 is 50 m/s). On the client it works for your own character and vehicle; on the ground the ped's animation cancels horizontal movement, vertical always works.Element Velocity
Server events 7
onAn element's data changed (Element Data Change setElementDataorremoveElementData), also from a client.onAn element is about to be destroyed (it still exists).Element Destroy onAn element moved to another dimension.Element Dimension Change onAn element moved to another interior.Element Interior Change onAn element's model changed (e.g. a player's skin or a car model).Element Model Change onA player started computing a vehicle's or object's physics (became its syncer).Element Start Sync onA player stopped computing an element's physics.Element Stop Sync
Client events 5
onNewAn element's data changed - through setElementData on the server or in a client script.Client Element Data Change onAn element moved to another dimension.Client Element Dimension Change onAn element moved to another interior.Client Element Interior Change onAn element appeared near the player (the game loaded it and draws it).Client Element Stream In onAn element moved away and the game stopped drawing it.Client Element Stream Out