Matt Posted December 17, 2012 Author Share Posted December 17, 2012 This tutorial touches up on the shop system. It adds a multiple shop item cost system, makes it possible to have items that are for free, and adds a nice development feature for editing shops. I'll be adding just one extra one shop item cost, but adding more will be very easy to do after this tutorial.Let's start out on the server!Go to modConstants and look for "Public Const MAX_SHOPS As Long = 50"Underneath it, put there "Public Const MAX_SHOP_ITEM_COSTS as Long = 2"Go to modTypes, and look for "Private Type TradeItemRec"You should see something like this``` costitem As Long costvalue As Long```Replace it with this.``` costitem(1 To MAX_SHOP_ITEM_COSTS) As Long costvalue(1 To MAX_SHOP_ITEM_COSTS) As Long```Now go to the sub "Sub HandleBuyItem"Replace "Dim itemamount As Long" with "Dim itemamount(1 to MAX_SHOP_ITEM_COSTS) As Long"and add "Dim i as long" underneath it.Replace``` ' check has the cost item itemamount = HasItem(index, .costitem) If itemamount = 0 Or itemamount < .costvalue Then PlayerMsg index, "You do not have enough to buy this item.", BrightRed ResetShopAction index Exit Sub End If```with``` ' check has the cost item For i = 1 To MAX_SHOP_ITEM_COSTS ' Check if the cost item is bigger than 0 If .costitem(i) > 0 Then itemamount(i) = HasItem(index, .costitem(i)) If itemamount(i) = 0 Or itemamount(i) < .costvalue(i) Then PlayerMsg index, "You do not have enough to buy this item.", BrightRed ResetShopAction index Exit Sub End If End If Next```and replace```TakeInvItem index, .costitem, .costvalueGiveInvItem index, .Item, .ItemValue```with``` ' Take all the items! For i = 1 To MAX_SHOP_ITEM_COSTS ' Check if the cost item is bigger than 0 If .costitem(i) > 0 Then TakeInvItem index, .costitem(i), .costvalue(i) End If Next ' Give the item GiveInvItem index, .Item, .ItemValue```On to the client!Go to modConstants and look for "Public Const MAX_SHOPS As Long = 50"Underneath it, put there "Public Const MAX_SHOP_ITEM_COSTS as Long = 2"Go to modTypes, and look for "Private Type TradeItemRec"You should see something like this```CostItem As LongCostValue As Long```Replace it with this.```CostItem(1 To MAX_SHOP_ITEM_COSTS) As LongCostValue(1 To MAX_SHOP_ITEM_COSTS) As Long```Now go to frmEditor_Shop and copy these form objects![](http://i.imgur.com/5UKQrn2.png)and paste them right underneath the originals. When it asks if you want to add a control array, hit yes.Now go to "ShopEditorInit" and add "Dim x As Long" just underneath "Dim i As Long"replace```frmEditor_Shop.cmbCostItem.ClearfrmEditor_Shop.cmbCostItem.AddItem "None"```with``` For x = 0 To MAX_SHOP_ITEM_COSTS - 1 frmEditor_Shop.cmbCostItem(x).Clear frmEditor_Shop.cmbCostItem(x).AddItem "None" Next```replace``` For i = 1 To MAX_ITEMS frmEditor_Shop.cmbItem.AddItem i & ": " & Trim$(Item(i).Name) frmEditor_Shop.cmbCostItem.AddItem i & ": " & Trim$(Item(i).Name) Next```with``` For i = 1 To MAX_ITEMS frmEditor_Shop.cmbItem.AddItem i & ": " & Trim$(Item(i).Name) For x = 0 To MAX_SHOP_ITEM_COSTS - 1 frmEditor_Shop.cmbCostItem(x).AddItem i & ": " & Trim$(Item(i).Name) Next Next```and replace``` frmEditor_Shop.cmbItem.ListIndex = 0 frmEditor_Shop.cmbCostItem.ListIndex = 0```with``` frmEditor_Shop.cmbItem.ListIndex = 0 For x = 0 To MAX_SHOP_ITEM_COSTS - 1 frmEditor_Shop.cmbCostItem(x).ListIndex = 0 Next```Now go to "cmdUpdate_Click" and under "Dim Index As Long" put there "Dim i As Long"replace``` With Shop(EditorIndex).TradeItem(Index) .Item = cmbItem.ListIndex .ItemValue = Val(txtItemValue.text) .CostItem = cmbCostItem.ListIndex .CostValue = Val(txtCostValue.text) End With```with``` With Shop(EditorIndex).TradeItem(Index) .Item = cmbItem.ListIndex .ItemValue = Val(txtItemValue.text) For i = 1 To MAX_SHOP_ITEM_COSTS .CostItem(i) = cmbCostItem(i - 1).ListIndex .CostValue(i) = Val(txtCostValue(i - 1).text) Next End With```go to "cmdDeleteTrade_Click" and under "Dim Index As Long" put there "Dim i As Long"replace``` With Shop(EditorIndex).TradeItem(Index) .Item = 0 .ItemValue = 0 .CostItem = 0 .CostValue = 0 End With```with``` With Shop(EditorIndex).TradeItem(Index) .Item = 0 .ItemValue = 0 For i = 1 To MAX_SHOP_ITEM_COSTS .CostItem(i) = 0 .CostValue(i) = 0 Next End With```now go to "UpdateShopTrade" and under "Dim i As Long" put there "Dim x As Long", "Dim Text As String", and "Dim CostText As String"replace``` For i = 1 To MAX_TRADES With Shop(EditorIndex).TradeItem(i) ' if none, show as none If .Item = 0 And .CostItem = 0 Then frmEditor_Shop.lstTradeItem.AddItem "Empty Trade Slot" Else frmEditor_Shop.lstTradeItem.AddItem i & ": " & .ItemValue & "x " & Trim$(Item(.Item).Name) & " for " & .CostValue & "x " & Trim$(Item(.CostItem).Name) End If End With Next```with``` For i = 1 To MAX_TRADES CostText = vbNullString With Shop(EditorIndex).TradeItem(i) ' if none, show as none If .Item = 0 Then Text = "Empty Trade Slot" Else Text = i & ": " & .ItemValue & "x " & Trim$(Item(.Item).Name) & " for " For x = 1 To MAX_SHOP_ITEM_COSTS If .CostItem(x) > 0 Then CostText = CostText & .CostValue(x) & "x " & Trim$(Item(.CostItem(x)).Name) End If Next if CostText = vbNullString Then CostText = " free" End If End With frmEditor_Shop.lstTradeItem.AddItem Text & CostText Next```now go to "picShopItems_MouseDown" and under "Dim shopItem As Long" put there "Dim i As Long" and "Dim CostText As String"replace``` Case 0 ' no action, give cost With Shop(InShop).TradeItem(shopItem) AddText "You can buy this item for " & .CostValue & " " & Trim$(Item(.CostItem).Name) & ".", White End With```with``` Case 0 ' no action, give cost With Shop(InShop).TradeItem(shopItem) For i = 1 To MAX_SHOP_ITEM_COSTS If .CostItem(i) > 0 Then CostText = CostText & " " & .CostValue(i) & " " & Trim$(Item(.CostItem(i)).Name) End If Next If CostText = vbNullString Then CostText = " free" CostText = CostText & "." AddText "You can buy this item for" & CostText, White End With```And lastly, we're going to be adding in a handy tool for editing shops. On frmEditor_Shop, double click on lstTradeItem and paste this code there.```Private Sub lstTradeItem_Click()Dim i As Long With Me .cmbItem.ListIndex = Shop(EditorIndex).TradeItem(lstTradeItem.ListIndex + 1).Item .txtItemValue.Text = Shop(EditorIndex).TradeItem(lstTradeItem.ListIndex + 1).ItemValue For i = 1 To MAX_SHOP_ITEM_COSTS .cmbCostItem(i - 1).ListIndex = Shop(EditorIndex).TradeItem(lstTradeItem.ListIndex + 1).CostItem(i) .txtCostValue(i - 1).Text = Shop(EditorIndex).TradeItem(lstTradeItem.ListIndex + 1).CostValue(i) Next End WithEnd Sub```Compile your server and client, and enjoy! Link to comment Share on other sites More sharing options...
Ganjika Posted December 17, 2012 Share Posted December 17, 2012 I cant find```TakeInvItem index, .costitem, .costvalue```In my project. What steps should i follow for this? Link to comment Share on other sites More sharing options...
Matt Posted December 17, 2012 Author Share Posted December 17, 2012 Look in your sub which handles buying an item in a shop. There should be something like that. Link to comment Share on other sites More sharing options...
Ganjika Posted December 17, 2012 Share Posted December 17, 2012 Could it be modGameEditors?I also keep getting a subscript out of range error when trying to sign in after launch with a highlighted (in modhandledata)``` CopyMemory ByVal VarPtr(Shop(shopnum)), ByVal VarPtr(ShopData(0)), ShopSize```modGameEditors```Public Sub UpdateShopTrade(Optional ByVal tmpPos As Long = 0)Dim i As Long' If debug mode, handle error then exit outIf Options.Debug = 1 Then On Error GoTo errorhandlerfrmEditor_Shop.lstTradeItem.ClearFor i = 1 To MAX_TRADES With Shop(EditorIndex).TradeItem(i) ' if none, show as none If .Item = 0 And .CostItem = 0 Then frmEditor_Shop.lstTradeItem.AddItem "Empty Trade Slot" ElsefrmEditor_Shop.lstTradeItem.AddItem i & ": " & .ItemValue & "x " & Trim$(Item(.Item).Name) & " for " & .CostValue & "x " & Trim$(Item(.CostItem).Name) & " and " & .CostValue2 & "x " & Trim$(Item(.CostItem2).Name) End If End WithNextfrmEditor_Shop.lstTradeItem.ListIndex = tmpPos' Error handlerExit Suberrorhandler:HandleError "UpdateShopTrade", "modGameEditors", Err.Number, Err.Description, Err.Source, Err.HelpContextErr.ClearExit SubEnd Sub```CopyMemory ByVal VarPtr(Shop(shopnum)), ByVal VarPtr(ShopData(0)), ShopSize Link to comment Share on other sites More sharing options...
Matt Posted December 17, 2012 Author Share Posted December 17, 2012 No no. Go on teamviewer. I'll help you out. Link to comment Share on other sites More sharing options...
Wortel Angels Posted December 17, 2012 Share Posted December 17, 2012 there is an tut already for this.. but nice :-) Link to comment Share on other sites More sharing options...
MCADAMS Posted December 17, 2012 Share Posted December 17, 2012 > there is an tut already for this..> I saw a tutorial for this a while ago, but people complained about it being buggy.Literally the first thing he said. Link to comment Share on other sites More sharing options...
Wortel Angels Posted December 17, 2012 Share Posted December 17, 2012 Oh lol xDSorry havent readed it ^^ Link to comment Share on other sites More sharing options...
zerohero Posted January 10, 2013 Share Posted January 10, 2013 Hey this is the tutorial that I made some months ago. From my perspective it was not so much buggy just the code was very bloated due to my lesser knowledge of vb. I will update the original tutorial in a few days. Link to comment Share on other sites More sharing options...
Matt Posted January 10, 2013 Author Share Posted January 10, 2013 When I wasn't so experienced in VB6, I used your tutorial and it didn't work for me. I saw other people complain about it not working as well and that's why I mentioned it.> Hey this is the tutorial that I made some months ago.I assure you I did not copy your code, only the goal. Link to comment Share on other sites More sharing options...
zerohero Posted January 10, 2013 Share Posted January 10, 2013 Sorry I should of said, this is 'based' on the tutorial I made. I meant nothing negative by it only that I think I can re-write it far better than it currently is now. Link to comment Share on other sites More sharing options...
Matt Posted January 10, 2013 Author Share Posted January 10, 2013 > Sorry I should of said, this is 'based' on the tutorial I made. I meant nothing negative by it only that I think I can re-write it far better than it currently is now.Ah I see. Link to comment Share on other sites More sharing options...
Dr.House Posted January 19, 2013 Share Posted January 19, 2013 Method or data member not found. I'm sure that i added everything, and re-added, what could be the problem? using ERHighlights this Public Sub ShopEditorInit() Link to comment Share on other sites More sharing options...
Matt Posted January 21, 2013 Author Share Posted January 21, 2013 > Method or data member not found. I'm sure that i added everything, and re-added, what could be the problem? using ER> > Highlights this PublicSubShopEditorInit()Hi! Sorry I didn't respond so quickly. I've been focusing more on my studies. What bit in that sub does it highlight? Link to comment Share on other sites More sharing options...
Dr.House Posted January 22, 2013 Share Posted January 22, 2013 It highlight just that, searched for more, but didn;t find.. Link to comment Share on other sites More sharing options...
erkro1 Posted January 23, 2013 Share Posted January 23, 2013 > It highlight just that, searched for more, but didn;t find..Change it to this:Public Sub ShopEditorInit() Link to comment Share on other sites More sharing options...
Gemini Xavier Castorm Posted January 31, 2013 Share Posted January 31, 2013 ok. so how do i make it so in a shop it shows both items it requires? because right now it only shows the first one i list…. ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png) Link to comment Share on other sites More sharing options...
Zappy Posted February 9, 2013 Share Posted February 9, 2013 Aha, nice. I was going to make something similar to this to emulate "Crafting" ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Now I can be lazy <3 You're the best Link to comment Share on other sites More sharing options...
Matt Posted February 9, 2013 Author Share Posted February 9, 2013 > Aha, nice. I was going to make something similar to this to emulate "Crafting" ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Now I can be lazy <3 You're the bestNo problem! Tell me if you run into any problems. Keep in mind that this edit assumes there are always two costs! Link to comment Share on other sites More sharing options...
Zappy Posted February 9, 2013 Share Posted February 9, 2013 yeah, I'm just using your work as a guide so I don't have to search. I'm just turning the costitem/costvalue's into arrays ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
DeathKnight Posted February 9, 2013 Share Posted February 9, 2013 Just looking over this code I caught one small thing this line```If itemamount = 0 Or itemamount < .costvalue Or itemamount2 = 0 Or itemamount < .CostValue2 Then```should be this```If itemamount = 0 Or itemamount < .costvalue Or itemamount2 = 0 Or itemamount2 < .CostValue2 Then```otherwise it's compairing item amount 1 to item cost 2 Link to comment Share on other sites More sharing options...
Dr.House Posted February 10, 2013 Share Posted February 10, 2013 You didn't answer my question yet…What is Wrong here? I can't find any other Highlighted just this !![](http://www.freemmorpgmaker.com/files/imagehost/pics/ef800475463ae9d06ddf3b3aa863da99.png) Link to comment Share on other sites More sharing options...
Matt Posted February 10, 2013 Author Share Posted February 10, 2013 > You didn't answer my question yet…> > What is Wrong here? I can't find any other Highlighted just this !What is the error its bringing up?> Just looking over this code I caught one small thing this line> > ```> > If itemamount = 0 Or itemamount < .costvalue Or itemamount2 = 0 Or itemamount < .CostValue2 Then> > ```> > should be this```> > If itemamount = 0 Or itemamount < .costvalue Or itemamount2 = 0 Or itemamount2 < .CostValue2 Then> > ```> > otherwise it's compairing item amount 1 to item cost 2Ah! A mistake on my part. Thank you for pointing it out! I fixed the tutorial. Link to comment Share on other sites More sharing options...
Dr.House Posted February 11, 2013 Share Posted February 11, 2013 Method or data member not found. This is the error, only this appears on client, the server side doesn't highlight anything. Link to comment Share on other sites More sharing options...
Dr.House Posted February 20, 2013 Share Posted February 20, 2013 Of course, ignore the crippled man.Just kidding, but I still wait for a usefull reply. ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png)Thank you 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