GetLatentEventStatus: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 30: Line 30:
function beginTransfer()
function beginTransfer()
     triggerLatentServerEvent("blah", resourceRoot, myVeryLongString)    -- Start latent event
     triggerLatentServerEvent("blah", resourceRoot, myVeryLongString)    -- Start latent event
     myHandle = getLatentEventHandles(#getLatentEventHandles())          -- Get last latent event handle
     myHandle = getLatentEventHandles()[#getLatentEventHandles()]        -- Get last latent event handle
     myTimer = setTimer( updateStatus, 1000, 0 )                        -- Output status once a second
     myTimer = setTimer( updateStatus, 1000, 0 )                        -- Output status once a second
end
end

Revision as of 19:44, 10 May 2012

Gets the status of one queued latent event.

Syntax

Server:

table getLatentEventStatus( player thePlayer, int handle )

Client:

table getLatentEventStatus( int handle )

Required Arguments

  • thePlayer: (Only required if called on the server) The player who is receiving the event.
  • handle: A handle previous got from getLatentEventHandles.

Returns

Returns a table with the following info or false if invalid arguments were passed:

  • tickStart: A number estimating how many ticks until the data transfer starts (Negative means the transfer has already started)
  • tickEnd: A number estimating how many ticks until the data transfer completes
  • totalSize: A number representing how many bytes in total this transfer will transfer
  • percentComplete: A number between 0-100 saying how much is done

Example

Click to collapse [-]
Client

The example starts a latent event and outputs the status of the transfer to the client console

function beginTransfer()
    triggerLatentServerEvent("blah", resourceRoot, myVeryLongString)    -- Start latent event
    myHandle = getLatentEventHandles()[#getLatentEventHandles()]        -- Get last latent event handle
    myTimer = setTimer( updateStatus, 1000, 0 )                         -- Output status once a second
end

function updateStatus()
    local status = getLatentEventStatus(myHandle)   -- Get latent event status
    if not status then
        killTimer(myTimer)                          -- getLatentEventStatus returns false when the handle is no longer valid
    else
        outputConsole( "Transfer status:"
            .. " tickStart:" .. tostring(status.tickStart)
            .. " tickEnd:" .. tostring(status.tickEnd)
            .. " totalSize:" .. tostring(status.totalSize)
            .. " percentComplete:" .. tostring(status.percentComplete)
            )
    end
end

Requirements

This template will be deleted.

See Also