sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 In EO, there's a function that will check if you have a certain item in your inventory, but not how many of that item you have(unless it's currency) This function will return the amount of the specified item.Please note this is not used for currency, use the HasItem function to get the amount of money you have. This will count each slot that the specified item is in and return that number.**Server-Side**In modPlayer, all the way at the bottom add this:```Function GetAmountOfItem(ByVal index As Long, ByVal itemNum As Long) Dim i As Long, counter As Long counter = 0 ' Check for subscript out of range If IsPlaying(index) = False Or itemNum <= 0 Or itemNum > MAX_ITEMS Then Exit Function End If For i = 1 To MAX_INV If GetPlayerInvItemNum(index, i) = itemNum Then counter = counter + 1 End If Next GetAmountOfItem = counterEnd Function```Now you will be able to check how many of an item you have in the inventory.Example:```if GetAmountOfItem(Index, 10) >= 5 'Has the item and specific amountElse 'Doesn't have all the itemsEnd If```If you have the amount 5 or greater of the item 10, it will go to the first comment, if not it will go to the second comment. Hope this turns out helpful to someone. Enjoy. Link to comment Share on other sites More sharing options...
Scott Posted April 3, 2012 Share Posted April 3, 2012 Why not``` Dim itemamount As Long itemamount = HasItem(Index, 1) If itemamount = 0 Or itemamount < 5000 Then PlayerMsg Index, "Not enough item.", BrightRed Exit Sub End If TakeInvItem Index, 1, 5000```Replace the numbers with variables and you got what your code does with out all those loops. Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 Does TakeInvItem work with items that aren't stackable?Yeah, I believe your code would only work with currency. Correct me if I'm wrong. Link to comment Share on other sites More sharing options...
crzyone9584 Posted April 3, 2012 Share Posted April 3, 2012 It doesn't matter if its stackable or not. TakeInvItem will take the item that is passed to it no matter what. Just have to pass in the right amount of number to take of that item. Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 Ah, hmm.. But HasItem cannot check to see if you have a certain amount of an item can it? Link to comment Share on other sites More sharing options...
crzyone9584 Posted April 3, 2012 Share Posted April 3, 2012 Sure it can. orginally no. but HasItem is a basic check to see if the person has that item you want to take.Also You don't have to create an entire new sub. Just edit the current HasItem function to be like the following.```Function HasItem(ByVal index As Long, ByVal itemnum As Long, Optional ByVal long itemAmount) As Long Dim i As Long ' Check for subscript out of range If IsPlaying(index) = False Or itemnum <= 0 Or itemnum > MAX_ITEMS Then Exit Function End If For i = 1 To MAX_INV ' Check to see if the player has the item If GetPlayerInvItemNum(index, i) = itemnum Then If Item(itemnum).Type = ITEM_TYPE_CURRENCY Then HasItem = GetPlayerInvItemValue(index, i) Else If itemAmount > 0 if Player(index).Inv.Num >= itemAmount HasItem = GetPlayerInvItemValue(index, i) Else HasItem = 1 End If Exit Function End If NextEnd Function```Code will prolly not work. Been a while since i messed around with EO but you get the drift of all you have to do is have an Optional value passed in. if its not passed in it will be 0. Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 I think I see where you're going with this. I will edit HasItem and release it tomorrow. Thanks for the info on "optional" and such ;) Link to comment Share on other sites More sharing options...
Scott Posted April 3, 2012 Share Posted April 3, 2012 It already does that only need a small edit for non currency.```Function HasItem(ByVal Index As Long, ByVal itemnum As Long) As Long Dim i As Long ' Check for subscript out of range If IsPlaying(Index) = False Or itemnum <= 0 Or itemnum > MAX_ITEMS Then Exit Function End If For i = 1 To MAX_INV ' Check to see if the player has the item If GetPlayerInvItemNum(Index, i) = itemnum Then----------> If Item(itemnum).Type = ITEM_TYPE_CURRENCY Then------------> HasItem = GetPlayerInvItemValue(Index, i) Else------------> HasItem = 1 End If Exit Function End If NextEnd Function```GetPlayerInvItemValue returns the value(amount) of that item if it is currency(can be edited for others) and returns 1 for non stackable single items. Link to comment Share on other sites More sharing options...
crzyone9584 Posted April 3, 2012 Share Posted April 3, 2012 Scott, you just copied and posted the entire HasItem Function. He should do what i said and return Has item like the currency does. Link to comment Share on other sites More sharing options...
Scott Posted April 3, 2012 Share Posted April 3, 2012 I pasted it to point out the sub already checks for the amount, I pointed out the lines where it returns the value(thus re-affirming it needed no edits) which was the whole point of this tutorial than if you look how shops handle transaction you get a great example of working with stacked items(the code I posted above). Link to comment Share on other sites More sharing options...
crzyone9584 Posted April 3, 2012 Share Posted April 3, 2012 All i noticed was a few points and no explanation to what you wanted. How do you know he wants to check for a stacked item everytime. Thats why i added in the optional value. Link to comment Share on other sites More sharing options...
Scott Posted April 3, 2012 Share Posted April 3, 2012 No point in arguing with a brick wall, but point blank he was trying to check to see if a person had multiple of an item and the fact is the current function does what he wants fine. All you need to do is call HasItem, if it is greater than 1 than it is stackable(currency) if not its a single item.> How do you know he wants to check for a stacked item everytimeYou just call that block of code(below) where he needs to check for the stack why are we even editing the sub? I could see if he made a sub that checks than removed it(like I think he was trying to do) but he went around it the wrong way.You just use this(ripped from shops) throw this in a function, replace the numbers with variables bam done.``` Dim itemamount As Long itemamount = HasItem(Index, 1) If itemamount = 0 Or itemamount < 5000 Then PlayerMsg Index, "Not enough item.", BrightRed Exit Sub End If TakeInvItem Index, 1, 5000``` Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 What I'm trying to actually do is check for x of a non-stackable item. What I use this for in my game is for quests. Say you need to go grab 5 non-stackable items. The HasItem function can check if I have the item, but can not check for 5 of them in my inventory at one time.The function I made takes each item out of the inventory and counts how many it takes. If it's not enough for the quest I need, then it gives back the number of items it took. If it counts the number that I passed into the function(for ItemAmountReq), then it will return true, ending the quest. Link to comment Share on other sites More sharing options...
Baron Posted April 3, 2012 Share Posted April 3, 2012 why not just mod the hasitems function to be a simple count and loop it through each inventory slot? Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 Actually planning on doing that. I'll post it up sometime soon. Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 There we go, just edited the HasItem function to check if the third parameter is not equal to 0\. Then it will count all the specified items throughout the for loop of all the inventory spaces. If the item was counted to match the itemamount parameter, it will return 1. Link to comment Share on other sites More sharing options...
Baron Posted April 3, 2012 Share Posted April 3, 2012 Wouldn't it be more useful to return the quantity they have, not a true/false value?GetNumberOfItem(X) seems more useful than HasItems(X,5000)ie (very pseudocode-ish)var ore_count = GetNumberOfItem(Ore);if ore_count > 5 do stuff, else playermsg("you need " & (5 - ore_count) & " more ore.)also would let you do stuff likevar items_redeemed = GetNumberOfItem(Redeemable)grant experience = items_redeemed * 500xp Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 That's very true, I like that actually. Would it be a better idea to create that function rather than counting in the HasItem function? Link to comment Share on other sites More sharing options...
Baron Posted April 3, 2012 Share Posted April 3, 2012 Well maybe you seperate the two functions if HasItem has existing code references to it, otherwise I would supersede HasItem with GetNumberOfItem. Or even make the hasitem function just run the getnumberofItem function and if the quantity is >1 return true. Up to you really.ie HasITem returns a true false as its function name implies,GetNumberOfItem returns the quantity a player posesses. Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 Alright, made a new function GetAmountOfItem. It simply goes through all the inv slots and counts how many of the item are in the inventory, and returns the number it counted. Link to comment Share on other sites More sharing options...
Baron Posted April 3, 2012 Share Posted April 3, 2012 Ah good choice of description. Amount specifies it well since number could be the item index.Great work! Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 Thank you sir, and thanks for all the input :) Link to comment Share on other sites More sharing options...
crzyone9584 Posted April 3, 2012 Share Posted April 3, 2012 @scott - brick wall? there is no brick wall. its two different views. And your first post made little since. If you give a description of ripping apart one Function/Sub at least give more details. Your second post of what you ment makes more since to me because you went into more detail.On Topic - Either way you choose to do the system is fine. Adding a new function is a little bit of a waste when you can just add it to the current function. Either way its still a nice add to the HasItem function. Link to comment Share on other sites More sharing options...
sirsk8aton Posted April 3, 2012 Author Share Posted April 3, 2012 As Baron stated, the HasItem should do what it sounds like it supposed to do. Check to see if you have the item and return true/false. GetAmountOfItem clearly states what it's supposed to do and does it. Again, thanks for the input. All of you actually helped me do what I needed to do the right way. Link to comment Share on other sites More sharing options...
Scott Posted April 3, 2012 Share Posted April 3, 2012 Nice job on finishing it up, your first piece of code had so much useless looping. My whole point was why where you editing HasItem its used by other areas glad to see you got it working as you intended and made it separate. 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