Print Page | Close Window

Two Handed Weapons

Printed From: Mirage Source
Category: Tutorials
Forum Name: Submitted Tutorials
Forum Discription: Tutorial submissions for MSE are posted here, waiting for approval
URL: http://ms.shannaracorp.com/backup-forums/forum_posts.asp?TID=50
Printed Date: 20 December 2006 at 6:02pm
Software Version: Web Wiz Forums 8.01 - http://www.webwizforums.com


Topic: Two Handed Weapons
Posted By: Sync
Subject: Two Handed Weapons
Date Posted: 07 February 2006 at 6:28pm
Originally posted by Dark Echo

Two Handed Weapons
This is basically what the name saids. I did not create a whole new item type, i just used the old item type and added an option to make weapons two handed or not, by just ticking a checkbox. So thats basically it. If you have any items, when you add this in you will have to remake all your items again, so yeah.. Also, back up your source before you add in this tutorial, just to be safe.

- Tutorial updated..
- Fixed small shield bug

Difficult: 1/5

Part 1 - Server Side
Ok, go into modTypes and find:
Type ItemRec


Add under Data3 As Integer:
TwoHanded As Byte


Alright, now go into modDatabase and find:
Sub SaveItem(ByVal ItemNum As Long)


Now add this to the end of the saving sub, but before the End Sub:
Call PutVar(FileName, "ITEM" & ItemNum, "TwoHanded", Trim(Item(ItemNum).TwoHanded))


Ok, now find:
Sub LoadItems()


And after:
Item(i).Data3 = Val(GetVar(FileName, "ITEM" & i, "Data3"))


Add:
Item(i).TwoHanded = Val(GetVar(FileName, "ITEM" & i, "TwoHanded"))


Alrighty, we're nearly done for server side. go into modHandleData and find:
If LCase(Parse(0)) = "useitem" Then


And find:
Case ITEM_TYPE_WEAPON


And make it look like this:
                 Case ITEM_TYPE_WEAPON
                     If InvNum <> GetPlayerWeaponSlot(Index) Then
                         If Item(GetPlayerInvItemNum(Index, InvNum)).TwoHanded < 1 Then
                              If Int(GetPlayerSTR(Index)) < n Then
                                   Call PlayerMsg(Index, "Your strength is to low to hold this weapon!  Required STR (" & n * 2 & ")", BrightRed)
                                   Exit Sub
                              End If
                              Call SetPlayerWeaponSlot(Index, InvNum)
                         Else
                              If GetPlayerShieldSlot(Index) = 0 Then
                                   Call SetPlayerWeaponSlot(Index, InvNum)
                                   Call SetPlayerShieldSlot(Index, InvNum)
                              Else
                                   Call PlayerMsg(Index, "You already have a shield equiped!", BrightRed)
                              End If
                         End If
                     Else
                         Call SetPlayerWeaponSlot(Index, 0)
                     End If
                     Call SendWornEquipment(Index)


Right under that, you will find the Shield sectin of that sub.. Now just change it so it looks like this one:
                 Case ITEM_TYPE_SHIELD
                     If GetPlayerShieldSlot(Index) > 0 Then
                         If GetPlayerWeaponSlot(Index) = GetPlayerShieldSlot(Index) Then
                              Call PlayerMsg(Index, "You have a two handed weapon equipped! Please unequip it before using your shield!", BrightRed)
                              Exit Sub
                         Else
                              Call PlayerMsg(Index, "You already have a shield equipped! Please unequip it before using your shield!", BrightRed)
                         End If
                     Else
                         If InvNum <> GetPlayerShieldSlot(Index) Then
                              Call SetPlayerShieldSlot(Index, InvNum)
                         Else
                              Call SetPlayerShieldSlot(Index, 0)
                         End If
                         Call SendWornEquipment(Index)
                     End If


Now find:
If LCase(Parse(0)) = "saveitem" Then


And add this to the end of the update item section:
Item(n).TwoHanded = Val(Parse(8))


So that section looks like this:
' Update the item
Item(n).Name = Parse(2)
Item(n).Pic = Val(Parse(3))
Item(n).Type = Val(Parse(4))
Item(n).Data1 = Val(Parse(5))
Item(n).Data2 = Val(Parse(6))
Item(n).Data3 = Val(Parse(7))
Item(n).TwoHanded = Val(Parse(8))


Go into modGameLogic, remember this is all server side for now.. And find:
Sub PlayerMapDropItem(ByVal Index As Long, ByVal InvNum As Long, ByVal Ammount As Long)


Now, look for:
Case ITEM_TYPE_WEAPON


And make that whole case look like this:
                 Case ITEM_TYPE_WEAPON
                     If Item(GetPlayerInvItemNum(Index, InvNum)).TwoHanded < 1 Then
                         If InvNum = GetPlayerWeaponSlot(Index) Then
                              Call SetPlayerWeaponSlot(Index, 0)
                              Call SendWornEquipment(Index)
                         End If
                         MapItem(GetPlayerMap(Index), i).Dur = GetPlayerInvItemDur(Index, InvNum)
                     Else
                         If InvNum = GetPlayerWeaponSlot(Index) And InvNum = GetPlayerShieldSlot(Index) Then
                              Call SetPlayerWeaponSlot(Index, 0)
                              Call SetPlayerShieldSlot(Index, 0)
                              Call SendWornEquipment(Index)
                         End If
                         MapItem(GetPlayerMap(Index), i).Dur = GetPlayerInvItemDur(Index, InvNum)
                     End If


