GetRemoteRequests: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(initial makup)
 
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
__NOTOC__
__NOTOC__
Gets all {{fetchRemote}} and {{callRemote}} requests currently running.
{{New feature/item|3.0158|1.5.7|20307|
 
Gets all [[FetchRemote|fetchRemote]] and [[CallRemote|callRemote]] requests currently running.
}}
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool getRemoteRequests ( [ resource theResource = nil ] )
table getRemoteRequests ( [ resource theResource = nil ] )
</syntaxhighlight>
</syntaxhighlight>


Line 40: Line 41:
This example prints how many request are currently pending.
This example prints how many request are currently pending.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function CMD_requestInfo(player, _, resourceName)
function CMD_requestInfo(_, resourceName)
     local res = resourceName and getResourceFromName(resourceName) or not resourceName and nil
     local res = resourceName and getResourceFromName(resourceName) or not resourceName and nil
     if(res == false) then
     if(res == false) then
         outputChatBox("There is no resource named '" .. resourceName .. "'", player)
         outputChatBox("There is no resource named '" .. resourceName .. "'")
         return
         return
     elseif(res and getResourceState(res) ~= "running") then
     elseif(res and getResourceState(res) ~= "running") then
         outputChatBox("The provided resource '" .. resourceName .. "' is not running", player)
         outputChatBox("The provided resource '" .. resourceName .. "' is not running")
         return
         return
     end
     end
Line 53: Line 54:
     local requests = getRemoteRequests(res)
     local requests = getRemoteRequests(res)
     outputChatBox(("There are %d request%s running"):format(#requests, #requests == 1 and '' or 's'), player)
     outputChatBox(("There are %d request%s running"):format(#requests, #requests == 1 and '' or 's'))
end
end


Line 60: Line 61:
</section>
</section>


 
==Requirements==
{{Requirements|1.5.7|1.5.7}}
{{Requirements|1.5.7-9.20307|1.5.7-9.20307}}


==See Also==
==See Also==
{{Resource functions}}
{{Resource functions}}

Latest revision as of 13:58, 25 October 2020

Gets all fetchRemote and callRemote requests currently running.

Syntax

table getRemoteRequests ( [ resource theResource = nil ] )

Optional Arguments

  • theResource: the resource to get all requests from

Returns

Returns a table with all requests, false if an invalid resource was provided

Example

Click to collapse [-]
Server

This example prints how many request are currently pending.

function CMD_requestInfo(player, _, resourceName)
    local res = resourceName and getResourceFromName(resourceName) or not resourceName and nil
	
    if(res == false) then
        outputChatBox("There is no resource named '" .. resourceName .. "'", player)
        return
    elseif(res and getResourceState(res) ~= "running") then
        outputChatBox("The provided resource '" .. resourceName .. "' is not running", player)
        return
    end

    local requests = getRemoteRequests(res)
	
    outputChatBox(("There are %d request%s running"):format(#requests, #requests == 1 and '' or 's'), player)
end

addCommandHandler("requestinfo", CMD_requestInfo)
Click to collapse [-]
Client

This example prints how many request are currently pending.

function CMD_requestInfo(_, resourceName)
    local res = resourceName and getResourceFromName(resourceName) or not resourceName and nil
	
    if(res == false) then
        outputChatBox("There is no resource named '" .. resourceName .. "'")
        return
    elseif(res and getResourceState(res) ~= "running") then
        outputChatBox("The provided resource '" .. resourceName .. "' is not running")
        return
    end

    local requests = getRemoteRequests(res)
	
    outputChatBox(("There are %d request%s running"):format(#requests, #requests == 1 and '' or 's'))
end

addCommandHandler("requestinfo", CMD_requestInfo)

Requirements

Minimum server version 1.5.7-9.20307
Minimum client version 1.5.7-9.20307

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.5.7-9.20307" client="1.5.7-9.20307" />

See Also