steamworks.requestActivePlayerCount()

类型 函数
返回值 布尔
修订 2024.3703 版
关键词 steam、steamworks、requestActivePlayerCount
请参见 activePlayerCount
steamworks.*

概览

异步从 Steam 的服务器获取全球运行应用程序的人数,不包含当前登录用户。

如果请求已成功发送至 Steam,则返回 true。请注意,这并不一定意味着请求的操作会成功。例如,如果无网络连接,此函数会返回 true。所以,监听器必须检查接收的 event.isError 属性,以确定请求的操作是否成功。

如果提供的是无效参数,或 steamworks.isLoggedOn 属性为 false,则返回 false

语法

steamworks.requestActivePlayerCount( listener )
listener (必需)

函数. 将通过 activePlayerCount 事件接收结果请求的函数。

示例

local steamworks = require( "plugin.steamworks" )

-- Fetch the number of people currently playing this game
local function onReceivedActivePlayerCount( event )
    if ( event.isError ) then
        -- This will likely happen due to lack of Internet access
        print( "Failed to fetch active player count." )
    else
        -- Print current number of people playing this game
        print( "Active Player Count: " .. tostring(event.count) )
    end
end
steamworks.requestActivePlayerCount( onReceivedActivePlayerCount )