TakePlayerScreenShot: Difference between revisions
Jump to navigation
Jump to search
m (→Syntax: consistency) |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 5: | Line 5: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool takePlayerScreenShot ( player thePlayer, int width, int height [, string tag = "", int quality = 30, int | bool takePlayerScreenShot ( player thePlayer, int width, int height [, string tag = "", int quality = 30, int maxBandwidth = 5000, int maxPacketSize = 500 ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[player]]:takeScreenShot||}} | {{OOP||[[player]]:takeScreenShot||}} | ||
Line 16: | Line 16: | ||
*'''tag:''' A string to help identify the screen capture. The string is passed to the matching [[onPlayerScreenShot]] event for your personal convenience. | *'''tag:''' A string to help identify the screen capture. The string is passed to the matching [[onPlayerScreenShot]] event for your personal convenience. | ||
*'''quality:''' 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. | *'''quality:''' 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:''' The amount of client upload bandwidth to use (in bytes per second) when sending the image. | ||
*'''maxPacketSize: ''' The maximum size of one packet. | |||
===Returns=== | ===Returns=== | ||
Line 22: | Line 23: | ||
==Example== | ==Example== | ||
This example will | ===Example 1=== | ||
This example will take a player screenshot whenever a player takes a picture with the camera weapon and then send the picture to all clients, which will render the latest screenshot in the bottom right corner of their screen. | |||
<section name="Client" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local player = | 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) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
<section name="Server" class="server" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
function requestScreenshot() | |||
takePlayerScreenShot(source,320,240,"cameraphoto",50) -- the player just took a picture with the camera, let's request a screenshot to see what they took a photo of | |||
end | |||
addEvent("onPlayerTakesPhoto",true) | |||
addEventHandler("onPlayerTakesPhoto",root,requestScreenshot) | |||
== | function incomingPlayerScreenshot(res,status,img,timestamp,tag) | ||
if status == "ok" and tag == "cameraphoto" then -- make sure a picture was taken successfully and that we're the ones who requested this screenshot | |||
triggerClientEvent("updatePhoto",source,img) -- trigger a client event to share the image with everyone on the server | |||
end | |||
end | |||
addEventHandler("onPlayerScreenShot",root,incomingPlayerScreenshot) | |||
</syntaxhighlight> | |||
</section> | |||
==See Also== | ==See Also== | ||
{{Player functions}} | {{Player functions|server}} |
Latest revision as of 15:41, 7 November 2024
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.
Syntax
bool takePlayerScreenShot ( player thePlayer, int width, int height [, string tag = "", int quality = 30, int maxBandwidth = 5000, int maxPacketSize = 500 ] )
OOP Syntax Help! I don't understand this!
- Method: player:takeScreenShot(...)
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
- tag: A string to help identify the screen capture. The string is passed to the matching onPlayerScreenShot event for your personal convenience.
- quality: 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: The amount of client upload bandwidth to use (in bytes per second) when sending the image.
- maxPacketSize: The maximum size of one packet.
Returns
Returns true if the function was successfully, false if invalid arguments are specified.
Example
Example 1
This example will take a player screenshot whenever a player takes a picture with the camera weapon and then send the picture to all clients, which will render the latest screenshot in the bottom right corner of their screen.
Click to collapse [-]
Clientlocal 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)
Click to collapse [-]
Serverfunction requestScreenshot() takePlayerScreenShot(source,320,240,"cameraphoto",50) -- the player just took a picture with the camera, let's request a screenshot to see what they took a photo of end addEvent("onPlayerTakesPhoto",true) addEventHandler("onPlayerTakesPhoto",root,requestScreenshot) function incomingPlayerScreenshot(res,status,img,timestamp,tag) if status == "ok" and tag == "cameraphoto" then -- make sure a picture was taken successfully and that we're the ones who requested this screenshot triggerClientEvent("updatePhoto",source,img) -- trigger a client event to share the image with everyone on the server end end addEventHandler("onPlayerScreenShot",root,incomingPlayerScreenshot)
See Also
- getAlivePlayers
- getDeadPlayers
- getPlayerACInfo
- getPlayerAnnounceValue
- getPlayerCount
- getPlayerIdleTime
- getPlayerIP
- getPlayerVersion
- getRandomPlayer
- isPlayerMuted
- redirectPlayer
- resendPlayerACInfo
- resendPlayerModInfo
- setPlayerAnnounceValue
- setPlayerMuted
- setPlayerScriptDebugLevel
- setPlayerTeam
- setPlayerVoiceBroadcastTo
- setPlayerVoiceIgnoreFrom
- setPlayerWantedLevel
- spawnPlayer
- takePlayerScreenShot
- Shared
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerScriptDebugLevel
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState