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

Rav's cheap Crafting System (100% source-based)


Ravey
 Share

Recommended Posts

Hello,

I made a simple crafting system which uses the Bank.

Why the bank? because a Bank can store stacks of any item, not just currencies, useful when combining non-stacks of the same type.

Therefore, if you are interested, and haven't fixed your bank currency withdrawal bug yet, reffer to:

[http://www.touchofdeathforums.com/smf2/index.php/topic,81828.0.html](http://www.touchofdeathforums.com/smf2/index.php/topic,81828.0.html)

It uses bank slot checks to give items, the downside? It requires manual scripting for the whole thing. On the other side, you can make anything to happen once you have enough items in the slots, not only make an item.

Client

frmMain

- Find picBank and make a Command Button called "cmdCraft" in it, or anything else you want to click at.

- Double click "cmdCraft"

- Put this in:
```
Private Sub cmdCraft_Click()
' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    CraftItem

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "cmdCraft_Click", "frmMain", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub
```
modClientTCP

Place this to the bottom:

```
Public Sub CraftItem()
Dim Buffer As clsBuffer

    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    Set Buffer = New clsBuffer
    Buffer.WriteLong CCraftItem
    SendData Buffer.ToArray()
    Set Buffer = Nothing

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "CraftItem", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub
```
modEnumerations

**Do this both in Client and Server!**

Find 'Packets sent by client to server

Put **CCraftItem** to the list.

Server

modHandleData
Put this in the same order as the enumerations packets (not sure if it's neccesary)

```
HandleDataSub(CCraftItem) = GetAddress(AddressOf HandleCraftItem)
```
Now, add this there, too:

```
Sub HandleCraftItem(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    Call CraftScript(index)
End Sub
```
Crafting Script

Make a new module or put this in modCustomScripts.

```
'###################
'### CRAFTING  #####
'###################

Public Sub CraftFail(index)
PlayerMsg index, "Didn't make anything!", BrightRed
End Sub

Public Sub CraftScript(index As Long)
    Dim CraftSlot1 As Long
    Dim CraftSlot2 As Long
    Dim CraftSlot3 As Long
    Dim CraftAmnt1 As Long
    Dim CraftAmnt2 As Long
    Dim CraftAmnt3 As Long

    ' item index number
    CraftSlot1 = GetPlayerBankItemNum(index, 1)
    CraftSlot2 = GetPlayerBankItemNum(index, 2)
    CraftSlot3 = GetPlayerBankItemNum(index, 3)
    ' amount of items
    CraftAmnt1 = GetPlayerBankItemValue(index, 1)
    CraftAmnt2 = GetPlayerBankItemValue(index, 2)
    CraftAmnt3 = GetPlayerBankItemValue(index, 3)

    Select Case CraftSlot1
        Case 0 'USAGE-NONE
            PlayerMsg index, "You don't have a primary item in the first slot.", BrightRed

        Case 1 'USAGE-ITEM1
            Select Case CraftAmnt1
                Case Is >= 5
                    Select Case CraftSlot2
                        Case 2
                            Select Case CraftAmnt2
                                Case Is >= 1
                                    Call CraftProcess(index, 3, 5, 1, 0)
                                Case Else
                                    Call CraftFail(index)
                            End Select
                        Case Else
                            Call CraftFail(index)
                    End Select
                Case Else
                    Call CraftFail(index)
            End Select

        Case Else
            PlayerMsg index, "This item has no primary crafting usage.", BrightCyan
        End Select
End Sub

Public Sub CraftProcess(index As Long, CraftResult As Long, BnkChangeSlotAmnt1 As Long, BnkChangeSlotAmnt2 As Long, BnkChangeSlotAmnt3 As Long)

If FindOpenInvSlot(index, CraftResult) = 0 Then
    PlayerMsg index, "Inventory full!", Red
    Exit Sub
End If
SetPlayerBankItemValue index, 1, (GetPlayerBankItemValue(index, 1) - BnkChangeSlotAmnt1)
SetPlayerBankItemValue index, 2, (GetPlayerBankItemValue(index, 2) - BnkChangeSlotAmnt2)
SetPlayerBankItemValue index, 3, (GetPlayerBankItemValue(index, 3) - BnkChangeSlotAmnt3)
'check if the slots are at 0 amount, if that's true, clear the items from the slots completely.
If GetPlayerBankItemValue(index, 1) = 0 Then SetPlayerBankItemNum index, 1, 0
If GetPlayerBankItemValue(index, 2) = 0 Then SetPlayerBankItemNum index, 2, 0
If GetPlayerBankItemValue(index, 3) = 0 Then SetPlayerBankItemNum index, 3, 0
GiveInvItem index, CraftResult, 1, True
SendBank index
PlayerMsg index, "Item crafted successfully!", BrightGreen

End Sub
```
The first cases mean the number of the item, as in it's item editor inventory item number. then, you check for amount of slot 1 by adding another case selection, then you add another case selection for slot 2, check item, then, another case selection for amount check.

Call CraftProcess usage is:
```
Call CraftProcess(index, item number to give to the player, slot#1 substraction, slot#2 substraction, slot#3 substraction)
```
Make sure you try putting 5x Item#1 in the first bank slot and 1x Item#2 in the second bank slot, then click the button.

And so on, good luck.

Regards,
Ravey
Link to comment
Share on other sites

Put a primary item in the first slot in your bank,

Put another item in the second slot, and more you might specify in the craft script

Click the button.

I left a default item there,

You make it by putting 5 items of number 1 and 1 item of number 2, it puts item number 3 in your inventory.

Regards,
Ravey.
Link to comment
Share on other sites

I added descriptions.

```
Case 1 ' Check if we have item 1 in slot 1
            Select Case CraftAmnt1
                Case Is >= 5 ' Check if we have a stack of 5 or more of item 1
                    Select Case CraftSlot2
                        Case 2 ' Continue, Check if we have item 2 in slot 2 (Case = Item number, CraftSlot2 = slot)
                            Select Case CraftAmnt2
                                Case Is >= 1 ' Check if we have 1 amount of item 2.
                                    Call CraftProcess(index, 3, 5, 1, 0) ' Process the craft, give item 3, take away 5 items from slot 2, take away 1 item from slot 2
                                Case Else
                                    Call CraftFail(index)
                            End Select
                        Case Else
                            Call CraftFail(index)
                    End Select
                Case Else
                    Call CraftFail(index)
            End Select
```
You need to know how Case Selects work.

It's not that hard, just needs logic.

Regards,
Ravey
Link to comment
Share on other sites

Should it be..
```
Case 1 ' Check if we have item 1 in slot 1
            Select Case CraftAmnt1
                Case Is >= 5 ' Check if we have a stack of 5 or more of item 1
                    Select Case CraftSlot2
                        Case 2 ' Continue, Check if we have item 2 in slot 2 (Case = Item number, CraftSlot2 = slot)
                            Select Case CraftAmnt2
                                Case Is >= 1 ' Check if we have 1 amount of item 2.
                                    Call CraftProcess(index, 3, 5, 1, 0) ' Process the craft, give item 3, take away 5 items from slot 1, take away 1 item from slot 2
                                Case Else
                                    Call CraftFail(index)
                            End Select
                        Case Else
                            Call CraftFail(index)
                    End Select
                Case Else
                    Call CraftFail(index)
            End Select

```?
Link to comment
Share on other sites

Alright, look at this

You need to define the Primary item for the recipe.

Select Case CraftSlot1
Select Case CraftAmnt1

Cases of CraftSlot1 mean the NUMBER od the ITEM in your first slot

Case 0 = No item

Case 1 = Item # 1

Case 2 = Item # 2

Case 3 = Item # 3

Case 234 = Item # 234

Case Else = Any other item that has no primary crafting usage

Then, you create subchecks after checking the item, you check it's amount.

Sorry, I can't help more than this.

Just read it carefully in the source code, too see how it works.
Link to comment
Share on other sites

@Sherwin:

> Item Number 3? what if i want the result will be a flame sword on item number 20?

To make it very simple…

ITEM EDITOR

1.Gold
2.Hatchet
3.Wood Log
...
...
...
...
...
27\. Iron Sword
28\. Essence of Fire
...
...
...
...
45\. Flame Sword

First,

**In Select Case CraftSlot1**

Case 27  <–-- PRIMARY ITEM : 27 - Iron Sword

...**Select Case CraftAmnt1**
…..Case Is >= 1  <-------- Check if slot 1 has 1 or more in a stack, 1 Iron Sword or more
.........**Select Case CraftSlot2**
…...........Case 28 <----- SECONDARY ITEM : 28 - Essence of Fire
..................**Select Case CraftAmnt2**
…....................Case Is >= 10 <------ Check if slot 2 has 10 or more in stack, At least 10x Essence
..............................Call CraftProcess(index, 45, 1, 10, 0)

45 .... Give Item Number 45 --- Flame Sword
1 .... Take 1x Iron Sword
10 .... Take 10x Essence of Fire
0 .... Take nothing, no slot 3 requirement

That is all i can possibly do to explain it.

Regards,
Ravey.
Link to comment
Share on other sites

So i should add code to it first before it work? can you make a program that will make a result , because i was thinking to add alot of it.. ;D
EDIT: Nvm i got it how it work..

EDIT: at this sub , does the end if at the last part still needed?
```
'###################
'### CRAFTING  #####
'###################

Public Sub CraftFail(index)
PlayerMsg index, "Didn't make anything!", BrightRed
End Sub

Public Sub CraftScript(index As Long)
    Dim CraftSlot1 As Long
    Dim CraftSlot2 As Long
    Dim CraftSlot3 As Long
    Dim CraftAmnt1 As Long
    Dim CraftAmnt2 As Long
    Dim CraftAmnt3 As Long

    ' item index number
    CraftSlot1 = GetPlayerBankItemNum(index, 1)
    CraftSlot2 = GetPlayerBankItemNum(index, 2)
    CraftSlot3 = GetPlayerBankItemNum(index, 3)
    ' amount of items
    CraftAmnt1 = GetPlayerBankItemValue(index, 1)
    CraftAmnt2 = GetPlayerBankItemValue(index, 2)
    CraftAmnt3 = GetPlayerBankItemValue(index, 3)

    Select Case CraftSlot1
        Case 0 'USAGE-NONE
            PlayerMsg index, "You don't have a primary item in the first slot.", BrightRed

        Case 1 'USAGE-ITEM1
            Select Case CraftAmnt1
                Case Is >= 5
                    Select Case CraftSlot2
                        Case 2
                            Select Case CraftAmnt2
                                Case Is >= 1
                                    Call CraftProcess(index, 3, 5, 1, 0)
                                Case Else
                                    Call CraftFail(index)
                            End Select
                        Case Else
                            Call CraftFail(index)
                    End Select
                Case Else
                    Call CraftFail(index)
            End Select

        Case Else
            PlayerMsg index, "This item has no primary crafting usage.", BrightCyan
        End Select
End Sub

Public Sub CraftProcess(index As Long, CraftResult As Long, BnkChangeSlotAmnt1 As Long, BnkChangeSlotAmnt2 As Long, BnkChangeSlotAmnt3 As Long)

If FindOpenInvSlot(index, CraftResult) = 0 Then
    PlayerMsg index, "Inventory full!", Red
    Exit Sub
End If
SetPlayerBankItemValue index, 1, (GetPlayerBankItemValue(index, 1) - BnkChangeSlotAmnt1)
SetPlayerBankItemValue index, 2, (GetPlayerBankItemValue(index, 2) - BnkChangeSlotAmnt2)
SetPlayerBankItemValue index, 3, (GetPlayerBankItemValue(index, 3) - BnkChangeSlotAmnt3)
'check if the slots are at 0 amount, if that's true, clear the items from the slots completely.
If GetPlayerBankItemValue(index, 1) = 0 Then SetPlayerBankItemNum index, 1, 0
If GetPlayerBankItemValue(index, 2) = 0 Then SetPlayerBankItemNum index, 2, 0
If GetPlayerBankItemValue(index, 3) = 0 Then SetPlayerBankItemNum index, 3, 0
GiveInvItem index, CraftResult, 1, True
SendBank index
PlayerMsg index, "Item crafted successfully!", BrightGreen
End If

End Sub

```
Because i remove it , Well it said End If without Block If
Link to comment
Share on other sites

@Sherwin:

> I mean it Said End If without Block If , When End If is still there , But when i remove it no error shown..

Ahh, sorry.

The one i use has additional functions, i forgot to remove the End If for the tutorial.

Then yes, it shouldn't be there. Sorry for the dismay.

Regards,
Ravey.
Link to comment
Share on other sites

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...