Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding Weight To An Item
#1
The feature of adding weight to your items was brought on by James and John's Fabulatra. I figured why not add it. But, as it turns out, since I'm still new, it took me awhile to get it done! Currently all it does is check to see when to add or subtract from the player's weight. Whenever you get/give an item from the ground/shop, it should update your current weight and tell you when you are carrying too much. I leave it up to anyone who wants to use to decide what happens when you are carrying too much weight. Without further ado, let's begin.

Difficulty 3/5 – Comprehension (I tried to not make it a C + P, but I fail at making things hard ^_^)

Client Side

Start off in ModTypes.

Add this into ItemRec, at the bottom
Code:
Weight As Double

Inside PlayerRec, just under the inventory category, add this:
Code:
CurWeight As Long
MaxWeight As Long

Now go into ModGameLogic.
Add the following functions/subs somewhere in there (preferably at the bottom):
Code:
Function GetPlayerCurWeight(ByVal Index As Long) As Double
    GetPlayerCurWeight = Player(Index).CurWeight
End Function

Sub SetPlayerCurWeight(ByVal Index As Long, ByVal Modifier As Double)
    Player(Index).CurWeight = Modifier
End Sub

Function GetPlayerMaxWeight(ByVal Index As Long) As Long
    GetPlayerMaxWeight = Player(Index).MaxWeight
End Function


Sub SetPlayerMaxWeight(ByVal Index As Long, ByVal Modifier As Long)
    Player(Index).MaxWeight = Modifier
End Sub

Now, find the sub “ItemEditorInit” without the quotes of course.
Add this in before the first if statement:
Code:
frmItemEditor.txtWeight.Text = Item(EditorIndex).Weight

Now find the sub “ItemEditorOK”.
Add this before the first if statement:
Code:
Item(EditorIndex).Weight = frmItemEditor.txtWeight.Text

Now find the sub “ClearPlayer”
Add this line right before the armor statements (after the inventory clear):
Code:
Player(Index).CurWeight = 0
    Player(Index).MaxWeight = 0

Now find the sub “ClearItem”.
Add this line at the end:
Code:
Item(Index).Weight = 0

Moving on to ModClientTCP
Find the sub “SendSaveItem”.
Inside the packet part, remove the END_CHAR and add this:
Code:
& .Weight & END_CHAR

Go to ModHandleData
Find the “Edit item packet”
Add this at the end of the “ 'Update the Item” block of code
Code:
Item(n).Weight = Val(Parse(8))

Find the “Update item packet”
Add this right before it says exit sub
Code:
Item(n).Weight = Val(Parse(5))

Now, go into frmItemEditor
Add a text box and a label.
Text Box.Name = txtWeight
Label.Name = lblWeight
Lablel.Caption = Weight

That is all you have to do client side, now onto...

Server Side

Start off in ModTypes again
Add the same variables as you did in the Client

Go to ModGameLogic and add these in there
Code:
Function GetPlayerCurWeight(ByVal Index As Long) As Double
    GetPlayerCurWeight = Player(Index).Char(Player(Index).CharNum).CurWeight
End Function

Sub SetPlayerCurWeight(ByVal Index As Long, ByVal Modifier As Double)
    Player(Index).Char(Player(Index).CharNum).CurWeight = Modifier
End Sub

Function GetPlayerMaxWeight(ByVal Index As Long) As Long
    GetPlayerMaxWeight = Player(Index).Char(Player(Index).CharNum).MaxWeight
End Function

Sub SetPlayerMaxWeight(ByVal Index As Long, ByVal Modifier As Long)
    Player(Index).Char(Player(Index).CharNum).MaxWeight = Modifier
End Sub

Now find the sub “TakeItem”.
Add the top of the sub add a boolean called curtake.
Find “ ' Is what we are trying to take away more then what they have? If so just set it to zero” and replace that and the lines below it (until “ ' Check to see if its any sort of ArmorSlot/WeaponSlot”) with this:
Code:
' Is what we are trying to take away more then what they have?  If so just set it to zero
                If ItemVal >= GetPlayerInvItemValue(Index, i) Then
                    TakeItem = True
                    takecur = True
                Else
                    Call SetPlayerInvItemValue(Index, i, GetPlayerInvItemValue(Index, i) - ItemVal)
                    Call SendInventoryUpdate(Index, i)
                End If
            Else
                takecur = False

