Steamworks 文獻庫
ISteamInventory 介面
Steam 物品庫查詢與操作用 API。

詳細資訊請見 Steam 物品庫服務

成員函式

ISteamInventory 的成員函式可透過全域存取子函式 ISteamInventory() 呼叫。

AddPromoItem

bool AddPromoItem( SteamInventoryResult_t *pResultHandle, SteamItemDef_t itemDef );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
itemDefSteamItemDef_t將賦予玩家的 ItemDef。

賦予使用者特定促銷物品,為一次性動作。

由於此函式能賦予的物品皆可用 itemdef 中的原則上鎖,因此用戶端呼叫此函式並無風險。 呼叫此函式的主要狀況之一為把物品賦予已擁有某款特定遊戲的使用者。 This can be useful if your game has custom UI for showing a specific promo item to the user otherwise if you want to grant multiple promotional items then use AddPromoItems or GrantPromoItems.

任何可被賦予玩家的物品之 itemdef「必須」帶有「promo」屬性。 Promo 物品列表為使用者必須擁有,才能被授予指定物品的一組 App ID。 This version will grant all items that have promo attributes specified for them in the configured item definitions. This allows adding additional promotional items without having to update the game client. For example the following will allow the item to be granted if the user owns either TF2 or SpaceWar.

promo: owns:440;owns:480

傳回: bool
由一般使用者呼叫時,此函式將永遠傳回 true;由 SteamGameServer 呼叫時,將永遠傳回 false

成功時,如果存在已賦予的物品,物品庫結果將包含這些物品。 如果該使用者不符合促銷對象資格,因而沒收到任何物品,此函式仍屬成功。

透過 pResultHandle 傳回新結果控制代碼。

備註: 完成後,務必在提供的物品庫結果中呼叫 DestroyResult

範例:
void CInventory::GrantPromoItems() { SteamInventory()->AddPromoItem( &s_GenerateRequestResult, 110 ); }

AddPromoItems

bool AddPromoItems( SteamInventoryResult_t *pResultHandle, const SteamItemDef_t *pArrayItemDefs, uint32 unArrayLength );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
pArrayItemDefsconst SteamItemDef_t *待賦予使用者的物品列表。
unArrayLengthuint32pArrayItemDefs 中的物品數量。

Grant a specific one-time promotional item to the current user.

由於此函式能賦予的物品皆可用 itemdef 中的原則上鎖,因此用戶端呼叫此函式並無風險。 呼叫此函式的主要狀況之一為把物品賦予已擁有某款特定遊戲的使用者。 If you want to grant a single promotional item then use AddPromoItem. 想賦予所有能賦予的物品時,請使用 GrantPromoItems

任何可被賦予玩家的物品之 itemdef「必須」帶有「promo」屬性。 Promo 物品列表為使用者必須擁有,才能被授予指定物品的一組 App ID。 This version will grant all items that have promo attributes specified for them in the configured item definitions. This allows adding additional promotional items without having to update the game client. For example the following will allow the item to be granted if the user owns either TF2 or SpaceWar.

promo: owns:440;owns:480

傳回: bool
由一般使用者呼叫時,此函式將永遠傳回 true;由 SteamGameServer 呼叫時,將永遠傳回 false

成功時,如果存在已賦予的物品,物品庫結果將包含這些物品。 如果該使用者不符合促銷對象資格,因而沒收到任何物品,此函式仍屬成功。

透過 pResultHandle 傳回新結果控制代碼。

備註: 完成後,務必在提供的物品庫結果中呼叫 DestroyResult

範例:
void CInventory::GrantPromoItems() { SteamItemDef_t newItems[2]; newItems[0] = 110; newItems[1] = 111; SteamInventory()->AddPromoItems( &s_GenerateRequestResult, newItems, 2 ); }

CheckResultSteamID

bool CheckResultSteamID( SteamInventoryResult_t resultHandle, CSteamID steamIDExpected );
名稱型別說明
resultHandleSteamInventoryResult_t待查 Steam ID 的物品庫結果控制代碼。
steamIDExpectedCSteamID待驗證的 Steam ID。

檢查物品庫結果控制代碼屬於指明的 Steam ID。

This is important when using DeserializeResult, to verify that a remote player is not pretending to have a different user's inventory.

傳回: bool
true if the result belongs to the target steam ID; otherwise, false.

ConsumeItem

bool ConsumeItem( SteamInventoryResult_t *pResultHandle, SteamItemInstanceID_t itemConsume, uint32 unQuantity );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
itemConsumeSteamItemInstanceID_t將消耗的物品執行個體 ID。
unQuantityuint32堆疊中即將消耗的物品數量。

消耗使用者物品庫中的物品。 如果指定物品的數量降至零,則該物品將遭永久移除。

Once an item is removed it cannot be recovered. This is not for the faint of heart - if your game implements item removal at all, a high-friction UI confirmation process is highly recommended.

傳回: bool
由一般使用者呼叫時,此函式將永遠傳回 true;由 SteamGameServer 呼叫時,將永遠傳回 false

透過 pResultHandle 傳回新結果控制代碼。

備註: 完成後,務必在提供的物品庫結果中呼叫 DestroyResult

另外請見: AddPromoItemAddPromoItems

