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

Adding New Item Properties


balliztik1
 Share

Recommended Posts

I originally had a tutorial on how to add MAGI as a requirement for an item. This will take the ideas there and apply them to any and all item edits you may want to do.

NOTE: If you can grasp the concepts here, you can extend them into NPC editing, Map editing, Player editing and more. Source editing is all about applying concepts to situations.

**Server Side**
1\. First thing's first: we need to make up the new item property. For the example, I'll use MagiReq, just because it's been requested so many times (and I lost my tutorial, so this will serve 2 purposes). The first thing we'll need to do is locate the type. All the type declarations are in modTypes, so head there and look for "Type ItemRec". You'll see a list of item attributes that you should recognize. It doesn't matter where you put the new property, as long as it's within the type boundaries, but add this somewhere:

```
MagiReq as Long
```
NOTE: IMPORTANT!!! Adding MagiReq here assigns a new property to items. If you remember, in the "Bridging the Gap" tutorial I introduced properties. Now, you can use "Item(Num).MagiReq" to find the new property of any item. Whenever you add a property to an object like that, you can use it in the same way as above.

2\. Now that we have the property established, we need to assign it value in three places.

Find "Sub ClearItems" in modTypes. You'll see all the properties of an item being set to their lowest values. We'll want MagiReq to become 0 when clearing the item, so throw this line in the sub:

```
Item(index).MagiReq = 0
```
Again, you'll notice that as you type, MagiReq popped up as a property of Item. Now that we've established that, we can change the editing process. Find " 'update the item " under " Case "saveitem" " in modServerTCP. Again, you'll find a list of properties. You have 2 options here. You can place MagiReq as Parse(26) at the end, or as Parse(11) with all the other requirements. I advise to use 26 unless you want to alter a lot of subs in order to move each property up by 1\. So, add this:

```
Item(n).MagiReq = Val(Parse(26))
```
You'll notice some send commands under the properties. Recalling the previous tutorial, we must track their source. I'll save you the trouble and tell you to go to "Sub SendUpdateItemToAll" in modServerTCP. There are three consecutive subs there that you will need to edit. In each, find the line:

```
Packet = Packet & SEP_CHAR & END_CHAR
```
and change it to:

```
Packet = Packet & SEP_CHAR & Item(itemnum).MagiReq & SEP_CHAR & END_CHAR
```
Make sure to do that all three times.

3\. Last, we need to make the number actually do something. Find this line:

```
Dim n1 As Long, n2 As Long, n3 As Long, n4 As Long, n5 As Long
```
And change it to this:

```
Dim n1 As Long, n2 As Long, n3 As Long, n4 As Long, n5 As Long, n6 as Long
```
Under that, add this line:

```
            n6 = Item(GetPlayerInvItemNum(index, InvNum)).MagiReq
```
Further under there, you will find several instances of the following that you will need to change (one for each item type that will need MagiReq). Find these lines:

```
                        ElseIf Int(GetPlayerSPEED(index)) < n3 Then
                            Call PlayerMsg(index, "Your speed is too low to equip this item!  Required Speed (" & n3 & ")", BrightRed)
                            Exit Sub
                        End If
```
Change each of them to look like this:

```
                        ElseIf Int(GetPlayerSPEED(index)) < n3 Then
                            Call PlayerMsg(index, "Your speed is too low to equip this item!  Required Speed (" & n3 & ")", BrightRed)
                            Exit Sub
                        ElseIf Int(GetPlayerMagi(index)) < n6 Then
                            Call PlayerMsg(index, "Your magic is too low to equip this item!  Required magic (" & n6 & ")", BrightRed)
                            Exit Sub
End If
```
I believe there are 7 places where you have to change that.

That should be all for the server side.

**Client Side**
1\. Follow steps 1 and 2 (up to Sub ClearItem) from the server section, except do it this time on the client side.

2\. Now, we have to alter the item editor. Open frmItemEditor in Object view. Move stuff around in the item editor so you have room for a new HScrollBar. Name it scrlMagiReq. Add two labels above it, like the other bars. I named mine Label32 and Label33 to go along with the current theme of things. Double click the new scroll bar and make this sub in the form's code:

```
Private Sub scrlMagiReq_Change()
Label33.Caption = scrlMagiReq.Value
End Sub
```
3\. Now, we need to change the code that sets the actual values in two places:

Find "Sub ItemEditorInit" in modGameLogic. Find this line:

```
        frmItemEditor.scrlSpeedReq.Value = Item(EditorIndex).SpeedReq
```
And add this right under it:

```
        frmItemEditor.scrlMagiReq.Value = Item(EditorIndex).MagiReq
```
That changed when the editor starts. Scroll down to the next sub, "ItemEditorOk" to change the saving. Do the same as before, basically, except backwards. Find this line:

```
          Item(EditorIndex).SpeedReq = frmItemEditor.scrlSpeedReq.Value
```
And add this right under it:

```
        Item(EditorIndex).MagiReq = frmItemEditor.scrlMagiReq.Value
```
Scroll down a bit, and find this line several times:

```
        Item(EditorIndex).SpeedReq = 0
```
Underneath each instance of this line, add this:

```
        Item(EditorIndex).MagiReq = 0
```
That will assign the values whenever you edit the item now.

4\. The last thing is to make sure the server and client are communicating properly with the new data. Find "Sub SendSaveItem" in modClientTCP. Change the second to last line to this, like from above:

```
    Packet = Packet & SEP_CHAR & Item(ItemNum).MagiReq & SEP_CHAR & END_CHAR
```
Now that it sends the right value, we need it to read the right value. Find  " 'Update the Item " in "Sub HandleData" of modClientTCP. Add this line with the rest of them:

```
        Item(n).MagiReq = Val(Parse(26))
```

And there you have it. Hopefully you've not just idly followed these steps, but rather realized what each step did to help complete the whole code. The order in which we did things can be used to make other edits to items, or even to other types. It's just a matter of conceptual learning, like I said previously.
Link to comment
Share on other sites

Oh jeez. Sorry for the double post, but I just realized a huge error in this tutorial. I say "three places" but only list two. I left out an entire section of the tutorial! O.o

It's the part where you have to set the property equal to 0 upon item creation. I no longer have the source, so I'll have to dig a bit, but I should have this fixed soon.
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...