Find the sub “GiveItem”.
Add this before the SendInventoryUpdate
Code:
Call SetPlayerCurWeight(Index, (GetPlayerCurWeight(Index) + (Item(GetPlayerInvItemNum(Index, i)).Weight * GetPlayerInvItemValue(Index, i))))
        If GetPlayerCurWeight(Index) > GetPlayerMaxWeight(Index) Then Call PlayerMsg(Index, "You are overencumbered!", White)

Find the Sub “PlayerMapGetItem”.
Replace the if statement
Code:
If n  0
with:
Code:
If n  0 Then
                    ' Set item in players inventor
                    Call SetPlayerInvItemNum(Index, n, MapItem(MapNum, i).Num)
                    If Item(GetPlayerInvItemNum(Index, n)).Type = ITEM_TYPE_CURRENCY Then
                        Call SetPlayerInvItemValue(Index, n, GetPlayerInvItemValue(Index, n) + MapItem(MapNum, i).Value)
                        Msg = "You picked up " & MapItem(MapNum, i).Value & " " & Trim(Item(GetPlayerInvItemNum(Index, n)).Name) & "."
                        Call SetPlayerCurWeight(Index, (GetPlayerCurWeight(Index) + (Item(GetPlayerInvItemNum(Index, n)).Weight * GetPlayerInvItemValue(Index, n))))
                    Else
                        Call SetPlayerInvItemValue(Index, n, 0)
                        Msg = "You picked up a " & Trim(Item(GetPlayerInvItemNum(Index, n)).Name) & "."
                        Call SetPlayerCurWeight(Index, (GetPlayerCurWeight(Index) + (Item(GetPlayerInvItemNum(Index, n)).Weight)))
                    End If
                    Call SetPlayerInvItemDur(Index, n, MapItem(MapNum, i).Dur)
                        
                    ' Erase item from the map
                    MapItem(MapNum, i).Num = 0
                    MapItem(MapNum, i).Value = 0
                    MapItem(MapNum, i).Dur = 0
                    MapItem(MapNum, i).x = 0
                    MapItem(MapNum, i).y = 0
                                            
                    Call SendInventoryUpdate(Index, n)
                    Call SpawnItemSlot(i, 0, 0, 0, GetPlayerMap(Index), GetPlayerX(Index), GetPlayerY(Index))
                    Call PlayerMsg(Index, Msg, Yellow)
                    If GetPlayerCurWeight(Index) > GetPlayerMaxWeight(Index) Then Call PlayerMsg(Index, "You are overencumbered!", White)
                    Exit Sub
                Else
                    Call PlayerMsg(Index, "Your inventory is full.", BrightRed)
                    Exit Sub
                End If

Find the Sub “PlayerDropMapItem”.
Replace the if statement
Code:
If Item(GetPlayerInvItemNum(Index, InvNum)).Type = ITEM_TYPE_CURRENCY Then
with:
[code]If Item(GetPlayerInvItemNum(Index, InvNum)).Type = ITEM_TYPE_CURRENCY Then
' Check if its more then they have and if so drop it all
If Ammount >= GetPlayerInvItemValue(Index, InvNum) Then
MapItem(GetPlayerMap(Index), i).Value = GetPlayerInvItemValue(Index, InvNum)
Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " drops " & GetPlayerInvItemValue(Index, InvNum) & " " & Trim(Item(GetPlayerInvItemNum(Index, InvNum)).Name) & ".", Yellow)
Call SetPlayerInvItemNum(Index, InvNum, 0)
Call SetPlayerInvItemValue(Index, InvNum, 0)
Call SetPlayerInvItemDur(Index, InvNum, 0)
Else
MapItem(GetPlayerMap(Index), i).Value = Ammount
Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " drops " & Ammount & " " & Trim(Item(GetPlayerInvItemNum(Index, InvNum)).Name) & ".", Yellow)
Call SetPlayerInvItemValue(Index, InvNum, GetPlayerInvItemValue(Index, InvNum) - Ammount)
End If
Call SetPlayerCurWeight(Index, (GetPlayerCurWeight(Index) - (Item(GetPlayerInvItemNum(Index, InvNum)).Weight * GetPlayerInvItemValue(Index, InvNum))))
Else
' Its not a currency object so this is easy
MapItem(GetPlayerMap(Index), i).Value = 0
If Item(GetPlayerInvItemNum(Index, InvNum)).Type >= ITEM_TYPE_WEAPON And Item(GetPlayerInvItemNum(Index, InvNum)).Type
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)