範例:
void CInventory::DrinkOnePotion( SteamItemInstanceID_t itemID ) { SteamInventory()->ConsumeItem( &s_ConsumeRequestResult, itemID, 1 ); }

DeserializeResult

bool DeserializeResult( SteamInventoryResult_t *pOutResultHandle, const void *pBuffer, uint32 unBufferSize, bool bRESERVED_MUST_BE_FALSE = false );
名稱型別說明
pOutResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
pBufferconst void *待還原序列化的緩衝區。
unBufferSizeuint32pBuffer 的大小。
bRESERVED_MUST_BE_FALSEbool必須為 false

Deserializes a result set and verifies the signature bytes.

當控制代碼狀態設為 k_EResultExpired 時,此呼叫函式有可能引發軟性失敗模式。 GetResultItems 在此模式中仍會成功。 The "expired" result could indicate that the data may be out of date - not just due to timed expiration (one hour), but also because one of the items in the result set may have been traded or consumed since the result set was generated. 您可以比較從 GetResultTimestampISteamUtils::GetServerRealTime 的時間戳記來判斷資料的老舊程度。 You could simply ignore the "expired" result code and continue as normal, or you could request the player with expired data to send an updated result set.

當呼叫完此函式取得結果控制代碼後,請呼叫 CheckResultSteamID,並使用獲得的控制代碼確認遠端使用者並非假裝擁有其他使用者的物品庫。

備註:bRESERVED_MUST_BE_FALSE 參數保留供未來使用,並且在任何情形下都不應設為 true。

傳回: bool
遠傳回 true,其後透過 GetResultStatus 傳遞錯誤代碼。

透過 pResultHandle 傳回新結果控制代碼。

備註: 完成後,務必在提供的物品庫結果中呼叫 DestroyResult

DestroyResult

void DestroyResult( SteamInventoryResult_t resultHandle );
名稱型別說明
resultHandleSteamInventoryResult_tThe inventory result handle to destroy.

Destroys a result handle and frees all associated memory.

ExchangeItems

bool ExchangeItems( SteamInventoryResult_t *pResultHandle, const SteamItemDef_t *pArrayGenerate, const uint32 *punArrayGenerateQuantity, uint32 unArrayGenerateLength, const SteamItemInstanceID_t *pArrayDestroy, const uint32 *punArrayDestroyQuantity, uint32 unArrayDestroyLength );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
pArrayGenerateconst SteamItemDef_t *此呼叫將建立的物品列表。 Currently can only be 1 item!
punArrayGenerateQuantityconst uint32 *pArrayGenerate 中將建立的各個物品的數量。 Currently can only be 1 item and it must be set to 1!
unArrayGenerateLengthuint32pArrayGeneratepunArrayGenerateQuantity 中的物品數量。 目前必須為 1
pArrayDestroyconst SteamItemInstanceID_t *The list of items that will be destroyed by this call.
punArrayDestroyQuantityconst uint32 *The quantity of each item in pArrayDestroy to destroy.
unArrayDestroyLengthuint32pArrayDestroypunArrayDestroyQuantity 中的物品數量。

Grant one item in exchange for a set of other items.

This can be used to implement crafting recipes or transmutations, or items which unpack themselves into other items (e.g., a chest).

The caller of this API passes in the requested item and an array of existing items and quantities to exchange for it. The API currently takes an array of items to generate but at this time the size of that array must be 1 and the quantity of the new item must be 1.

任何可被賦予玩家的物品之 itemdef「必須」帶有交換屬性。 The exchange attribute specifies a set of recipes that are valid exchanges for this item. 物品庫服務將自動驗證交換配方,如提供的成分與配方不符,或數量不足,交換將失敗。

範例:
exchange: 101x1,102x1;103x5;104x3,105x3

代表該物品可透過三種方式交換:一個 #101 加一個 #102、五個 #103,或三個 #104 加三個 #105。 詳情請見Steam 物品庫結構描述

傳回: bool
This function returns true indicating success, and returns false when called from SteamGameServer or when unArrayGenerateLength or punArrayGenerateQuantity is not set to 1.

如不符合交換條件或所需數量不足,交換將失敗。

透過 pResultHandle 傳回新結果控制代碼。

備註: 完成後,務必在提供的物品庫結果中呼叫 DestroyResult

另外請見: ConsumeItemTransferItemQuantity

範例:
// 於使用者的物品庫中找尋擁有特定 itemdef 的物品 SteamItemInstanceID_t CInventory::GetItemIdFromInventory( SteamItemDef_t itemDefId ); void CInventory::Exchange() { SteamItemInstanceID_t inputItems[2]; uint32 inputQuantities[2]; inputItems[0] = GetItemIdFromInventory( 103 ); inputQuantities[0] = 3; inputItems[1] = GetItemIdFromInventory( 104 ); inputQuantities[1] = 3; SteamItemDef_t outputItems[1]; outputItems[0] = 100; uint32 outputQuantity[1]; outputQuantity[0] = 1; SteamInventory()->ExchangeItems( &s_ExchangeRequestResult, outputItems, outputQuantity, 1, inputItems, inputQuantities, 2 ); }

GenerateItems

