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

Item that calls a Custom Script


Peaverin
 Share

Recommended Posts

Hi, I though it was already possible to call a custom script with an Item in E.Worlds, but it isn't, so there's a tutorial for those who want to do it. It is very basic but some people may need it:

1st: Both Client and Server side

>! ->In modConstants, after the last item constant, you put:
>! ```
Public Const ITEM_TYPE_CSCRIPT As Byte = 10
```
In my case is ten because the last item constant I had was 9, but you'll have to put the next to the last number. This will set a new item type.
>!  
>!  
>! ->In modTypes, in Public Type ItemRec, add this before the End Type:
>! ```
CScriptNumber As Byte
```
This will create a new property for items, that indicates the Custom Script number.
>! Note: If you want to have more than 255 Custom Scripts (I doubt that), set it As Long instead of As Byte.

2nd: Client Side

>! In Frm Editor_Item:
>! ->Create a new frame, named fraCScript. Inside this frame create a new label named lblCScript (its caption should be Custom Script: 1). Also, create a scrollbar named scrlCScript. Set the scrollbar max to 255 if you set the CScriptNumber as Byte before, or set it at more if you set it at As Long. This way, you won't be able to exced 255 and won't cause any bug. Double click the scrollbar and paste this code:
>! ```
Private Sub scrlCScript_Change()
    If EditorIndex < 1 Or EditorIndex > MAX_ITEMS Then Exit Sub

    ' If debug mode, handle error then exit out
    If App.LogMode = 1 And Options.Debug = 1 Then On Error GoTo ErrorHandler

    lblCScript.Caption = "Custom Script: " & scrlCScript.Value
    Item(EditorIndex).CScriptNumber = scrlCScript.Value
    Exit Sub

' Error handler
ErrorHandler:
    HandleError "scrlCScript_Change", "frmEditor_Item", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
End Sub
```
->Then, in Private Sub cmbType_Click() after this:
>! ```
  If (frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_RECIPE) Then
        fraRecipe.Visible = True
    Else
        fraRecipe.Visible = False
    End If
```
Add this:
>! ```
>! If (cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then
        fraCScript.Visible = True
    Else
        fraCScript.Visible = False
    End If
```
->In Public Sub ItemEditorInit() before End With, add:
>! ```
>!  'custom script
                If (frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then
            frmEditor_Item.fraCScript.Visible = True
            frmEditor_Item.scrlCScript.Value = .CScriptNumber

        Else
            frmEditor_Item.fraCScript.Visible = False
        End If
>! ```
>!   ->In Private Function generateItemsForTab. After this: 
```
>! Case ITEM_TYPE_RECIPE
            ret = populateSpecificType(tempItems, ITEM_TYPE_RECIPE)
```
Copy this:
>! ```
>! Case ITEM_TYPE_CSCRIPT
            ret = populateSpecificType(tempItems, ITEM_TYPE_CSCRIPT)
```
We're done with client now.

3rd: Server Side

Now, in Server, in Public Sub Useitem, before End Select, copy this:

```

'Custom Script
            Case ITEM_TYPE_CSCRIPT
            'get the item script number
            n = Item(ItemNum).CScriptNumber
           Call CustomScript(index, n)
           Call TakeInvSlot(index, InvNum, 1) Call SendInventoryUpdate(Index, invNum)
```

Note: If you want the item to be reusable, delete this line:

```

Call TakeInvSlot(index, InvNum, 1)
```

Using Custom Scripts

This is an example of custom scripts, in mod CustomScripts in Server:

```

Public Sub CustomScript(index As Long, caseID As Long)
Dim n As Byte
    Select Case caseID
    Case "0"
    PlayerMsg index, "You just activated custom script " & caseID & ". It works hell yea.", BrightRed
    Case "1"
    n = Random(0, 20)
    If (n < 1) Then
    Call GiveInvItem(index, 10, 1, 110, 3, True)
    PlayerMsg index, "You've obtained the Eclipse Sword!", Magenta
    ElseIf (n < 5) Then
    Call GiveInvItem(index, 3, 1, 110, 3, True)
    PlayerMsg index, "You've obtained a diamond!", White
    Else
    Call GiveInvItem(index, 1, 20, -1, 3, True)
    PlayerMsg index, "You obtain 20 gold!", Black
    End If

        Case Else
            PlayerMsg index, "You just activated custom script " & caseID & ". This script is not yet programmed.", BrightRed
    End Select
End Sub
```