Woohoo, so close, just a few more lines. :) Alrighty, go into modServerTCP and find:
Sub SendUpdateItemToAll(ByVal ItemNum As Long)


And make the packet look like this:
Packet = "UPDATEITEM" & SEP_CHAR & ItemNum & SEP_CHAR & Trim(Item(ItemNum).Name) & SEP_CHAR & Item(ItemNum).Pic & SEP_CHAR & Item(ItemNum).Type & SEP_CHAR & Item(ItemNum).Data1 & SEP_CHAR & Item(ItemNum).Data2 & SEP_CHAR & Item(ItemNum).Data3 & SEP_CHAR & Item(ItemNum).TwoHanded & SEP_CHAR & END_CHAR


Last sub, woot!! Find:
Sub SendEditItemTo(ByVal Index As Long, ByVal ItemNum As Long)


And make that last packet look like this:
Packet = "EDITITEM" & SEP_CHAR & ItemNum & SEP_CHAR & Trim(Item(ItemNum).Name) & SEP_CHAR & Item(ItemNum).Pic & SEP_CHAR & Item(ItemNum).Type & SEP_CHAR & Item(ItemNum).Data1 & SEP_CHAR & Item(ItemNum).Data2 & SEP_CHAR & Item(ItemNum).Data3 & SEP_CHAR & Item(ItemNum).TwoHanded & SEP_CHAR & END_CHAR


And thats it for the server side..

Part 2 - Client Side
Ok, go into modTypes and find:
Type ItemRec


Add under Data3 As Integer:
TwoHanded As Byte


Alright, now go into modClientTCP and find:
Public Sub SendSaveItem(ByVal ItemNum As Long)


Add this to the end of your packet:
.TwoHanded & SEP_CHAR &


If you've done this correctly, it should look like this:
Packet = "SAVEITEM" & SEP_CHAR & ItemNum & SEP_CHAR & Trim(.Name) & SEP_CHAR & .Pic & SEP_CHAR & .Type & SEP_CHAR & .Data1 & SEP_CHAR & .Data2 & SEP_CHAR & .Data3 & SEP_CHAR & .TwoHanded & SEP_CHAR & END_CHAR


You now have to add a checkbox in the equipment frame, in the items editor. Call it chkTwoHanded and your set.

Now, go into modGameLogic and find:
Public Sub ItemEditorOk()


Now at the bottom of:
If (frmItemEditor.cmbType.ListIndex >= ITEM_TYPE_POTIONADDHP) And (frmItemEditor.cmbType.ListIndex <= ITEM_TYPE_POTIONSUBSP) Then


And:
If (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_SPELL) Then


Add:
Item(EditorIndex).TwoHanded = 0


So they both should look like this:
    If (frmItemEditor.cmbType.ListIndex >= ITEM_TYPE_POTIONADDHP) And (frmItemEditor.cmbType.ListIndex <= ITEM_TYPE_POTIONSUBSP) Then
        Item(EditorIndex).Data1 = frmItemEditor.scrlVitalMod.Value
        Item(EditorIndex).Data2 = 0
        Item(EditorIndex).Data3 = 0
        Item(EditorIndex).TwoHanded = 0
    End If
   
    If (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_SPELL) Then
        Item(EditorIndex).Data1 = frmItemEditor.scrlSpell.Value
        Item(EditorIndex).Data2 = 0
        Item(EditorIndex).Data3 = 0
        Item(EditorIndex).TwoHanded = 0
    End If


Now, add at the bottom of:
If (frmItemEditor.cmbType.ListIndex >= ITEM_TYPE_WEAPON) And (frmItemEditor.cmbType.ListIndex <= ITEM_TYPE_SHIELD) Then


After:
Item(EditorIndex).Data3 = 0


Add:
Item(EditorIndex).TwoHanded = frmItemEditor.chkTwoHanded.Value


Ok, now go into modHandleData and find:
If (LCase(Parse(0)) = "updateitem") Then


Add below the update item section this:
Item(n).TwoHanded = 0


Now find:
If (LCase(Parse(0)) = "edititem") Then


And below:
Item(n).Data3 = Val(Parse(7))


Add:
Item(n).TwoHanded = Val(Parse(8))


Woot.. Done done done!! Another one of these little things people like in their games :) I just like helping out!! Now, if any of yous have realised, i did the client side first, because i thought i had already done the server side.. Well, i actually did, but forgot i deleted it.. Idiot me.. Anyway, so thats why i got so excited near the end of the server side.. :D Look forward to more tutorials like these.. Adding in simple and easy features that people want desperately in their games!! :D



Replies:
Posted By: Sync
Date Posted: 07 February 2006 at 6:28pm
If someone can verify before I approve ... please 



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums version 8.01 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info