bool GenerateItems( SteamInventoryResult_t *pResultHandle, const SteamItemDef_t *pArrayItemDefs, const uint32 *punArrayQuantity, uint32 unArrayLength );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
pArrayItemDefsconst SteamItemDef_t *待賦予使用者的物品列表。
punArrayQuantityconst uint32 *pArrayItemDefs 中將給予的各個物品的數量。 非強制性,傳入 NULL 可指明每項物品各 1 。
unArrayLengthuint32pArrayItemDefs 中的物品數量。

Grants specific items to the current user, for developers only.

This API is only intended for prototyping - it is only usable by Steam accounts that belong to the publisher group for your game.

您可以傳入經物品的 SteamItemDef_t 定義的物品陣列,也可選擇性地傳入第二個陣列,內含各項物品的對應數量。 The length of these arrays MUST match!

傳回: bool
由一般使用者呼叫時,此函式將永遠傳回 true;由 SteamGameServer 呼叫時,將永遠傳回 false

透過 pResultHandle 傳回新結果控制代碼。

備註: 完成後,務必在提供的物品庫結果中呼叫 DestroyResult

範例:
void CInventory::GrantTestItems() { SteamItemDef_t newItems[2]; uint32 quantities[2]; newItems[0] = 110; newItems[1] = 111; quantities[0] = 1; quantities[1] = 1; SteamInventory()->GenerateItems( &s_GenerateRequestResult, newItems, quantities, 2 ); }

GetAllItems

bool GetAllItems( SteamInventoryResult_t *pResultHandle );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。

Start retrieving all items in the current users inventory.

備註: 此函式的呼叫受制於頻率,如果呼叫頻率太頻繁,可能傳回快取中的結果。 我們建議您只在準備顯示使用者的所有物品,或您推測物品庫已變更時,呼叫此函式。

傳回: bool
由一般使用者呼叫時,此函式將永遠傳回 true;由 SteamGameServer 呼叫時,將永遠傳回 false

透過 pResultHandle 傳回新結果控制代碼。

備註: 完成後,務必在提供的物品庫結果中呼叫 DestroyResult

範例:
void SpaceWarItem::LoadInventory( IGameEngine *pGameEngine ) { SteamInventory()->GetAllItems( &s_RequestResult ); }

GetEligiblePromoItemDefinitionIDs

bool GetEligiblePromoItemDefinitionIDs( CSteamID steamID, SteamItemDef_t *pItemDefIDs, uint32 *punItemDefIDsArraySize );
名稱型別說明
steamIDCSteamID物品將賦予的使用者 Steam ID。 應與 SteamInventoryEligiblePromoItemDefIDs_t.m_steamID 相同。
pItemDefIDsSteamItemDef_t *以複製進此陣列的方式,傳回物品 ID。
punItemDefIDsArraySizeuint32 *應為 pItemDefIDs 的長度,並與 SteamInventoryEligiblePromoItemDefIDs_t.m_numEligiblePromoItemDefs 相同。

獲取使用者可被賦予的物品定義 ID 列表。

在透過 SteamInventoryEligiblePromoItemDefIDs_t 呼叫結果獲取物品定義 ID 時,應呼叫此函式。

傳回: bool


另外請見: AddPromoItemAddPromoItems

GetItemDefinitionIDs

bool GetItemDefinitionIDs( SteamItemDef_t *pItemDefIDs, uint32 *punItemDefIDsArraySize );
名稱型別說明
pItemDefIDsSteamItemDef_t *以複製進此陣列的方式,傳回物品定義。
punItemDefIDsArraySizeuint32 *應設為 pItemDefIDs 的長度。 If pItemDefIDs is NULL then this will return the number of elements the array needs to hold.

傳回在 Steamworks 網站的應用程式管理員中定義的所有物品定義 ID。

物品定義可為非連續整數。

SteamInventoryDefinitionUpdate_t 回呼函式會連帶呼叫此函式。 如果您的遊戲採用寫定的數字定義 ID(如:紫面罩 = 20,藍武器模組 = 55),且不允許在沒有用戶端修補程式的狀況下添加新物品類型,便無需呼叫此函式。

傳回: bool
成功時傳回 true。 只有在物品定義經伺服器載入,或當下的應用程式中不存在物品定義時,才會傳回 false

如果呼叫成功,那麼 punItemDefIDsArraySize 將包含可用的物品定義數量。

GetItemDefinitionProperty

bool GetItemDefinitionProperty( SteamItemDef_t iDefinition, const char *pchPropertyName, char *pchValueBuffer, uint32 *punValueBufferSizeOut );
名稱型別說明
iDefinitionSteamItemDef_t待獲取其屬性的物品定義。
pchPropertyNameconst char *待獲取數值的屬性名稱。 如傳入 NULL,則 pchValueBuffer 將包含可用名稱的列表,名稱之間以逗號分隔。
pchValueBufferchar *傳回 pchPropertyName 相關的值。
punValueBufferSizeOutuint32 *This should be set to the size of pchValueBuffer, and returns the number of bytes required to hold the value.

從指明的物品定義中獲取字串屬性。
為特定的物品定義獲取屬性值。

請注意根據當下的 Steam 語言設定,有些屬性(如「name」)可能為翻譯字串(請參考 ISteamApps::GetCurrentGameLanguage)。 屬性名稱不論何時皆為 ASCII 英數字與底線。

