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

[Resolved] Get Item amount


Nifflr
 Share

Recommended Posts

Hi there, so I'm new to editing the source code and I'm trying to teach myself – but I've ran into a bit of difficulty and perhaps someone could be of assistance. My problem seems rather simple but I'm stuck.

What is the command to get the amount of a specific item that a player has?

For example I want to know how many of item 2 (a currency) the player has and save it as a variable.

Thanks for reading. Any help would be greatly appreciated.
Link to comment
Share on other sites

Well, first off you'd need to figure out which slot the currency is in, after which you can use the **.value** variable to retrieve the value of items stacked in that slot.

If this doesn't help I'll write something up, but I figured I'd give you a hint you can fiddle with before flat-out writing the code in response.
Link to comment
Share on other sites

```
Public Function GetPlayerItemAmount(Byval Index as Long, Byval ItemNum as Long) as Long

dim TempSlot as long

' Check for subscript out of range.

If Index <= 0 or Index > MAX_PLAYERS then exit sub

If ItemNum <= 0 or ItemNum > MAX_ITEMS then exit sub

tempslot = FindItem(Index, ItemNum)

if tempslot <> 0 then

GetPlayerItemAmount = GetPlayerInvItemValue(Index, Tempslot)

end if

End Function
```

I wrote that real quick from the top of my head. May not work, but don't have VB6 to check right now.
Link to comment
Share on other sites

Okay, I'm looking at this but I really don't understand it. How do I specify that I want the value of item number two? Would I change

```

tempslot = FindItem(Index, ItemNum)

```

to

```

tempslot = FindItem(Index, 2)

```

And how would I save this value and refer to it elsewhere?
Link to comment
Share on other sites

Okay, so where would I put that function that you wrote? Would it perhaps be placed in Game Logic – or would it need to go in the same module that I'm using:```
ItemVariableHere = GetPlayerItemAmount(Index, 2)
```

I'm sorry, I really have very little idea what I'm doing. I'm quite new to doing source edits.
Link to comment
Share on other sites

Depends on what you're trying to do. All my function does, is simply create a new command for you to use(To put it very simple). If you copy it in modPlayer at the bottom, you can call it from everywhere in your source and use it whereever you need it.
Link to comment
Share on other sites

Uh… possibly because I have no idea what I'm doing.

Let me elaborate on what I'm trying to do. I want a currency system with three types of coins: knuts, sickles and galleons. Each are worth different amounts: 1, 17, and 493 respectively. But on the GUI where it displays the amount of gold you have I want to display the players wealth all in knuts so it is easy to see just how much money they have.

I tried to accomplish this by changing this:

```

' Check if it's gold, and update the label

If GetPlayerInvItemNum(MyIndex, i) = 1 Then '1 = gold ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

frmMain.lblGold.Caption = Format$(Amount, "#,###,###,###") & "g"

```

to this:

```

' Get number of sickles and galleons

Sickles = GetPlayerItemAmount(Index, 2) * 17

Galleons = GetPlayerItemAmount(Index, 3) * 493

' Check if it's gold, and update the label

If GetPlayerInvItemNum(MyIndex, i) = 1 Then '1 = gold ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

frmMain.lblGold.Caption = Format$(Amount + Sickles + Galleons, "#,###,###,###") & "knuts"

```
Link to comment
Share on other sites

There should be a function(Or some code anyway, I mean Amount is defined somewhere) to get amounts client-side already, and it's MyIndex for the player's index on the client. :] I can't really check or write it at the moment, it's 1am and I'm nowhere near my copy of VB6 :[
Link to comment
Share on other sites

Okay, well thank you so much for all the help you have given me. I'll see if maybe I can figure the rest out on my own. Or else hope for someone who has VB6 to come along.

Edit: Oh! I think I got it. ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png)

```

' Get number of sickles and galleons

Sickles = GetPlayerInvItemValue(MyIndex, 2) * 17

Galleons = GetPlayerInvItemValue(MyIndex, 3) * 493

' Check if it's gold, and update the label

If GetPlayerInvItemNum(MyIndex, i) = 1 Then '1 = gold ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

frmMain.lblGold.Caption = Format$(Amount + Sickles + Galleons, "#,###,###,###") & "knuts"

```

Again, thanks for your help, Gumball. I do feel like I've learned something.
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...