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

Code problem


Zopto
 Share

Recommended Posts

me and mortal  trying to make  when player got lvl 15 he evolue in other sprite but for that it need to have itam in inventory

```
If Player(Index).Char(TempPlayer(Index).CurChar).HasItem = 5 Then
TakeInvItem Index, 5
Else
Addtext "You need an Stone.", BrightRed
EndIf
```
i geting error on HasItam any one cnow how to fix
Link to comment
Share on other sites

Thats not really the correct way to use HasItem I believe, the correct method would be to do something like this (this is complete pseudo code)

```

CheckItem = HasItem(index, ItemNum)

if CheckItem > 0 Then
TakeInvItem Index, 5
Else
Addtext "You need an Stone.", BrightRed
End If

```
Something like that should do the trick.
Link to comment
Share on other sites

@zerohero:

> Thats not really the correct way to use HasItem I believe, the correct method would be to do something like this (this is complete pseudo code)
>
> ```
>
> CheckItem = HasItem(index, ItemNum)
>
> if CheckItem > 0 Then
> TakeInvItem Index, 5
> Else
> Addtext "You need an Stone.", BrightRed
> End If
>
> ```
> Something like that should do the trick.

ERROR On chekitam variable not defined
Link to comment
Share on other sites

@Zopto:

> ahh yess dim chekitam as long  but now i getting  this error on TakeInvItem(argument not optional)

Hmm your original paremetres for the **TakeInvItem** is incorrect

It should be more like this -

```
TakeInvItem index, itemname, Amount
```
So in your case it would be

```
TakeInvItem index, CheckItem, 1
```
So your final code should work now -

```
CheckItem = HasItem(index, ItemNum)

if CheckItem > 0 Then
TakeInvItem index, CheckItem, 1
Else
Addtext "You need an Stone.", BrightRed
End If
```
Link to comment
Share on other sites

but it dont take itam from inventory  also it blocking evolution comand

here is my code see if you can fix it tnx

```
Public Sub CustomScript(Index As Long, caseID As Long)
Dim itemnum As Long
Dim CheckItem As Long
CheckItem = HasItem(Index, itemnum)
    Select Case caseID
    Case 1
  If Player(Index).Char(TempPlayer(Index).CurChar).Sprite = 1 Then
If Player(Index).Char(TempPlayer(Index).CurChar).Level >= 5 Then
If CheckItem > 5 Then
Player(Index).Char(TempPlayer(Index).CurChar).Sprite = 2
TakeInvItem Index, CheckItem, 5
Call SetPlayerPOINTS(Index, GetPlayerPOINTS(Index) + 15)
Call SendPlayerData(Index)
End If
Else
End If
Else
End If
      Case Else
            PlayerMsg Index, "You just activated custom script " & caseID & ". This script is not yet programmed.", BrightRed

    End Select
End Sub
```
Link to comment
Share on other sites

```
Public Sub CustomScript(Index As Long, caseID As Long)
Dim CheckItem As Long

CheckItem = HasItem(Index, 5)

    Select Case caseID
    Case 1

        If Player(Index).Char(TempPlayer(Index).CurChar).Sprite = 1 And Player(Index).Char(TempPlayer(Index).CurChar).Level >= 5 And CheckItem > 0 Then
        Player(Index).Char(TempPlayer(Index).CurChar).Sprite = 2
        TakeInvItem Index, CheckItem, 1
        Call SetPlayerPOINTS(Index, GetPlayerPOINTS(Index) + 15)
        Call SendPlayerData(Index)
        End If

    Case Else

    PlayerMsg Index, "You just activated custom script " & caseID & ". This script is not yet programmed.", BrightRed

End Select

End Sub
```
Link to comment
Share on other sites

@zerohero:

> ```
> Public Sub CustomScript(Index As Long, caseID As Long)
> Dim CheckItem As Long
>
> CheckItem = HasItem(Index, 5)
>
>     Select Case caseID
>     Case 1
>    
>         If Player(Index).Char(TempPlayer(Index).CurChar).Sprite = 1 And Player(Index).Char(TempPlayer(Index).CurChar).Level >= 5 And CheckItem > 0 Then
>         Player(Index).Char(TempPlayer(Index).CurChar).Sprite = 2
>         TakeInvItem Index, CheckItem, 1
>         Call SetPlayerPOINTS(Index, GetPlayerPOINTS(Index) + 15)
>         Call SendPlayerData(Index)
>         End If
>
>     Case Else
>    
>     PlayerMsg Index, "You just activated custom script " & caseID & ". This script is not yet programmed.", BrightRed
>
> End Select
>
> End Sub
> ```

WORKS TNX!!!!!!  :star: :star: :star: :star: :star:
Link to comment
Share on other sites

Haha I knew we would get there in the end. Your code was a bit bloated and some of you logic was off, always be sure you understand the paremetres of a sub or function before calling them or you will just create errors that pile up.

Please take a look at what I changed from your original code for future reference.

*edit*

Oh sorry change
```

TakeInvItem Index, CheckItem, 1
```
to

```
TakeInvItem Index, 5, 1
```
Have a nice day.
Link to comment
Share on other sites

@zerohero:

> Haha I knew we would get there in the end. Your code was a bit bloated and some of you logic was off, always be sure you understand the paremetres of a sub or function before calling them or you will just create errors that pile up.
>
> Please take a look at what I changed from your original code for future reference.
>
> *edit*
>
> Oh sorry change
> ```
>
> TakeInvItem Index, CheckItem, 1
> ```
> to
>
> ```
> TakeInvItem Index, 5, 1
> ```
> Have a nice day.

hehe tnx alot man !!!!works perfectly!
tnx tnx!  :bstar: :bstar: :star: :bstar: :star:
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...