NULL 傳入 pchPropertyName 可獲得可用屬性名稱的列表,名稱之間以逗號分隔。 在這個模式中,punValueBufferSizeOut 將包含建議的緩衝區大小。 Otherwise it will be the number of bytes actually copied to pchValueBuffer.

傳回: bool
成功時,傳回 true;若否,傳回 false,代表物品定義並未從伺服器載入、該應用程式中不存在物品定義,或物品定義中找不到屬性名稱。

The associated value is returned via pchValueBuffer, and the total number of bytes required to hold the value is available from punValueBufferSizeOut. 我們建議您呼叫此函式兩次,第一次將 pchValueBuffer 設為 NULLpunValueBufferSizeOut 設為零,獲取為存放後續呼叫結果所需的緩衝區大小。

The output looks something like this:
pchPropertyName 設為 NULL
appid、itemdefid、Timestamp
pchPropertyName set to "name":
SW_DECORATION_HAT

備註: Call LoadItemDefinitions first, to ensure that items are ready to be used before calling GetItemDefinitionProperty.

GetItemsByID

bool GetItemsByID( SteamInventoryResult_t *pResultHandle, const SteamItemInstanceID_t *pInstanceIDs, uint32 unCountInstanceIDs );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
pInstanceIDsconst SteamItemInstanceID_t *待更新狀態的物品執行個體 ID 列表。
unCountInstanceIDsuint32pInstanceIDs 中的物品數量。

Gets the state of a subset of the current user's inventory.

The subset is specified by an array of item instance IDs.

The results from this call can be serialized using SerializeResult and passed to other players to "prove" that the current user owns specific items, without exposing the user's entire inventory. For example, you could call this with the IDs of the user's currently equipped items and serialize this to a buffer, and then transmit this buffer to other players upon joining a game.

傳回: bool
This function always returns true when called by a regular user, and always returns false when called from SteamGameServer.

Returns a new result handle via pResultHandle.

NOTE: You must call DestroyResult on the provided inventory result when you are done with it.

GetItemPrice

bool GetItemPrice( SteamItemDef_t iDefinition, uint64 *pPrice );
名稱型別說明
iDefinitionSteamItemDef_tThe item definition id to retrieve the price for
pPriceuint64*要填入的價格指標。 價格將以使用者的當地貨幣呈現。

After a successful call to RequestPrices, you can call this method to get the pricing for a specific item definition.

傳回: bool
true upon success, indicating that pPrice has been successfully filled with the price for the given item definition id.
false if the parameters are invalid or if there is no price for the given item definition id.

See Also: RequestPrices

GetItemsWithPrices

bool GetItemsWithPrices( SteamItemDef_t *pArrayItemDefs, uint64 *pPrices, uint32 unArrayLength );
名稱型別說明
pArrayItemDefsSteamItemDef_t *要填入的物品定義陣列。
pPricesuint64*The array of prices for each corresponding item definition id in pArrayItemDefs. Prices are rendered in the user's local currency.
unArrayLengthuint32This should be the length of pArrayItemDefs and pPrices arrays, which are derived from the result of calling GetNumItemsWithPrices .

After a successful call to RequestPrices, you can call this method to get all the pricing for applicable item definitions. Use the result of GetNumItemsWithPrices as the the size of the arrays that you pass in.

Returns: bool
true upon success, indicating that pArrayItemDefs and pPrices have been successfully filled with the item definition ids and prices of items that are for sale.
false if the parameters are invalid

See Also: RequestPrices, GetItemPrice

GetNumItemsWithPrices

uint32 GetNumItemsWithPrices();
After a successful call to RequestPrices, this will return the number of item definitions with valid pricing.

傳回: uint32

See Also: RequestPrices, GetItemsWithPrices

GetResultItemProperty

bool GetResultItemProperty( SteamInventoryResult_t resultHandle, uint32 unItemIndex, const char *pchPropertyName, char *pchValueBuffer, uint32 *punValueBufferSizeOut );
名稱型別說明
resultHandleSteamInventoryResult_t含有待獲取屬性的物品之結果控制代碼。
unItemIndexuint32
pchPropertyNameconst char *待獲取數值的屬性名稱。 如傳入 NULL,則 pchValueBuffer 將包含可用名稱的列表,名稱之間以逗號分隔。
pchValueBufferchar *傳回 pchPropertyName 相關的值。
punValueBufferSizeOutuint32 *This should be set to the size of pchValueBuffer, and returns the number of bytes required to hold the value.

Gets the dynamic properties from an item in an inventory result set.

Property names are always composed of ASCII letters, numbers, and/or underscores.

If the results do not fit in the given buffer, partial results may be copied.

傳回: bool
This returns true upon success; otherwise, false indicating that the inventory result handle was invalid or the provided index does not contain an item.

GetResultItems

bool GetResultItems( SteamInventoryResult_t resultHandle, SteamItemDetails_t *pOutItemsArray, uint32 *punOutItemsArraySize );
名稱型別說明
resultHandleSteamInventoryResult_t待獲取的物品之物品庫結果控制代碼。
pOutItemsArraySteamItemDetails_t *透過將詳細資料複製至此陣列的方式傳回詳細資料。
punOutItemsArraySizeuint32 *應設為 pOutItemsArray 的長度。 如果 pOutItemsArrayNULL,則將傳回該陣列需要存放的元素數量。

