takePlayerScreenShot | Multi Theft Auto: Wiki Skip to content

takePlayerScreenShot

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function forces a client to capture the current screen output and send it back to the server. The image will contain the GTA HUD and the output of any dxDraw functions that are not flagged as 'post GUI'. The image specifically excludes the chat box and all GUI (including the client console). The result is received with the event onPlayerScreenShot.

OOP Syntax Help! I don't understand this!

  • Method:player:takeScreenShot(...)

Syntax

bool takePlayerScreenShot ( player thePlayer, int width, int height, [ string tag = "", int quality = 30, int maxBandwidth = 5000, int maxPacketSize = 500 ] )
Required Arguments
  • thePlayer: the player to get the screen capture from.
  • width: the width of the capture image.
  • height: the height of the capture image.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • tag (default: ""): A string to help identify the screen capture. The string is passed to the matching onPlayerScreenShot event for your personal convenience.
  • quality (default: 30): Quality of the final JPEG image from 0 to 100. A lower value can reduce the memory used by the image considerably which will result in faster and less intrusive uploads.
  • maxBandwidth (default: 5000): The amount of client upload bandwidth to use (in bytes per second) when sending the image.
  • maxPacketSize (default: 500): The maximum size of one packet.

Returns

  • bool: value

Returns true if the function was successfully, false if invalid arguments are specified.

Code Examples

shared
local screenSizeX,screenSizeY = guiGetScreenSize() -- save the current screen dimensions
local imgtexture
local takenBy
function wepFire(weapon)
if weapon == 43 then -- if the weapon the player just fired is the camera
triggerServerEvent("onPlayerTakesPhoto",localPlayer)
end
end
addEventHandler("onClientPlayerWeaponFire",localPlayer,wepFire)
function updateLatestPhoto(img)
if imgtexture then -- clean up the old dxTextrue if there is one
destroyElement(imgtexture)
end
imgtexture = dxCreateTexture(img) -- create a new dxTexture from the image data so that we can render it using dxDrawImage
takenBy = "taken by "..getPlayerName(source) -- let's also credit the photographer
end
addEvent("updatePhoto",true)
addEventHandler("updatePhoto",root,updateLatestPhoto)
function renderPhoto()
if imgtexture then
local sizeX, sizeY = 320, 240
dxDrawImage(screenSizeX-sizeX,screenSizeY-sizeY,sizeX,sizeY,imgtexture) -- render the picture as well as the name of the photographer in the bottom right corner of the screen
dxDrawText(takenBy,screenSizeX-sizeX,screenSizeY-sizeY,screenSizeX,screenSizeY,tocolor(0,0,0))
end
end
addEventHandler("onClientRender",root,renderPhoto)

See Also