Small Crafting Problem

So here is my code. The problem is, when the recipe calls for 1 item it takes the whole stack regardless and gives just 1 product item. Any help on this?```

Private Sub TakePlayerItems(ByVal Index As Long, ByVal itemID As Long, ByVal itemCount As Long, ByVal startSlot As Long)

Dim itemsTaken As Long

itemsTaken = 0

Dim i As Long

If startSlot > 0 And startSlot <= MAX_INV Then

 If player(Index).Char(TempPlayer(Index).CurChar).Inv(startSlot).num = itemID Then

	 If Item(itemID).Type = ITEM_TYPE_CURRENCY Or Item(itemID).Stackable Then

		 itemsTaken = player(Index).Char(TempPlayer(Index).CurChar).Inv(startSlot).Value

	 Else

		 itemsTaken = 1

	 End If

	 player(Index).Char(TempPlayer(Index).CurChar).Inv(startSlot).num = 0

	 player(Index).Char(TempPlayer(Index).CurChar).Inv(startSlot).Value = 0

	 Call SendInventoryUpdate(Index, startSlot)

 End If

End If

For i = 1 To MAX_INV

 If itemsTaken >= itemCount Then Exit Sub

 If player(Index).Char(TempPlayer(Index).CurChar).Inv(i).num = itemID Then

	 If Item(itemID).Type = ITEM_TYPE_CURRENCY Then

		 If player(Index).Char(TempPlayer(Index).CurChar).Inv(i).Value > (itemCount - itemsTaken) Then

			 player(Index).Char(TempPlayer(Index).CurChar).Inv(i).Value = player(Index).Char(TempPlayer(Index).CurChar).Inv(i).Value - itemCount + itemsTaken

			 itemsTaken = itemCount

			 player(Index).Char(TempPlayer(Index).CurChar).Inv(i).num = 0

		 Else

			 itemsTaken = itemsTaken + player(Index).Char(TempPlayer(Index).CurChar).Inv(i).Value

			 player(Index).Char(TempPlayer(Index).CurChar).Inv(i).num = 0

		 End If

	 Else

		 itemsTaken = itemsTaken + 1

		 player(Index).Char(TempPlayer(Index).CurChar).Inv(i).num = 0

	 End If

	 Call SendInventoryUpdate(Index, i)

 End If

Next i

End Sub

Replaced it with Sub TakePlayerItems from Eclipse Reborn

Okay, I replaced it, but Now when crafting something, it gives me an error in do recipe logic. here is the code```

Public Function DoRecipeLogic(ByVal index As Long, ByVal RIndex As Long, ByVal SlotA As Long, ByVal SlotB As Long, ByVal productionCount As Long) As Boolean

Dim itemCount As Long

DoRecipeLogic = False

If Not (CanPlayerUseRecipe(index, RIndex, True)) Then Exit Function

itemCount = GetPlayerItemCount(index, Recipe(RIndex).itemID)

If itemCount < Recipe(RIndex).itemCount Then

 Call SendBattleMsg(index, "You need " & Recipe(RIndex).itemCount & " " & GetItemName(Recipe(RIndex).itemID) & " to craft a " & GetItemName(Recipe(RIndex).ResultItem), Red)

 Exit Function

End If

If Not (Recipe(RIndex).TileRecipe) And Recipe(RIndex).SecondItem > 0 Then

 If GetPlayerItemCount(index, Recipe(RIndex).SecondItem) < 1 Then

	 Call SendBattleMsg(index, "You need one " & GetItemName(Recipe(RIndex).SecondItem) & " to craft a " & GetItemName(Recipe(RIndex).ResultItem) & ".", Red)

	 Exit Function

 End If

End If

If Not (HasInventorySpaceFor(index, RIndex)) Then

 If Item(Recipe(RIndex).ResultItem).Type = ITEM_TYPE_CURRENCY Then

	 Call SendBattleMsg(index, "You need a free inventory slot to craft a " & GetItemName(Recipe(RIndex).ResultItem) & ".", Red)

 Else

	 Call SendBattleMsg(index, "You need " & Recipe(RIndex).ResultCount & " free inventory spaces to craft a " & GetItemName(Recipe(RIndex).ResultItem) & ".", Red)

 End If

 Exit Function

End If

If Recipe(RIndex).ToolRequired > 0 And Not (HasTool(index, Recipe(RIndex).ToolRequired)) Then

 Call SendBattleMsg(index, "You need a " & GetToolTypeName(Recipe(RIndex).ToolRequired) & " to create a " & GetItemName(Recipe(RIndex).ResultItem) & ".", Red)

 Exit Function

End If

Dim firstSlot As Long, secondSlot As Long

If player(index).Char(TempPlayer(index).CurChar).Inv(SlotA).num = Recipe(RIndex).itemID Then

 firstSlot = SlotA

 secondSlot = SlotB

Else

 firstSlot = SlotB

 secondSlot = SlotA

End If

Dim i As Long

Dim made As Long

made = 0

Do While True

 Call TakePlayerItems(index, Recipe(RIndex).itemID, Recipe(RIndex).itemCount, firstSlot)

 If Not (Recipe(RIndex).TileRecipe) And Recipe(RIndex).SecondItem > 0 Then

	 Call TakePlayerItems(index, Recipe(RIndex).SecondItem, 1, secondSlot)

 End If

 Call GivePlayerItems(index, Recipe(RIndex).ResultItem, Recipe(RIndex).ResultCount)

 Select Case Recipe(RIndex).Type

	 Case 1: GivePlayerEXP index, Crafting, Recipe(RIndex).Exp

	 Case 2: GivePlayerEXP index, Alchemy, Recipe(RIndex).Exp

 End Select

 Call CheckTasks(index, QUEST_TYPE_GOGATHER, Recipe(RIndex).ResultItem)

 made = made + 1

 If made >= productionCount And productionCount > 0 Then Exit Do

 If Not (CanDoRecipe(index, RIndex)) Then Exit Do

Loop

DoRecipeLogic = True

End Function


If Not (Recipe(RIndex).TileRecipe) And Recipe(RIndex).SecondItem > 0 Then

Call TakePlayerItems(index, Recipe(RIndex).SecondItem, 1, secondSlot)

End If

What’s the error in that highlighted section? Like ‘Subscript out of range’? What’s the issue and exactly what line is it breaking on?

Log in to reply