I already am. Should I add a reference to it or just use Imports System.Linq?
Nvm, you can't add a reference to it.
I already am. Should I add a reference to it or just use Imports System.Linq?
Nvm, you can't add a reference to it.
Last edited by poopsiedoodle; 09-30-2013 at 12:41 PM.
It's not a problem with referencing the LINQ library. It's just how listbox items are stored. Try this:
Code:Dim lootItem as LootItem = ListBox3.Items.ToList().Where(Function(x) x.Text = loot.Id).FirstOrDefault()
I'll try it as soon as I get home from school.
EDIT:Code:Error 1 'ToList' is not a member of 'System.Windows.Forms.ListBox.ObjectCollection'. C:\Documents and Settings\matt and steve\My Documents\Downloads\Bot (1)\Bot\Bot\Form2.vb 471 44 Bot
Last edited by poopsiedoodle; 09-30-2013 at 08:23 PM.
I apologize, this is what I get for not having access to VB and trying to type from memory on my cellphone. See if this will work:
That should convert all the listboxitems to a list of LootItem objects. If that doesn't work, I'll have to give it a shot once I'm in front of my computer and can access VB.Code:Dim lootItem as LootItem = ListBox3.Items.OfType(Of LootItem)().FirstOrDefault(Function(x) x.Text = loot.Id)
Well, there aren't any errors with that, just the same warning I have with the attacker (before and after your new code) which isbut that hasn't caused any problems, so meh.Code:Warning 2 Using the iteration variable in a lambda expression may have unexpected results. Instead, create a local variable within the loop and assign it the value of the iteration variable.
I forgot about that little warning with lambda expressions... You can solve it by setting 'loot' to a variable before the line above (Dim lootItem As LootItem...) and then reference that variable instead of loot.
Code:Private Sub LootItems() For Each body As Container In inventory.GetContainers().Where(Function(x) x.Name.ToLower().StartsWith("dead ") Or x.Name.ToLower().StartsWith("remains ") Or x.Name.ToLower().StartsWith("slain ")) For Each loot As Item In body.GetItems() Dim thisLoot As Item = loot Dim lootItem As LootItem = ListBox3.Items.OfType(Of LootItem)().FirstOrDefault(Function(x) x.Text = thisLoot.Id) If lootItem IsNot Nothing Then lootBP = inventory.GetContainers().FirstOrDefault(Function(x) x.Name = lootItem.BP) If lootBP IsNot Nothing Then lootItem.Move(lootBP.GetItems().First().Location) End If End If Next Next End Sub
well, it still loots stuff, so I don't think there'd be too much point in changing it :P
Now I just have to figure out a way to put the body locating/opening code that I wrote in there.
Ok, so, my function for opening bodies is not working at all. LootItems() is working though. Here's what I have:
Code:Private Function openbodies() My.Settings.deadlocs.Clear() For Each dead As Creature In c.BattleList.GetCreatures If dead.HPBar = 0 Then My.Settings.deadlocs.Add(dead.Location.ToString) For Each bodyloc As String In My.Settings.deadlocs For Each square As Tile In c.Map.GetTiles If square.Location.ToString = bodyloc Then For Each deadbody As Item In square.Items If deadbody.Name.Contains("Dead") Or deadbody.Name.Contains("Slain") Or deadbody.Name.Contains("Remains") Then p.Walk(bodyloc) c.Inventory.UseItemOnTile(deadbody.Id, square) Lootitems() End If Next End If Next Next End If Next Return True End Function Private Function Lootitems() For Each body As Container In inventory.GetContainers().Where(Function(x) x.Name.ToLower().StartsWith("dead ") Or x.Name.ToLower().StartsWith("remains ") Or x.Name.ToLower().StartsWith("slain ")) For Each loot As Item In body.GetItems() Dim lootItem As LootItem = ListBox3.Items.OfType(Of LootItem)().FirstOrDefault(Function(x) x.Text = loot.Id) If lootItem IsNot Nothing Then Dim lootBP = inventory.GetContainers().FirstOrDefault(Function(x) x.Name = lootItem.BP) If lootBP IsNot Nothing Then loot.Move(lootBP.GetItems().First().Location) End If End If Next Next Return True End Function