OnClientFileDownloadComplete: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
{{Client event}}
{{Client event}}  
{{New items|3.0140|1.4|
__NOTOC__  
This event is triggered when a file has been downloaded after [[downloadFile]] has been successfully called.
}}
==Parameters==
<syntaxhighlight lang="lua">
string fileName, bool success, resource requestResource
</syntaxhighlight>
 
*'''fileName''': the file downloaded.
*'''success''': whether successful or not.
{{New items|4.0157|1.5.7-20468|
*'''requestResource''': the resource that called [[downloadFile]].
}}


my test example until I get a chance to document properly
==Source==
The [[event system#Event source|source]] of this event is the [[root element]] of the resource that downloaded file.


==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 the file relates to this resource
if ( file == "test.mp3" ) then
        if ( success ) then                                       -- if the file was downloaded successfully
currentTrack = playSound ( "test.mp3" )
            if ( file == "test.mp3" ) then                       -- if the file name is what we were expecting
end
                currentTrack = playSound ( "test.mp3" )
else
            end
if ( file == "test.mp3" ) then
        else                                                     -- if the file wasn't downloaded successfully
outputChatBox ( "test.mp3 failed to download" )
            if ( file == "test.mp3" ) then
end
                outputChatBox ( "test.mp3 failed to download" )
end
            end
end
        end
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 ( source == currentTrack ) then
if ( reason == "play" ) then
outputChatBox ( "sound started" )
elseif ( reason == "resumed" ) then
outputChatBox ( "sound resumed" )
end
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
end
end
addCommandHandler("pause", songPause)
addEventHandler ( "onClientFileDownloadComplete", root, onDownloadFinish )
 
function startSoundFunction ()
currentTrack = playSound ( "test.mp3" )
end   
addCommandHandler ( "start1", startSoundFunction )
</syntaxhighlight>
</syntaxhighlight>


Line 75: Line 40:
===Other client events===
===Other client events===
{{Client_other_events}}
{{Client_other_events}}
===Client event functions===
{{Client_event_functions}}

Latest revision as of 18:46, 24 April 2020

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

Parameters

string fileName, bool success, resource requestResource
  • fileName: the file downloaded.
  • success: whether successful or not.
ADDED/UPDATED IN VERSION 1.5.7-20468 :

Source

The source of this event is the root element of the resource that downloaded file.

Example

This example plays a sound if it was downloaded successfully

function onDownloadFinish ( file, success )
    if ( source == resourceRoot ) then                            -- if the file relates to this resource
        if ( success ) then                                       -- if the file was downloaded successfully
            if ( file == "test.mp3" ) then                        -- if the file name is what we were expecting
                currentTrack = playSound ( "test.mp3" )
            end
        else                                                      -- if the file wasn't downloaded successfully
            if ( file == "test.mp3" ) then
                outputChatBox ( "test.mp3 failed to download" )
            end
        end
    end
end
addEventHandler ( "onClientFileDownloadComplete", root, onDownloadFinish )

See Also

Other client events


Client event functions