waylaidwanderer / PHP-SteamCommunity

A PHP library for interacting with the Steam Community website (steamcommunity.com)
MIT License
77 stars 41 forks source link

How to get the new assetid after a trade #38

Closed timmy78 closed 8 years ago

timmy78 commented 8 years ago

Hi

I don't know if you noticed, but the assetid of an item change after that the trade was confirmed.

So do you know if there is solution the get this new assetid ??

Here and here they are speaking about a function getItems

Thanks !

mruz commented 8 years ago

@timmy78 after merge you can try:

$tradeOffers = new SteamCommunity\TradeOffers($community);
$tradeOffer = $tradeOffers->getTradeOfferViaAPI($tradeOfferId);
$ids = $tradeOffers->getItems($tradeOffer);
timmy78 commented 8 years ago

Thank you !

Okay now I can get all new asset IDs.

But, in the case I have more than one item in the trade offer, I cannot match new asset IDs with old asset IDs (which are saved in DB for example). And the order of the items is not the same than GetTradeOffer order. So I'm still stuck. :sob:

Maybe the other way is to save the original_id which never change :confused:

Thanks for your help !

mruz commented 8 years ago

There is no "original_id which never change", you need to compare by yourself and market_hash_name.

timmy78 commented 8 years ago

I cannot compare in the case where there are mulitple identical items in the same trade offer , the market_hash_name, instanceid or classid are not unique :confused:

For example, if there are multiple items in a trade offer which are identical (same market_hash_name, same instanceid or same classid), I cannot match each item individually with getItems

Only the asset_id and original_id are uniques.


This is what I can get with getItems :

oItem = {"id":"5961236058","owner":"76561198277521499","classid":"384801282","instanceid":"0","market_hash_name":"CS:GO Weapon Case 3" }

oItem = {"id":"5961235873","owner":"76561198277521499","classid":"384801282","instanceid":"0","market_hash_name":"CS:GO Weapon Case 3"}

oItem = {"id":"5961235928","owner":"76561198277521499","classid":"310776566","instanceid":"302028390","market_hash_name":"AWP | Safari Mesh (Field-Tested)"}

Here I have two identical items, how can I know how to map each item which the original asset_ids ?

Here is my trade offer informations :

"offer": {
    "tradeofferid": "1188324023",
    "accountid_other": 82402037,
    "message": "...",
    "expiration_time": 1462802313,
    "trade_offer_state": 3,
    "items_to_receive": [
        {
            "appid": "730",
            "contextid": "2",
            "assetid": "4794390225",
            "classid": "720296558",
            "instanceid": "188530170",
            "amount": "1",
            "missing": true
        },
        {
            "appid": "730",
            "contextid": "2",
            "assetid": "4794352410",
            "classid": "384801282",
            "instanceid": "0",
            "amount": "1",
            "missing": true
        },
        {
            "appid": "730",
            "contextid": "2",
            "assetid": "4794361502",
            "classid": "310776566",
            "instanceid": "302028390",
            "amount": "1",
            "missing": true
        }
    ]
    ,
    "is_our_offer": true,
    "time_created": 1461592713,
    "time_updated": 1461592749,
    "tradeid": "465370522855866036",
    "from_real_time_trade": false,
    "escrow_end_date": 0,
    "confirmation_method": 0
}

Thanks !

mruz commented 8 years ago

Here I have two identical items, how can I know how to map each item which the original asset_ids?

I think you cannot. Steam's api doesn't provide original_id after trade, also asset_id and other *id can change afer trade, so you can not identify by them, just map by market_hash_name. If you have 2 or more the same name does it matter which was "original_id"?

waylaidwanderer commented 8 years ago

@mruz original_id is provided by the GetPlayerItems API. @timmy78 Before the trade, make a call to GetPlayerItems and record the original_id of each item, and then after the trade, make a call to GetPlayerItems and find the original_id again to get the new id. Keep in mind that the CSGO API for GetPlayerItems is buggy and often returns {} as a response, so you will need to use a retry-loop until you get a non-empty JSON response.

timmy78 commented 8 years ago

Thanks for the answers !

@mruz

If you have 2 or more the same name does it matter which was "original_id"?

Yes, because each CSGO weapon is unique (the wear is different, can have stickers, etc...)

@waylaidwanderer Yes, this is what I wanted to do, but as you say, GetPlayerItems often bugs (like yesterday)

What I will do is a mix.

Thanks again !