ScaleDraw
One Scaleform movie to rule them all! Say good bye to common Draw Natives, heavy and slow, increasing your resmon CPU time! Say Hello to ScaleDraw.
This Lua library allows you to create and manipulate scaleform-based shapes in FiveM, such as rectangles, circles, polygons, and sprites. It provides an easy-to-use API for drawing 2D elements with customizable properties.
Features
- Create rectangles, circles, polygons, and sprites with none to low CPU time increase.
- Set position, size, scale, rotation, and color
- Update textures for sprites
- Show, hide, and remove items
- Efficient scaleform-based rendering
Installation
- Clone the repository from my github: GitHub - manups4e/ScaleDraw: One Scaleform movie to rule them all!
- Place the lua files in your desired script or make a new folder called how you want in your FiveM Server resources folder. It is HIGLY adviced to put the scaleform
DRAW_ALL.gfx
into a separated assets resource so that in case of a script restart it won’t be affected. - Start the script.
Usage
Here’s how to use the library in your FiveM project:
Create a Rectangle
-- in case of exports
local rect = exports['yourresource']:CreateRect(0.5, 0.5, 0.2, 0.1, 255, 0, 0, 200)
-- in case of non exports
local rect = CreateRect(0.5, 0.5, 0.2, 0.1, 255, 0, 0, 200)
Create a Circle
-- in case of exports
local circle = exports['yourresource']:CreateCircle(0.5, 0.5, 0.1, 0.1, 0, 255, 0, 200)
-- in case of non exports
local circle = CreateCircle(0.5, 0.5, 0.1, 0.1, 0, 255, 0, 200)
Create a Polygon
-- in case of exports
local polygon = exports['yourresource']:CreatePoly(6, 0.5, 0.5, 0.2, 0.2, 0, 0, 255, 200)
-- in case of non exports
local polygon = CreatePoly(6, 0.5, 0.5, 0.2, 0.2, 0, 0, 255, 200)
Create a Sprite
-- in case of exports
local sprite = exports['yourresource']:CreateSprite('commonmenu', 'shop_box_tick', 0.5, 0.5, 0.1, 0.1, 255, 255, 255, 255)
-- in case of non exports
local sprite = CreateSprite('commonmenu', 'shop_box_tick', 0.5, 0.5, 0.1, 0.1, 255, 255, 255, 255)
API Reference
You can call the API via exports and / or via direct calls if you include the script directly into your resources (you’ll need all the files in the Client folder)
Creation Methods
- CreateRect(x, y, w, h, r, g, b, a): Creates a rectangle and returns its handle.
- CreateCircle(x, y, w, h, r, g, b, a): Creates a circle and returns its handle.
- CreatePoly(sides, x, y, w, h, r, g, b, a): Creates a polygon with the given sides and returns its handle.
- CreateSprite(txd, txn, x, y, w, h, r, g, b, a): Creates a sprite from a texture dictionary and returns its handle.
Update Methods
- SetItemPosition(handle, x, y): Updates an item’s position.
- SetItemSize(handle, w, h): Updates an item’s size.
- SetItemScale(handle, scale): Scales an item.
- SetItemColor(handle, r, g, b, a): Changes an item’s color.
- SetItemRotation(handle, rotation): Rotates an item (0 to 360 degrees).
- SetItem3DRotation(handle, xrot, yrot): Rotates an item in 3D space.
- SetItemVisible(handle, visible): Shows or hides an item.
- UpdateSprite(handle, txd, txn, w, h): Updates a sprite’s texture and size.
Cleanup Methods
- RemoveItem(handle): Removes an item.
- ClearAll(): Clears all created items.
Special thanks to the FiveM community for continued support and inspiration.