Ravey Posted July 24, 2012 Author Share Posted July 24, 2012 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.ClientfrmMain- 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 Suberrorhandler: HandleError "cmdCraft_Click", "frmMain", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd Sub```modClientTCPPlace 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 Suberrorhandler: HandleError "CraftItem", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd Sub```modEnumerations**Do this both in Client and Server!**Find 'Packets sent by client to serverPut **CCraftItem** to the list.ServermodHandleDataPut 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 ScriptMake a new module or put this in modCustomScripts.```'###################'### CRAFTING #####'###################Public Sub CraftFail(index)PlayerMsg index, "Didn't make anything!", BrightRedEnd SubPublic 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 SelectEnd SubPublic 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 SubEnd IfSetPlayerBankItemValue 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, 0If GetPlayerBankItemValue(index, 2) = 0 Then SetPlayerBankItemNum index, 2, 0If GetPlayerBankItemValue(index, 3) = 0 Then SetPlayerBankItemNum index, 3, 0GiveInvItem index, CraftResult, 1, TrueSendBank indexPlayerMsg index, "Item crafted successfully!", BrightGreenEnd 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 More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 How do i craft on it? Link to comment Share on other sites More sharing options...
Ravey Posted July 25, 2012 Author Share Posted July 25, 2012 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 scriptClick 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 More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 how do i make item that will be result on crafting? Link to comment Share on other sites More sharing options...
Ravey Posted July 25, 2012 Author Share Posted July 25, 2012 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 More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 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 More sharing options...
Ravey Posted July 25, 2012 Author Share Posted July 25, 2012 Alright, look at thisYou need to define the Primary item for the recipe.Select Case CraftSlot1Select Case CraftAmnt1Cases of CraftSlot1 mean the NUMBER od the ITEM in your first slotCase 0 = No itemCase 1 = Item # 1Case 2 = Item # 2Case 3 = Item # 3Case 234 = Item # 234Case Else = Any other item that has no primary crafting usageThen, 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 More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 i don't understand , If i put 5 items at Slot 1 and 1 item at slot 2 , The result will be the Slot 3 item on my Inventory? Link to comment Share on other sites More sharing options...
Ravey Posted July 25, 2012 Author Share Posted July 25, 2012 No, the result will be Item # 3 as chosen in the Item Editor. Link to comment Share on other sites More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 Item Number 3? what if i want the result will be a flame sword on item number 20? Link to comment Share on other sites More sharing options...
Ravey Posted July 25, 2012 Author Share Posted July 25, 2012 @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 EDITOR1.Gold2.Hatchet3.Wood Log...............27\. Iron Sword28\. Essence of Fire............45\. Flame SwordFirst,**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 Sword1 .... Take 1x Iron Sword10 .... Take 10x Essence of Fire0 .... Take nothing, no slot 3 requirementThat is all i can possibly do to explain it.Regards,Ravey. Link to comment Share on other sites More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 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.. ;DEDIT: 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!", BrightRedEnd SubPublic 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 SelectEnd SubPublic 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 SubEnd IfSetPlayerBankItemValue 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, 0If GetPlayerBankItemValue(index, 2) = 0 Then SetPlayerBankItemNum index, 2, 0If GetPlayerBankItemValue(index, 3) = 0 Then SetPlayerBankItemNum index, 3, 0GiveInvItem index, CraftResult, 1, TrueSendBank indexPlayerMsg index, "Item crafted successfully!", BrightGreenEnd IfEnd Sub```Because i remove it , Well it said End If without Block If Link to comment Share on other sites More sharing options...
Ravey Posted July 25, 2012 Author Share Posted July 25, 2012 That means it is needed there, so put it back.Regards,Ravey. Link to comment Share on other sites More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 @Ravey:> That means it is needed there, so put it back.> > Regards,> Ravey.I mean it Said End If without Block If , When End If is still there , But when i remove it no error shown.. Link to comment Share on other sites More sharing options...
Ravey Posted July 25, 2012 Author Share Posted July 25, 2012 @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 More sharing options...
hisherwin Posted July 25, 2012 Share Posted July 25, 2012 haven't tested yet :D but thanks for this.. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now