Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Small Crafting Problem


SkywardRiver
 Share

Recommended Posts

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

```
Link to comment
Share on other sites

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

```Highlights this section 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
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...