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

Need a function or way to check item


DrNova
 Share

Recommended Posts

I plan on having "damaged" items, user can click them(scripted item) to repair them.
However, I dont want to have to make a seperate case for ever single item if I dont have to.

Is there a way to make a function to check the number of the scripted item used?
Such as

Function(num)
num= scripted item used

(scripted item sub)
Case 4
If num=this, then
Else if num=this then, ect

If that makes sence.
I COULD make them all seperate cases, but just seems like it would be more efficient to put it all into a single scripted item that can tell the item number clicked.
Link to comment
Share on other sites

Okay… I don't quite understand your request, your title is different than what you say...?
Anyway, if it's what your title is asking:
```
Function CanTake(Index, Number, Amount)
  Dim Slot

  Slot = 1

  Index = Int(Index)
  Number = Int(Number)
  Amount = Int(Amount)

  Do While Slot < 25
      If GetPlayerInvItemNum(Index, Slot) = Number Then
        If GetPlayerInvItemValue(Index, Slot) >= Amount Then
            CanTake = True
            Exit Function
        End If
      End If

      Slot = Slot + 1
  Loop

  CanTake = False
End Function
```Credits 2 Godlord. If it's not what you're asking, then… tell me. XD

> Command/Function Name: CanTake
> Parameters:
>     Index (Integer): the player index.
>     Number (Integer): the item number.
>     Amount(Integer): the amount of items.
> Description: checks if the item is available and if the quantity of that item is at least as much as the one specifed, or more than specified.
> Return Value: true if there is an item with the right amount else false (Boolean).
Link to comment
Share on other sites

I mean to be able to check the item number of the scripted item used.
I have a bunch of nearly identical scripted items, just different item numbers, and want to condense it to a single scripted item that can tell which item number the script was ran from, instead of having a bunch of nearly identical cases, same thing just different item number.

If possible
Link to comment
Share on other sites

Why the hell did you post that reply? DrNova is intelligent, and he'd know that you could script it in sadscript rather than source editing. Think before posting. And it wouldn't be a huge script that would make the server laggy, there are only about two scripts that are of that magnitude. I doubt this would be one. Think before posting.

To answer your request: I think it's possible. I'll get back to you on that. I'll try scripting it now.

[edit]
Hmm… I know it's possible. I just can't think right now, I'm kind of tired. I hope someone can help you with it.
Also, try using
```
GetPlayerInvItemValue(Index, Slot)
```to make the script. That's what I'm thinking along the lines of right now.
Link to comment
Share on other sites

The problem I havent been able to get past however, is how to tell the number of the item clicked, or even its slot.
I know how to find item slots and such, but how to find the number of the item using that case.  For example, I have 5 items using the same base script in a case, how can I get it to know which item activated the script.

I'm beginning to think this cant be done with current scripting commands,  I cant see any way to identify the item number that was used to call the script, except by having multiple case's for each different item..
Link to comment
Share on other sites

I'm conflicting with myself whether this is possible or not. Now that I think about it, it would be way easier just hardcoding it in. However, I'm pretty sure it can be sadscripted.
Link to comment
Share on other sites

@dg1423:

> nah, you'd have to do a small source edit to include the item number in the scripteditem sub call. it's a very easy modification, and I think it'll be included in 2.8.

If you've not already thought about it, adding the slot parameter would also be beneficial.
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...