- Documentation
- Client functions
- createElementPreview
Function
createElementPreview
Creates a preview of an element (a vehicle, a player, a ped, an object, a model object) as an image for dxDrawImage, e.g. for a car shop or a wardrobe. false as the target = the scene from the camera. By default the camera orbits the target so that it fits in the frame.
Syntax
preview createElementPreview(element|bool target [, int width = 256, int height])Arguments
targetelement|bool- The preview target.
widthint, optional = 256- Image width.
heightint, optional- Image height (same as the width by default).
Returns
The preview or false.
Example
The player's car turning in the corner of the screen.
local veh = getPedOccupiedVehicle(localPlayer)
local preview = veh and createElementPreview(veh, 320, 200)
addEventHandler("onClientRender", root, function()
if not preview then return end
setElementPreviewOrbit(preview, getTickCount() / 30 % 360, 15)
local img = getElementPreviewImage(preview)
if img then dxDrawImage(20, 20, 320, 200, img) end
end)
Notes
No camera setup. A model preview needs no manual object and camera placement and no external resources.
See also
setElementPreviewOrbitSets a camera orbiting the target: the horizontal angle (yaw, 0 = from the north), the vertical angle (pitch), the distance (0 = the whole target in frame), the height and the field of view.setElementPreviewModelSets a model preview without an element in the world (e.g. a list of cars or skins in a shop): the kind ("vehicle","ped","object") and the model number. The model only exists for this player, for the shots.getElementPreviewImageReturns the path of the preview PNG file (fordxDrawImageanddxCreateTexture) orfalsewhen there is no first shot yet.destroyElementPreviewRemoves a preview fromcreateElementPreview.isElementPreviewChecks whether a value is an existing preview fromcreateElementPreview.