Get the items associated with an inventory result handle.

傳回: bool
true if the call was successful, otherwise false.
Potential failure reasons include:
  • resultHandle 無效,或物品庫結果控制代碼尚未準備完成
  • pOutItemsArray 的大小不夠存放陣列
  • 該使用者沒有物品

If the call is successful then punItemDefIDsArraySize will contain the number of item definitions available.

範例:
bool bGotResult = false; std::vector<SteamItemDetails_t> vecDetails; uint32 count = 0; if ( SteamInventory()->GetResultItems( callback->m_handle, NULL, &count ) ) { vecDetails.resize( count ); bGotResult = SteamInventory()->GetResultItems( callback->m_handle, vecDetails.data(), &count ); }

GetResultStatus

EResult GetResultStatus( SteamInventoryResult_t resultHandle );
名稱型別說明
resultHandleSteamInventoryResult_t待獲取狀態的物品庫結果控制代碼。

Find out the status of an asynchronous inventory result handle.

This is a polling equivalent to registering a callback function for SteamInventoryResultReady_t.

傳回: EResult
Whether the call was successful or not.

Possible values:

Example:
void SpaceWarItem::CheckInventory( IGameEngine *pGameEngine ) { if ( s_RequestResult != 0 ) { EResult result = SteamInventory()->GetResultStatus( s_RequestResult ); if ( result == k_EResultOK ) { // 於此進行處理 } } }

GetResultTimestamp

uint32 GetResultTimestamp( SteamInventoryResult_t resultHandle );
名稱型別說明
resultHandleSteamInventoryResult_t待獲取的物品庫結果控制代碼時間戳記。

Gets the server time at which the result was generated.

傳回: uint32
The timestamp is provided as Unix epoch time (Time since Jan 1st, 1970)

You can compare this value against ISteamUtils::GetServerRealTime to determine the age of the result.

GrantPromoItems

bool GrantPromoItems( SteamInventoryResult_t *pResultHandle );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。

Grant all potential one-time promotional items to the current user.

This can be safely called from the client because the items it can grant can be locked down via policies in the itemdefs. One of the primary scenarios for this call is to grant an item to users who also own a specific other game. If you want to grant specific promotional items rather than all of them see: AddPromoItem and AddPromoItems.

Any items that can be granted MUST have a "promo" attribute in their itemdef. That promo item list a set of APPIDs that the user must own to be granted this given item. This version will grant all items that have promo attributes specified for them in the configured item definitions. This allows adding additional promotional items without having to update the game client. For example the following will allow the item to be granted if the user owns either TF2 or SpaceWar.

promo: owns:440;owns:480

傳回: bool
This function always returns true when called by a regular user, and always returns false when called from SteamGameServer.

On success, the inventory result will include items which were granted, if any. If no items were granted because the user isn't eligible for any promotions, this is still considered a success.

Returns a new result handle via pResultHandle.

備註: You must call DestroyResult on the provided inventory result when you are done with it.

Example:
void CInventory::GrantPromoItems() { SteamInventory()->GrantPromoItems( &s_GenerateRequestResult ); }

LoadItemDefinitions

bool LoadItemDefinitions();
Triggers an asynchronous load and refresh of item definitions.

Item definitions are a mapping of "definition IDs" (integers between 1 and 999999999) to a set of string properties. Some of these properties are required to display items on the Steam community web site. Other properties can be defined by applications. There is no reason to call this function if your game hardcoded the numeric definition IDs (e.g. purple face mask = 20, blue weapon mod = 55) and does not allow for adding new item types without a client patch.

傳回: bool
Triggers a SteamInventoryDefinitionUpdate_t callback.
This call will always return true.

RequestEligiblePromoItemDefinitionsIDs

SteamAPICall_t RequestEligiblePromoItemDefinitionsIDs( CSteamID steamID );
名稱型別說明
steamIDCSteamID將接收符合資格的促銷物品的使用者 Steam ID。

Request the list of "eligible" promo items that can be manually granted to the given user.

These are promo items of type "manual" that won't be granted automatically. An example usage of this is an item that becomes available every week.

After calling this function you need to call GetEligiblePromoItemDefinitionIDs to get the actual item definition ids.

Returns: SteamAPICall_t to be used with a SteamInventoryEligiblePromoItemDefIDs_t call result.
Returns k_uAPICallInvalid if the steamID is not a valid individual account.

RequestPrices

SteamAPICall_t RequestPrices();

Request prices for all item definitions that can be purchased in the user's local currency. A SteamInventoryRequestPricesResult_t call result will be returned with the user's local currency code. After that, you can call GetNumItemsWithPrices and GetItemsWithPrices to get prices for all the known item definitions, or GetItemPrice for a specific item definition.

傳回: SteamAPICall_t to be used with a SteamInventoryRequestPricesResult_t call result.
Returns k_uAPICallInvalid if there was an internal problem.

See Also: GetNumItemsWithPrices, GetItemsWithPrices, GetItemPrice

SendItemDropHeartbeat

void SendItemDropHeartbeat();
Deprecated.

SerializeResult

bool SerializeResult( SteamInventoryResult_t resultHandle, void *pOutBuffer, uint32 *punOutBufferSize );
名稱型別說明
resultHandleSteamInventoryResult_t待序列化的物品庫結果控制代碼。
pOutBuffervoid *序列化後的結果將複製至的緩衝區。
punOutBufferSizeuint32 *應設為 pOutBuffer 的大小。 如果 pOutBufferNULL,則將傳回存放緩衝區所需的大小。

Serialized result sets contain a short signature which can't be forged or replayed across different game sessions.

A result set can be serialized on the local client, transmitted to other players via your game networking, and deserialized by the remote players. This is a secure way of preventing hackers from lying about posessing rare/high-value items. Serializes a result set with signature bytes to an output buffer. The size of a serialized result depends on the number items which are being serialized. When securely transmitting items to other players, it is recommended to use GetItemsByID first to create a minimal result set.

Results have a built-in timestamp which will be considered "expired" after an hour has elapsed. See DeserializeResult for expiration handling.

If this is set pOutBuffer to NULL then punOutBufferSize will be set to the buffer size required. So you can make the buffer and then call this again to fill it with the data.

傳回: bool
true upon success, indicating that punOutBufferSize has been successfully filled with the size of the buffer, and if pOutBuffer points to a buffer of sufficient size then it is filled out as well.
false under the following conditions:
  • 呼叫函式的並非一般使用者, GameServers 不支援此呼叫函式
  • resultHandle 無效,或物品庫結果控制代碼尚未準備完成
  • 傳入 punOutBufferSize 的值小於預期,同時 pOutBufferNULL

StartPurchase

SteamAPICall_t StartPurchase( const SteamItemDef_t *pArrayItemDefs, const uint32 *punArrayQuantity, uint32 unArrayLength );
名稱型別說明
pArrayItemDefsSteamItemDef_t *The array of item definition ids that the user wants to purchase.
punArrayQuantityuint32 *The array of quantities of each item definition that the user wants to purchase.
unArrayLengthuint32This should be the length of pArrayItemDefs and punArrayQuantity arrays.

Starts the purchase process for the user, given a "shopping cart" of item definitions that the user would like to buy. The user will be prompted in the Steam Overlay to complete the purchase in their local currency, funding their Steam Wallet if necessary, etc.

If the purchase process was started successfully, then m_ulOrderID and m_ulTransID
will be valid in the SteamInventoryStartPurchaseResult_t call result.

If the user authorizes the transaction and completes the purchase, then the callback SteamInventoryResultReady_t will be triggered and you can then retrieve what new items the user has acquired. NOTE: You must call DestroyResult on the inventory result for when you are done with it.

傳回: SteamAPICall_t to be used with a SteamInventoryStartPurchaseResult_t call result.
Returns k_uAPICallInvalid if the input was invalid.
Testing while in Development: When testing StartPurchase before your app is released, all transactions made by members of the development / publishing team will be made through the Sandbox micro-transaction API internally. This means you will not be charged for the purchases made before the app is released if you are part of the Steamworks publisher.

TransferItemQuantity

bool TransferItemQuantity( SteamInventoryResult_t *pResultHandle, SteamItemInstanceID_t itemIdSource, uint32 unQuantity, SteamItemInstanceID_t itemIdDest );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
itemIdSourceSteamItemInstanceID_t待轉移的來源物品。
unQuantityuint32將從 itemIdSource 轉移至 itemIdDest 的物品數量。
itemIdDestSteamItemInstanceID_t目的地物品。 您可以傳入 k_SteamItemInstanceIDInvalid 以拆分來源堆疊,做出要求數量的新物品堆疊。

Transfer items between stacks within a user's inventory.

This can be used to stack, split, and moving items. The source and destination items must have the same itemdef id. To move items onto a destination stack specify the source, the quantity to move, and the destination item id. To split an existing stack, pass k_SteamItemInstanceIDInvalid into itemIdDest. A new item stack will be generated with the requested quantity.

NOTE: Tradability/marketability restrictions are copied along with transferred items. The destination stack receives the latest tradability/marketability date of any item in its composition.

傳回: bool
This function always returns true when called by a regular user, and always returns false when called from SteamGameServer.

Returns a new result handle via pResultHandle.

NOTE: You must call DestroyResult on the provided inventory result when you are done with it.

See Also: ConsumeItem, ExchangeItems

Example:
void CInventory::CombineItems() { SteamInventoryResult_t transferResult; // split 2 items from an existing stack SteamItemInstanceID_t bigStack = GetItemIdFromInventory( ... ); SteamInventory()->TransferItemQuantity( &transferResult, bigStack, 1, k_SteamItemInstanceIDInvalid ); // move 2 from stack A to stack B SteamItemInstanceID_t originStack = GetItemIdFromInventory( ... ); SteamItemInstanceID_t destStack = GetItemIdFromInventory( ... ); SteamInventory()->TransferItemQuantity( &transferResult, originStack, 2, destStack ); }

TriggerItemDrop

bool TriggerItemDrop( SteamInventoryResult_t *pResultHandle, SteamItemDef_t dropListDefinition );
名稱型別說明
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。
dropListDefinitionSteamItemDef_t必須指向「playtimegenerator」種類的 itemdefid 。 詳情請見物品庫結構描述

Trigger an item drop if the user has played a long enough period of time.

This period can be customized in two places:
  • At the application level within Inventory Service: Playtime Item Grants. 將自動在所有沒有指明任何覆寫的「playtimegenerator」物品上實施。
  • 在單獨的「playtimegenerator」物品定義中。 該設定的優先順序將高於任何應用程式層級的設定。

Only item definitions which are marked as "playtime item generators" can be spawned.

Typically this function should be called at the end of a game or level or match or any point of significance in the game in which an item drop could occur. The granularity of the playtime generator settings is in minutes, so calling it more frequently than minutes is not useful and will be rate limited in the Steam client. The Steam servers will perform playtime accounting to prevent too-frequent drops. The servers will also manage adding the item to the players inventory.

Returns: bool
This function always returns true when called by a regular user, and always returns false when called from SteamGameServer.

Returns a new result handle via pResultHandle.

備註: You must call DestroyResult on the provided inventory result when you are done with it.

The inventory result returned by this function will be the new item granted if the player is eligible. If the user is not eligible then it will return an empty result ('[]').

範例:
void CInventory::FinishGame() { SteamInventory()->TriggerItemDrop( &s_PlaytimeRequestResult, 10 ); }

StartUpdateProperties

SteamInventoryUpdateHandle_t StartUpdateProperties();

Starts a transaction request to update dynamic properties on items for the current user. This call is rate-limited by user, so property modifications should be batched as much as possible (e.g. at the end of a map or game session). After calling SetProperty or RemoveProperty for all the items that you want to modify, you will need to call SubmitUpdateProperties to send the request to the Steam servers. A SteamInventoryResultReady_t callback will be fired with the results of the operation.

Example:
void CInventory::FinishLevel() { SteamInventoryUpdateHandle_t updateHandle = SteamInventory()->StartUpdateProperties(); for ( SteamItemInstanceID_t itemid : m_vecItemIDs ) { SteamInventory()->SetProperty( updateHandle, itemid, "string_value", "blah" ); SteamInventory()->SetProperty( updateHandle, itemid, "bool_value", true ); SteamInventory()->SetProperty( updateHandle, itemid, "int64_value", (int64)55 ); SteamInventory()->SetProperty( updateHandle, itemid, "float_value", 123.456f ); } SteamInventoryResult_t resultHandle; SteamInventory()->SubmitUpdateProperties( updateHandle, &resultHandle ); }

NOTE: You must call DestroyResult on the provided inventory result for SubmitUpdateProperties when you are done with it.

Returns: SteamInventoryUpdateHandle_t

See Also: SetProperty, RemoveProperty, SubmitUpdateProperties

SubmitUpdateProperties

bool SubmitUpdateProperties( SteamInventoryUpdateHandle_t handle, SteamInventoryResult_t * pResultHandle );
名稱型別說明
handleSteamInventoryUpdateHandle_tThe update handle corresponding to the transaction request, returned from StartUpdateProperties.
pResultHandleSteamInventoryResult_t *傳回新物品庫結果控制代碼。

Submits the transaction request to modify dynamic properties on items for the current user. See StartUpdateProperties.

NOTE: You must call DestroyResult on the provided inventory result for when you are done with it.

傳回: bool

See Also: StartUpdateProperties, SetProperty, RemoveProperty

RemoveProperty

bool RemoveProperty( SteamInventoryUpdateHandle_t handle, SteamItemInstanceID_t nItemID, const char *pchPropertyName );
Name型別Description
handleSteamInventoryUpdateHandle_tThe update handle corresponding to the transaction request, returned from StartUpdateProperties.
nItemIDSteamItemInstanceID_tID of the item being modified.
pchPropertyNameconst char*The dynamic property being removed.

Removes a dynamic property for the given item.

傳回: bool

另外請見: StartUpdateProperties, SetProperty, SubmitUpdateProperties

SetProperty

bool SetProperty( SteamInventoryUpdateHandle_t handle, SteamItemInstanceID_t nItemID, const char *pchPropertyName, const char *pchPropertyValue ); bool SetProperty( SteamInventoryUpdateHandle_t handle, SteamItemInstanceID_t nItemID, const char *pchPropertyName, bool bValue ); bool SetProperty( SteamInventoryUpdateHandle_t handle, SteamItemInstanceID_t nItemID, const char *pchPropertyName, int64 nValue ); bool SetProperty( SteamInventoryUpdateHandle_t handle, SteamItemInstanceID_t nItemID, const char *pchPropertyName, float flValue );
名稱型別說明
handleSteamInventoryUpdateHandle_tThe update handle corresponding to the transaction request, returned from StartUpdateProperties.
nItemIDSteamItemInstanceID_tID of the item being modified.
pchPropertyNameconst char*The dynamic property being added or updated.
pchPropertyValueconst char*The string value being set.
bValueboolThe boolean value being set.
nValueint64The 64 bit integer value being set.
flValuefloatThe floating point number value being set.

Sets a dynamic property for the given item. Supported value types are strings, boolean, 64 bit integers, and 32 bit floats.

Returns: bool

See Also: StartUpdateProperties, RemoveProperty, SubmitUpdateProperties

回呼

These are callbacks which can be fired by calling SteamAPI_RunCallbacks. Many of these will be fired directly in response to the member functions of ISteamInventory.

SteamInventoryDefinitionUpdate_t

This callback is triggered whenever item definitions have been updated, which could be in response to LoadItemDefinitions or any time new item definitions are available (eg, from the dynamic addition of new item types while players are still in-game).

This callback has no fields.

關聯函式: LoadItemDefinitions

SteamInventoryEligiblePromoItemDefIDs_t

Returned when you have requested the list of "eligible" promo items that can be manually granted to the given user. These are promo items of type "manual" that won't be granted automatically. An example usage of this is an item that becomes available every week.

名稱型別說明
m_resultEResultk_EResultOK upon success, any other value indicates failure.
m_steamIDCSteamID物品將賦予的使用者 Steam ID。
m_numEligiblePromoItemDefsint該使用者符合資格的促銷物品數量。 您應該使用此傳回結果建立 SteamItemDef_t 緩衝區,讓 GetEligiblePromoItemDefinitionIDs 可順利取得實際的 ItemDef。
m_bCachedDataboolIndicates that the data was retrieved from the cache and not the server. This happens if the user is not logged on or can not otherwise connect to the Steam servers.

Associated Functions: RequestEligiblePromoItemDefinitionsIDs

SteamInventoryFullUpdate_t

Triggered when GetAllItems successfully returns a result which is newer / fresher than the last known result. (It will not trigger if the inventory hasn't changed, or if results from two overlapping calls are reversed in flight and the earlier result is already known to be stale/out-of-date.)
The regular SteamInventoryResultReady_t callback will still be triggered immediately afterwards; this is an additional notification for your convenience.

名稱型別說明
m_handleSteamInventoryResult_t新物品庫結果控制代碼。

SteamInventoryResultReady_t

This is fired whenever an inventory result transitions from k_EResultPending to any other completed state, see GetResultStatus for the complete list of states. There will always be exactly one callback per handle.

名稱型別說明
m_handleSteamInventoryResult_t物品庫結果現已產生。
m_resultEResult控制代碼的新狀態。 等同於呼叫 GetResultStatus

SteamInventoryStartPurchaseResult_t

Returned after StartPurchase is called.

名稱型別說明
m_resultEResultk_EResultOK upon success, any other value indicates failure.
m_ulOrderIDuint64發起購買時自動授予的訂單 ID。
m_ulTransIDuint64發起購買時自動授予的交易 ID。

SteamInventoryRequestPricesResult_t

Returned after RequestPrices is called.

名稱型別說明
m_resultEResultk_EResultOK upon success, any other value indicates failure.
m_rgchCurrencychar字串形式的使用者當地貨幣代碼。

結構

These are structs which functions in ISteamInventory may return and/or interact with.

SteamItemDetails_t



名稱型別說明
m_itemIdSteamItemInstanceID_t全域不重複的物品執行個體控制代碼。
m_iDefinitionSteamItemDef_t該物品的物品定義數。
m_unQuantityuint16該物品的當下數量。
m_unFlagsuint16ESteamItemFlags 將位元遮罩後的集合。

Enums

These are enums which are defined for use with ISteamInventory.

ESteamItemFlags

These are bitflags that are set in SteamItemDetails_t.

名稱說明
k_ESteamItemNoTrade1 << 0此物品已鎖在帳戶中,無法交易出去或送出。 此為永久附著於特定物品執行個體上的物品狀態旗標。
k_ESteamItemRemoved1 << 8The item has been destroyed, traded away, expired, or otherwise invalidated. This is an action confirmation flag which is only set one time, as part of a result set.
k_ESteamItemConsumed1 << 9物品數量已透過 ConsumeItem API 減 1。 此動作確認旗標只會在結果集中被設一次。

Typedefs

These are typedefs which are defined for use with ISteamInventory.

名稱基礎型別說明
SteamInventoryResult_tint32非同步物品庫結果控制代碼。
SteamItemDef_tint32您的遊戲中的物品是經由一個 32 位元的「物品定義數」所定義的。
有效的定義數介於 1 至 999999999 之間,比 0 小或等於 0 無效,而大於十億(1x10^9)的數字保留,僅供 Stem 內部使用。
SteamItemInstanceID_tuint64Every individual instance of an item has a globally-unique instance ID.
This ID is unique to the combination of a player and specific item instance, and will not be transferred to another player or re-used for another item.
SteamInventoryUpdateHandle_tuint64Returned from the call StartUpdateProperties, which starts a transaction request to modify dynamic properties on items for the current user.

常數

These are constants which are defined for use with ISteamInventory.

名稱TypeValue說明
k_SteamInventoryResultInvalidSteamInventoryResult_t-1無效的 Steam 物品庫結果控制代碼。
k_SteamItemInstanceIDInvalidSteamItemInstanceID_t(SteamItemInstanceID_t)~0An invalid item instance id. This is usually returned when an operation has failed. It's recommended that you initialize all new item instances with this value.
STEAMINVENTORY_INTERFACE_VERSIONconst char *"STEAMINVENTORY_INTERFACE_V002"
  翻译: