Jessecar96 / SteamBot

Automated bot software for interacting with Steam Trade
http://scrap.tf
MIT License
1.33k stars 910 forks source link

Delete Item code... #295

Closed tkphoto closed 11 years ago

tkphoto commented 11 years ago

After updating with the newest code today, i have tried testing if its working in its most basic form by checking a crate id and then forming a on message to delete this item and subsequently checking if its been removed..

ie..

if (message == "crate") { Bot.SetGamePlaying(440); SteamBot.TF2GC.Items.DeleteItem(Bot,1650009978);

        }  

This does not seem to work..

After the initial test i was hoping to expand on issuing a delete command for all crates... so if anyone also knows how to combine deleting with all crates apart from salvage..

DrProfAxesome commented 11 years ago

I would assume that to delete all crates, you would have to make a function that would get your inventory (assuming you aren't in a trade) then check for crates in the inventory, and then for each crate id, delete it

awillinger commented 11 years ago

Anyone made any progress on this? Would be handy for example to delete all crates at once.

iMagooo commented 11 years ago

307 #307 #307

But, I'm bored.

This needs to be in your userhandler, underneath if (IsAdmin) within the OnMessage() function.

if (message.startswith(".deletecrates")
{
    Bot.DeleteAllCrates();
}

SEE THE SIMPLIFIED CODE IN A BELOW COMMENT Put this in Bot.cs, needs to be called from the UserHandler using a call similar to the above call.

/// <summary>
/// Deletes all crates in the users inventory
/// </summary>
public void DeleteAllCrates()
{
    GetInventory();
    List<ulong> toDelete = new List<ulong>();

    //Iterate over each item in the bot's inventory
    foreach (var item in MyInventory.Items)
    {
        //If the item is a crate
        if (Trade.CurrentSchema.GetItem(item.Defindex).ItemClass == "supply_crate")
        {
            // This function will only work up until crate series #99
            for (int series = 1; series < 100; series++)
            {
                //Assuming that Valve's pattern of salvaged crates continue to occur at 10x, if not, edit this if statement
                //If the crate is salvaged, do not move on to delete
                if (series!=30 && series!=40 && series!=50 && series!=60 && series!=70 && series!=80 && series!=90)
                {
                    //We need to search the whole Attributes array for the series number 
                    for (int count = 0; count < item.Attributes.Length; count++)
                    {
                        // FloatValue will give you the crate's series number
                        if (series == (int)item.Attributes[count].FloatValue)
                        {
                            toDelete.Add(item.Id);
                        }
                    }
                }
            }
        }
    }

    if (CurrentGame != 440)
    {
        SetGamePlaying(440);
        System.Threading.Thread.Sleep(1000);
    }

    foreach (ulong itemID in toDelete)
    {
        TF2GC.Items.DeleteItem(this, itemID);
        System.Threading.Thread.Sleep(200);
    }

    toDelete.Clear();
}

Bare in mind, this function is untested and has been thoroughly simplified in a below comment.

@redjazz96 unless someone can see a major flaw in what I wrote, this issue is solved.

iMagooo commented 11 years ago

Yeah, I just looked at the Russian/Chinese Schema, the item_name attribute is in Russian/Chinese.

If language cross-compatibility was not needed, then using the item_name attribute would save a lot of code.

Another option is to look at the name attribute, which seems to be consistent across all languages. The Salvaged Crates have: "name": "Supply Crate Rare"

vs. a regular crate: "name": "Supply Crate"

But, then the code doesn't account for Summer/Winter/Other crates, which all seem to have another name.

We could use: if (item.Name.Contains("Crate")&& !item.Name.Contains("Rare")&& item.ItemClass == "supply_crate")

Which should flag for all crates, not including the Rare (Salvaged) crates and the item.ItemClass == "supply_crate" will ensure that it does not flag for other items such as the pallet of crates.

iMagooo commented 11 years ago
/// <summary>
/// Deletes all crates in the users inventory
/// </summary>
public void DeleteAllCrates()
{
    GetInventory();
    List<ulong> toDelete = new List<ulong>();

    //Iterate over each item in the bot's inventory
    foreach (var item in MyInventory.Items)
    {
        var schemaItem = Trade.CurrentSchema.GetItem(item.Defindex);
        if (schemaItem.Name.Contains("Crate")&& !schemaItem.Name.Contains("Rare")&& schemaItem.ItemClass == "supply_crate")
        {
             toDelete.Add(item.Id);    
        }
    }

    if (CurrentGame != 440)
    {
        SetGamePlaying(440);
        System.Threading.Thread.Sleep(1000);
    }

    foreach (ulong itemID in toDelete)
    {
        TF2GC.Items.DeleteItem(this, itemID);
        System.Threading.Thread.Sleep(200);
    }

    toDelete.Clear();
}
thesandvichisaliar commented 11 years ago

Since every crate has had a series number, why don't you just check for a defindex of 187 in the item's Attributes? Then you can also easily customize which crate numbers you don't want to delete like any future salvaged crates (salvaged = FloatValue % 10 == 0 && FloatValue > 20). You could also save any expired (or brand new) crates that you don't want to delete with an optional parameter holding series #'s to keep.

This will get any future crate, no matter the name, without having to find each one in the schema.

ric20007 commented 11 years ago

Salvaged crates have this defindex 5068. Wouldn't it be easier not to craft this defindex ? schemaItem.Defindex != 5068

thesandvichisaliar commented 11 years ago

@ric20007 That is definitely easier. Although I would use the Inventory.Item Defindex, just to avoid searching the schema.

iMagooo commented 11 years ago

@thesandvichisaliar @ric20007 There are multiple implementations, realistically all will work just as well. Feel free to do what you want with the code from here, but the issue's resolved.

iMagooo commented 11 years ago

@redjazz96 Unless this is something you think should be added (in which case the code probably should be optimized to just use the Inventory.Item class as opposed to referring to the Schema.Item), this issue can be closed.