- Documentation
- Drawing (dx)
Category
Drawing (dx)
All Lua functions and events in the Drawing (dx) category, on the server and the client.
Client functions 91
attachAttaches the camera to an element (a vehicle, a player, a ped, an object, a model object). The position and target are in metres in the element's frame (x right, y forward, z up); the target defaults to 10 m in front of the camera. A rear-view mirror is a camera at the back of the car looking backwards plusCamera Render setCameraRenderMirrored.createCreates a second camera that renders the world into a texture: a car mirror, CCTV, a screen showing a drone view. Draw the texture withCamera Render dxDrawImage,dxDrawMaterialLine3Dor pass it to a shader. Size 16-2048 pixels, 0-60 shots per second (0 = only on request withrenderCameraMatrix/updateCameraRender). Every shot is an extra scene render, so it costs performance.createNewLays an image on the ground - a track, a stain or a place marker. The image follows slopes and kerbs instead of hanging flat above them. It is drawn up to 150 m from the camera, and with a lifetime set the last second fades out smoothly. The decal stays until destroyGroundDecal or until the resource stops.Ground Decal createCreates a recording from AVI (MJPEG) data: fromRecording From Data getRecordingData, a file or another player.createCreates a recording player that is a texture: you draw it like any texture, also in the world withRecording Player dxDrawMaterialLine3D. The recording can be deleted afterwards; the player keeps its own frames.destroyNewRemoves a decal made with createGroundDecal.Ground Decal detachDetaches the camera from an element; it stays at the spot of the last shot.Camera Render dxConverts pixels to another format:Convert Pixels plain,pngorjpeg(with quality 1-100).dxCreates a font from a resource TTF/OTF file or from a system typeface (pass its name). The size is in points. Pass the font toCreate Font dxDrawTextandguiSetFont.dxCreates an off-screen drawing surface. AfterCreate Render Target dxSetRenderTarget(rt)everydxDraw*draws on it, and then you draw it like a texture. Without an alpha channel every pixel is opaque.dxCreates a screen source of a given size.Create Screen Source dxUpdateScreenSourcewrites the game image into it (scaled), which you then draw or process with a shader.dxCreates a texture: from a resource image file, from pixels (Create Texture plain,png,jpeg,dds) or an empty one of a given size. The texture is a material fordxDrawImage,dxDrawMaterial*3Dand shaders.dxDraws a rectangle with a fill and a border of a given thickness in one call.Draw Bordered Rectangle dxDraws a circle, an ellipse or a pie slice with centre (x, y) and a radius in pixels. The short form takes just a colour as the fourth argument.Draw Circle dxDraws a rectangle with a vertical blend from the top colour to the bottom one.Draw Gradient Rectangle dxDraws an image (a resource PNG/JPG file, a texture, a render target, a browser or a camera) in a screen rectangle, with optional rotation and tint.Draw Image dxDraws a section of an image (u, v, section width and height in image pixels) in a screen rectangle. Useful for icon sheets and progress bars.Draw Image Section dxDraws a line between two screen points.Draw Line dxDraws a line between two world points: projects them onto the screen and joins them. It only draws when both ends are on screen and is not hidden by buildings.Draw Line3 D dxDraws a material (an image, a texture, a browser, a camera or a shader) as a strip in the 3D world: from the start point (top of the image) to the end, with a given width. The strip faces the camera or theDraw Material Line3 D faceX, faceY, faceZpoint. The drawing is part of the world: buildings hide it and it glows (a screen is visible at night). This is how you make a billboard, a cinema screen or a sign above a building.dxDraws a triangle shape in the 3D world covered with a material. Vertices areDraw Material Primitive3 D {x, y, z, color, u, v}, where u and v (0-1) tell which image point lands on the vertex. The colour of the whole shape comes from the first vertex.dxLikeDraw Material Section Line3 D dxDrawMaterialLine3D, but draws only a section of the material (u, v, section width and height in pixels).dxDraws a game object model at a spot for one frame: without collision, hidden by the world. It does not work for peds and vehicles. The first frame of a new model waits until the game loads it. At most 64 objects at once.Draw Model3 D dxDraws a 2D shape from a list ofDraw Primitive {x, y [, color]}vertices: points, lines or triangles. The colour is blended smoothly between vertices.dxDraws a shape made of triangles in the 3D world fromDraw Primitive3 D {x, y, z, color}vertices. The whole shape has the colour of the first vertex.dxDraws a filled rectangle on the screen for one frame. Call it inDraw Rectangle onClientRenderto keep it visible.dxDraws a rectangle with rounded corners. The radius is in pixels and never exceeds half of the shorter side.Draw Rounded Rectangle dxDraws text on the screen for one frame. Call it inDraw Text onClientRenderto keep it visible.dxDraws a wire sphere in the world (for debugging, e.g. a zone range). It is drawn on the screen, so it shows through walls.Draw Wired Sphere dxReturns the mode set withGet Blend Mode dxSetBlendMode("blend"by default).dxReturns the font set withGet Default Font dxSetDefaultFontin this resource or"default".dxReturns the current resource'sGet Draw Priority dxSetDrawPrioritysetting:"overHud"(the default) or"underHud".dxReturns the height of one line of text in pixels for a scale and a font.Get Font Height dxReturns a font description: the typeface (Get Font Info family), the size in pixels (px) and points (size), style settings and the source.dxReturns the names of the built-in fonts:Get Font List default,default-bold,clear,arial,sans,pricedown,bankgothic,diploma,beckett,unifont,inter,inter-medium,inter-semibold,inter-bold.dxReturns the width and height of a material: a texture, a render target, a browser or a shader.Get Material Size dxReturns the colour of pixel (x, y) from pixels inGet Pixel Color plainformat.dxTells which format pixels are in:Get Pixels Format "plain","png","jpeg","dds"orfalse.dxReturns the width and height of an image stored in pixels (any format).Get Pixels Size dxReturns the drawing state: the test mode, the resolution, the number of script textures, render targets and screen sources, and texture memory. Useful for finding texture leaks.Get Status dxReturns the width and height of a block of text, also when wrapped to a given width.Get Text Size dxReads the pixels of a texture, a render target or a screen source inGet Texture Pixels plain,pngorjpegformat, whole or from a section (x, y, width, height). For example for a screenshot.dxReturns the width of text in pixels for a given scale and font (like inGet Text Width dxDrawText). Useful for centring and boxes fitted to text.dxReturns the size of a resource image file in pixels, without creating a texture.Image Size dxReturns the setting fromIs Aspect Ratio Adjustment Enabled dxSetAspectRatioAdjustmentEnabled.dxTurns on drawing aspect ratio correction on wide screens. The value is stored for compatibility with existing scripts (Set Aspect Ratio Adjustment Enabled dxIsAspectRatioAdjustmentEnabled) but does not change drawing; compute positions fromguiGetScreenSize.dxSets the colour blending mode for drawing (Set Blend Mode blend,add,modulate_add,overwrite). The value is stored for compatibility with existing scripts (dxGetBlendMode), but drawing always uses normal blending.dxSets the fontSet Default Font dxDrawTextuses when none is given, only in the current resource.nilrestores the default.dxSets whether the resource's normal 2D drawings (Set Draw Priority dxDrawRectangle,dxDrawText,dxDrawImage,dxDrawLineand others withoutpostGUI) are drawn above the game HUD and radar ("overHud", the default) or below them ("underHud"). The setting applies to the resource's nextdxDraw*calls and stays until changed; every resource has its own. You can switch inside oneonClientRender: some drawings below the HUD, some above it. Drawings withpostGUI = trueare always on top of everything.dxChanges the style of a font fromSet Font Style dxCreateFont:bold,italic,underline,strike,weight,spacing,widthScale,shadow,outline,outlineColor,gradient,lineSpacing,size. Pass one key or a table.dxSets the colour of pixel (x, y) inSet Pixel Color plainpixels and changes the passed string. Images smaller than 4x4 are rejected.dxSets where theSet Render Target dxDraw*functions draw: on a render target (optionally clearing it first) or, without an argument, on the screen. It only works inonClientRenderandonClientPreRender; after the event drawing goes back to the screen.dxTurns on a test mode to check that a script handles failures:Set Test Mode "no_mem"(creating textures fails),"low_mem"(no effect),"no_shader"(dxCreateShaderfails),"none"(off).dxSets what a texture shows outside its image in sections (Set Texture Edge dxDrawImageSection): repeat (wrap), mirror (mirror), stretched edge (clamp) or a border colour (border).dxWrites pixels (Set Texture Pixels plain,png,jpeg) into a texture or a render target, whole or into a section.dxRefreshes a screen source with the game image (without the script overlay). The image arrives 1-2 frames later.Update Screen Source getReturns the element the camera is attached to.Camera Render Attached To getReturns the camera's current brightness multiplier and whether it is automatic.Camera Render Exposure getReturns the set number of shots per second (Camera Render Frame Rate getCameraRenderInfogives the measured one).getReturns the camera state:Camera Render Info state, the number of frames in the texture (frames), measured shots per second (fps), whether the image arrives (ready), whether the attached element disappeared (attachLost) and an error (error).getReturns the camera placement: x, y, z, the target, roll and field of view. For a camera attached to an element it gives the spot of the last shot.Camera Render Matrix getReturns the camera view distance in metres (0 = like the game).Camera Render View Distance getReturns the whole recording as an AVI (MJPEG) file in a string, e.g. forRecording Data fileWrite, sending to the server orcreateRecordingFromData.getReturns the pixels of one recording frame (number from 1) inRecording Frame jpeg(default),pngorplainformat, e.g. fordxCreateTextureor saving a photo.getReturns recording information: whether it runs (Recording Info recording), the frame count, frames per second, the length in ms (duration), the image size, the data size in bytes (size) and the stop reason (stopReason).getReturns the player position and the recording length in milliseconds.Recording Player Position getReturns the occlusion check state: whether it is on (World Point Occlusion Info enabled), whether the game answers (available), the number of checks (checks), the queue (queue) and stored points (cached).isChecks whether the recording is still running (it stops by itself after the maximum time, a memory limit or when the camera is removed).Camera Recording isChecks whether a value is a working camera fromCamera Render createCameraRender.isChecks whether the camera image is mirrored.Camera Render Mirrored isChecks whether the player is playing (not paused and not at the end without a loop).Recording Player Playing isChecks whetherWorld Point Occlusion Enabled isWorldPointVisiblechecks occlusion.isChecks whether a world point is on screen and not hidden by a building or terrain. Occlusion is checked in the background, so the result for a new point arrives after a moment. For 3D labels and markers that should not show through walls.World Point Visible loadLoads a recording from a resource AVI (MJPEG) file.Recording renderTakes one shot from the given spot (likeCamera Matrix setCameraRenderMatrixandupdateCameraRenderat once). The image appears in the texture 1-2 frames later; it also works at 0 shots per second.saveSaves a recording to an AVI file in the resource (overwrites an existing one, likeRecording fileCreate).setHides an element only in this camera's image, e.g. your own car in the mirror or the player holding a phone. The element's shadow stays. Up to 64 elements per camera.Camera Render Element Hidden setSets the camera image brightness:Camera Render Exposure "auto"(default, picks a 0.5-4 multiplier from the frame brightness like a camera) or a fixed 0.05-16 multiplier. The camera image has lifted shadows so it looks similar to the game at night.setSets how many shots per second the camera takes (0-60; 0 = only on request).Camera Render Frame Rate setPlaces the camera likeCamera Render Matrix setCameraMatrix: the position, the point it looks at, roll and field of view (5-170, 70 by default). It detaches the camera from an element.setMirrors the camera image horizontally (a mirror). Also applies to recordings from this camera.Camera Render Mirrored setSets the camera view distance in metres (0 = like the game). A shorter distance means a cheaper render, e.g. for a mirror.Camera Render View Distance setNewChanges the colour of a decal made with createGroundDecal.Ground Decal Color setTurns looped playback on or off.Recording Player Looped setPauses or resumes a player. Resuming after the end starts from the beginning.Recording Player Paused setSeeks the player to a given millisecond of the recording.Recording Player Position setSets the playback speed 0-16 (1 = normal, 0.5 = slow motion).Recording Player Speed setTurns occlusion checks inWorld Point Occlusion isWorldPointVisibleon or off (false= points visible through walls, for debugging).startRecords the image of a camera fromCamera Recording createCameraRenderinto memory (no sound). Returns a recording element. 1-60 frames per second, up to 600 seconds, JPEG quality 1-100. The camera should take at least as many shots per second as the recording, otherwise frames repeat.stopStops recording. The recording stays available for playback and saving. ReturnsCamera Recording falseif it was no longer recording.updateRequests one camera shot in the next frame (the image is in the texture 1-2 frames later).Camera Render
Client events 3
onArrives every frame beforeClient Pre Render onClientRender, without drawing. It gets the time since the previous frame, so it suits smooth movement (cameras, animations).onTriggered every game frame. This is where you draw everything that should stay on screen: HUD, counters, text.Client Render onThe game resolution or window size changed. Recompute interface positions then.Client Screen Size Change