So if Custom Script Number is 0, it'll say "You just activated custom script 0\. It works hell yea." And if Custom Script Number is 1, it'll give you a random item with 5% chances to obtain the Eclipse Sword, 20%chances to obtain a diamond and 75% to obtain 20 gold. Custom Scripts can be used for many things, it just depends on your imagination, so having the option to call a custom script with an item is pretty good. If you have any problem, please report it, although I might not be able to solve it if it's something dificult, to be honest i don't really know anything about vb6, I just looked at the code in order to work out how to do little edits.

Enjoy and report any bug if found!
Link to comment
Share on other sites

Add this:

```
 If (cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then
        fraCScript.Visible = True
    Else
        fraCScript.Visible = False
    End If
```

->In Public Sub ItemEditorInit() before End With, add:

```
       'custom script
                If (frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then
            frmEditor_Item.fraCScript.Visible = True
            frmEditor_Item.scrlCScript.Value = .CScriptNumber

        Else
            frmEditor_Item.fraCScript.Visible = False
        End If

```

->In Private Function generateItemsForTab. After this:

```
       Case ITEM_TYPE_RECIPE
            ret = populateSpecificType(tempItems, ITEM_TYPE_RECIPE)
```

Copy this:

```
                   Case ITEM_TYPE_CSCRIPT
            ret = populateSpecificType(tempItems, ITEM_TYPE_CSCRIPT)
```

We're done with client now.

3rd: Server Side

Now, in Server, in Public Sub Useitem, before End Select, copy this:

```
'Custom Script
            Case ITEM_TYPE_CSCRIPT
            'get the item script number
            n = Item(ItemNum).CScriptNumber
           Call CustomScript(index, n)
           Call TakeInvSlot(index, InvNum, 1)
```

Note: If you want the item to be reusable, delete this line:

```
Call TakeInvSlot(index, InvNum, 1)
```

Using Custom Scripts

This is an example of custom scripts, in mod CustomScripts in Server:

```

Public Sub CustomScript(index As Long, caseID As Long)
Dim n As Byte
    Select Case caseID
    Case "0"
    PlayerMsg index, "You just activated custom script " & caseID & ". It works hell yea.", BrightRed
    Case "1"
    n = Random(0, 20)
    If (n < 1) Then
    Call GiveInvItem(index, 10, 1, 110, 3, True)
    PlayerMsg index, "You've obtained the Eclipse Sword!", Magenta
    ElseIf (n < 5) Then
    Call GiveInvItem(index, 3, 1, 110, 3, True)
    PlayerMsg index, "You've obtained a diamond!", White
    Else
    Call GiveInvItem(index, 1, 20, -1, 3, True)
    PlayerMsg index, "You obtain 20 gold!", Black
    End If

        Case Else
            PlayerMsg index, "You just activated custom script " & caseID & ". This script is not yet programmed.", BrightRed
    End Select
End Sub
```

So if Custom Script Number is 0, it'll say "You just activated custom script 0\. It works hell yea." And if Custom Script Number is 1, it'll give you a random item with 5% chances to obtain the Eclipse Sword, 20%chances to obtain a diamond and 75% to obtain 20 gold. Custom Scripts can be used for many things, it just depends on your imagination, so having the option to call a custom script with an item is pretty good. If you have any problem, please report it, although I might not be able to solve it if it's something dificult, to be honest i don't really know anything about vb6, I just looked at the code in order to work out how to do little edits.
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...
  • 3 weeks later...
After using an item, the item stays in your inventory as a graphical bug, but if you drag it or click it it disappears.

Under this:

```
'Custom Script
Case ITEM_TYPE_CSCRIPT
'get the item script number
n = Item(ItemNum).CScriptNumber
Call CustomScript(Index, n)
Call TakeInvSlot(Index, invNum, 1)

```
Put this

```
Call SendInventoryUpdate(Index, invNum)

```
Link to comment
Share on other sites

How would i do this with spells?

I tried adding the server side code to CastSpell

but apparently CSScriptNumber gets highlighted with error "Method or Data Member not found"

I got CSScriptNumber as byte in types

in enumerations i got SPELL_TYPE_CSSCRIPT defined too
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...