OnClientFileDownloadComplete: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
{{Client event}}
{{Client event}}  
__NOTOC__
This event is triggered when a file has been downloaded after [[downloadFile]] has been successfully called.


my test example until I get a chance to document properly
==Parameters==
<syntaxhighlight lang="lua">
string fileName, bool success
</syntaxhighlight>


*'''fileName''': the file downloaded.
*'''success''': whether successful or not.
==Source==
The [[event system#Event source|source]] of this event is the [[root element]] of the resource that called [[downloadFile]].
==Example==
This example plays a sound if it was downloaded successfully
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
currentTrack = nil
function onStart ( )
downloadFile ( "test.mp3" )
end
addEventHandler ( "onClientResourceStart", getRootElement(), onStart )
function onDownloadFinish ( file, success )
function onDownloadFinish ( file, success )
if ( success ) then
if ( source == resourceRoot ) then
if ( file == "test.mp3" ) then
if ( success ) then
currentTrack = playSound ( "test.mp3" )
if ( file == "test.mp3" ) then
end
currentTrack = playSound ( "test.mp3" )
else
end
if ( file == "test.mp3" ) then
else
outputChatBox ( "test.mp3 failed to download" )
if ( file == "test.mp3" ) then
outputChatBox ( "test.mp3 failed to download" )
end
end
end
end
end
end
end
addEventHandler ( "onClientFileDownloadComplete", getRootElement(), onDownloadFinish )
addEventHandler ( "onClientFileDownloadComplete", getRootElement(), onDownloadFinish )
function onSoundStopped ( reason )
if ( source == currentTrack ) then
if ( reason == "destroyed" ) then
outputChatBox ( "sound destroyed" )
elseif ( reason == "finished" ) then
outputChatBox ( "end of sound" )
elseif ( reason == "paused" ) then
outputChatBox ( "sound paused" )
end
end
end
addEventHandler ( "onClientSoundStopped", getRootElement(), onSoundStopped )
function onSoundStarted ( reason )
if ( reason == "play" ) then
outputChatBox ( "sound started" )
elseif ( reason == "resumed" ) then
outputChatBox ( "sound resumed" )
end
end
addEventHandler ( "onClientSoundStarted", getRootElement(), onSoundStarted )
function stopSoundFunction ()
stopSound ( currentTrack )
end   
addCommandHandler ( "stop1", stopSoundFunction )
function songPause()
    local pause = isSoundPaused ( currentTrack )
    if ( pause == true ) then
setSoundPaused ( currentTrack, false )
    else
setSoundPaused ( currentTrack, true )
    end
end
addCommandHandler("pause", songPause)
function startSoundFunction ()
currentTrack = playSound ( "test.mp3" )
end   
addCommandHandler ( "start1", startSoundFunction )
</syntaxhighlight>
</syntaxhighlight>


Line 73: Line 36:
===Other client events===
===Other client events===
{{Client_other_events}}
{{Client_other_events}}
===Client event functions===
{{Client_event_functions}}

Revision as of 17:16, 27 February 2012

This event is triggered when a file has been downloaded after downloadFile has been successfully called.

Parameters

string fileName, bool success
  • fileName: the file downloaded.
  • success: whether successful or not.

Source

The source of this event is the root element of the resource that called downloadFile.

Example

This example plays a sound if it was downloaded successfully

function onDownloadFinish ( file, success )
	if ( source == resourceRoot ) then
		if ( success ) then
			if ( file == "test.mp3" ) then
				currentTrack = playSound ( "test.mp3" )
			end
		else
			if ( file == "test.mp3" ) then
				outputChatBox ( "test.mp3 failed to download" )
			end
		end
	end
end
addEventHandler ( "onClientFileDownloadComplete", getRootElement(), onDownloadFinish )

See Also

Other client events


Client event functions