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

[EO] [Custom Item/NPC/Spell Types]


The New World
 Share

Recommended Posts

**[Custom Item/NPC/Spell Types]**

**Summary**

* * *

This tutorial will guide you on your way to making scriptable types in your Eclipse Origins source code. What does this mean exactly? Well lets think about it, you have your Healing items, combatant items .. well what if what's provided isn't enough? What if I want an item to reset my stats, like a potion? Do I want to code in that functionality and make a brand new item type for every new special item I think of? Bloody hell no.

So what's the next best thing? Having one 100% customizable item type. A custom item type if I may. You will program the functionality for each custom item, and then assign the item a number to refer to. This number will refer to a case we will be coding. Within this case is a specific instruction for that item.

Now lets carry on, shall we?

**Code**

* * *

Within this guide, we will first venture forth to the _Client_ project, or as it is so brilliantly referred to as, the _Client-side_. From here we will be navigating from module to module in alphabetical order as necessary. Note that this tutorial is for learning, not for copying and pasting, you will also go no where with this tutorial without learning the capabilities of the engine at some point.

**Trivia:** Modules are used in VB6 simply as means of organization. They keep your functions and sub-routines out of the way of your forms, and allow you to re-use these methods throughout your project without having to re-create their functionality each time you wish to use them.

Now we begin first by navigating to the module: _modConstants_. Here we will place the following code:

```
Public Const MAX_CUSTOMS As Long = 3
```
This creates a new constant in our project that we may use in loops and the like. But in our case it will obviously stand for the maximum amount of custom types we'll be using. For convenience sake, you may wish to place a marker like the following:

```
' Custom Types System
```
Above all the code we implement into your source during this tutorial. Why? Well if something malfunctions, or if you wish to remove it later on, you can make sure you got it all, and find it much more quickly by searching for this marker with the Ctrl+F search mechanism in your IDE.

**Trivia:** In your Visual Basic 6.0 IDE, you can use the Ctrl+F search mechanism to replace bits of code, whether it be a copy & paste error, or anything else of the like. If you cannot find this replace functionality in the default Ctrl+F manner, you can use Ctrl+H to jump right to it.

Now, also in the current module: _modConstants_, we will add the following code, if you're following the project standards then you'll add it beneath your last _ITEM_TYPE__ constant:

```
Public Const ITEM_TYPE_CUSTOM As Byte = 9
```
You may wish to replace the numeral 9 with the number that follows your last item type constant. Now we are adding this constant to represent a new type of item. Why? Well we're doing this to follow the current working on things. For instance, in the _UseItem_ sub in the Server project, we depict what type of item we're working with, and carry on as follows.

Now following the same logic as said above, please implement the following code:

```
Public Const NPC_BEHAVIOUR_CUSTOM As Byte = 6
```
Once again, replace the number 6 with the number that follows your last npc type constant.

Now, one last time I promise, use the logic as you have been to implement this code:

```
Public Const SPELL_TYPE_CUSTOM As Byte = 5
```
Great, now one of the boring parts is over and done with. We've set up our constants to be used in accordance with the rest of the system. Now we will move on to editing the Item/NPC/Spell UDTs to allow for a custom member to be added onto them.

**Trivia:** A UDT, or User-Defined Type, can act as a type of custom, or extended type of variable. Throughout the source you'll see this used a countless amount of times. The Player(Index) itself is an array of UDTs. With a UDT you can create and set other variables within it, to allow for, as I said, a more extended sort of variable.

Now to actually edit these UDTs we will need to navigate our way to the module: _modTypes_. I remind you, we are editing the _Client-side_. Now within this module we will be adding a new variable to the Item/NPC/Spell UDTs for us to edit. This variable will be called _Custom_, quite original, eh? This variable will be used to store the custom ID we wish to be used with the Item, NPC, or Spell. This ID will access the specifically identified (iseewutudidthar) custom procedure.

Within the Item UDT, on a vanilla copy of Eclipse Origins, you should see the following:

```
    name As String * NAME_LENGTH
    Desc As String * 255
    Sound As String * NAME_LENGTH

    Pic As Long
    Type As Byte
    Data1 As Long
    Data2 As Long
    Data3 As Long
    ClassReq As Long
    AccessReq As Long
    LevelReq As Long
    Mastery As Byte
    Price As Long
    Add_Stat(1 To Stats.Stat_Count - 1) As Byte
    Rarity As Byte
    Speed As Long
    Handed As Long
    BindType As Byte
    Stat_Req(1 To Stats.Stat_Count - 1) As Byte
    Animation As Long
    Paperdoll As Long

    AddHP As Long
    AddMP As Long
    AddEXP As Long
    CastSpell As Long
    instaCast As Byte

```
These are all the variables within the Item UDT by default. Now these variables, in this order, are what is stored within each and every Item file. So to avoid corrupting the files we have now, we will be adding our new variable to the bottom of the UDT, so when the item is saved, the new member will be added to the bottom of the file, not changing the order of things as they are now.

The logic behind this is; when the data is read, it can be represented as follows:

```
1
4
5
3
2
4
5
6

```
Now these may just look like random numbers, but they are values. Now the server is actively reading these values in this order when a file is processed or saved, or whatever the case may be, and assigning them to the variable they belong to in a parallel order, as seen in the item UDT.

Suppose we were to throw a random 9 in there?

```
1
4
5
9 ' <---- /troll
3
2
4
5
6

```
Well now the server will read whatever the fourth variable is, and will assign it the 9 instead of the 3\. Well suppose it wasn't a 9 we threw in, but a word, well the fourth variable was expecting a numeric value, not a string, so there we went and corrupted the file by throwing that 9 in there. But suppose we had added the 9 to the bottom of the file? Well then it would've read all the normal variables and set their values as it had been before, then saw, oh hey, theres a new variable at the bottom, we'll assign it's value you to. Then Mr. 9 (That dog!) and Ms. Value will be happily married inside Item#.dat.

So to add our new variable _Custom_ to the UDT, we will do as Mr. 9 did and add it to the bottom as follows.

```
    name As String * NAME_LENGTH
    Desc As String * 255
    Sound As String * NAME_LENGTH

    Pic As Long
    Type As Byte
    Data1 As Long
    Data2 As Long
    Data3 As Long
    ClassReq As Long
    AccessReq As Long
    LevelReq As Long
    Mastery As Byte
    Price As Long
    Add_Stat(1 To Stats.Stat_Count - 1) As Byte
    Rarity As Byte
    Speed As Long
    Handed As Long
    BindType As Byte
    Stat_Req(1 To Stats.Stat_Count - 1) As Byte
    Animation As Long
    Paperdoll As Long

    AddHP As Long
    AddMP As Long
    AddEXP As Long
    CastSpell As Long
    instaCast As Byte

    Custom As Long

```
Now our new variable has been added to the UDT safe and sound. Now you will perform this same task to the NPC, and Spell UDT by adding the following code to the bottom of them:

```
Custom As Long
```
**Ey, I'll finish this tutorial later, this should be more than enough to teach you something new.**
Link to comment
Share on other sites

  • 3 weeks later...
  • 5 weeks later...
  • 1 month later...
  • 4 weeks later...

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...