Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two Handed Weapons Tutorial
#1
Hi, could someone run off to the backup forums and grab my 2 handed weapons tute.. The updated one.. Cheers.. I want to back it up before i format.. Thanks guys.. :wink:
Reply
#2
I assume you mean this one..

[code]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. Smile 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_POTIONADDHP) And (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_WEAPON) And (frmItemEditor.cmbType.ListIndex
Reply
#3
Ahh.. Cheers dude.. Thanks heaps.. Big Grin
Reply
#4
Eh, no problem. I've told you, if you need, you can have my old ID/Pass for things like this.
Reply
#5
Yeah i know, but it was for just a small things, nothing big.. Lol..
Reply
#6
You definately wrote this the hard way. Apart from the editor saving/loading you can write about 6 lines of code to do this.
Reply
#7
Really? I know i didnt take the best path possible, but i thought it was pretty clean.. Lol.. If you dont mind me asking, could you explain it more, i wouldnt mind changing my tutorial or make it faster.. Thanks dude.. :wink:
Reply
#8
in most games Data3 is unused, yay for making things already sent/recieved and unused into other things :wink:
Reply
#9
Ahh.. Right.. Of course.. Although i have a habit to name things when coding..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)