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 SideStart 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
ModClientTCPFind the sub “SendSaveItem”.
Inside the packet part, remove the END_CHAR and add this:
Code:
& .Weight & END_CHAR
Go to
ModHandleDataFind 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
frmItemEditorAdd 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 SideStart 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 <= ITEM_TYPE_SHIELD Then
Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " drops a " & Trim(Item(GetPlayerInvItemNum(Index, InvNum)).Name) & " " & GetPlayerInvItemDur(Index, InvNum) & "/" & Item(GetPlayerInvItemNum(Index, InvNum)).Data1 & ".", Yellow)
Else
Call MapMsg(GetPlayerMap(Index), GetPlayerName(Index) & " drops a " & Trim(Item(GetPlayerInvItemNum(Index, InvNum)).Name) & ".", Yellow)
End If
Call SetPlayerCurWeight(Index, (GetPlayerCurWeight(Index) - (Item(GetPlayerInvItemNum(Index, InvNum)).Weight)))
Call SetPlayerInvItemNum(Index, InvNum, 0)
Call SetPlayerInvItemValue(Index, InvNum, 0)
Call SetPlayerInvItemDur(Index, InvNum, 0)
End If
Now, make your way over to
modHandleDataFind the “Save item packet”
At the end of the “ 'Update the item” block, add this:
Code:
Item(n).Weight = Val(Parse(8))
Next up is
modDatabaseFind the Sub “Saveitem”.
Add this at the end of sub
Code:
Call PutVar(FileName, "ITEM" & ItemNum, "Weight", Trim(Item(ItemNum).Weight))
Find the Sub “Loaditems”.
Add this before the Do Events code:
Code:
Item(i).Weight = Val(GetVar(FileName, "ITEM" & i, "Weight"))
Find the Sub “Addchar”.
After
Code:
Player(Index).Char(CharNum).Map = START_MAP
Player(Index).Char(CharNum).x = START_X
Player(Index).Char(CharNum).y = START_Y
Add this:
Code:
Player(Index).Char(CharNum).CurWeight = 0
Player(Index).Char(CharNum).MaxWeight = 4 * (Class(ClassNum).STR + Class(ClassNum).DEF)
If you have your people start off with items, then edit the first line. Change the second line to the formula for the max weight that the character can carry.
Find the Sub “SavePlayer.
Add this is before the save spells code:
Code:
Call PutVar(FileName, "CHAR" & i, "CurWeight", STR(Player(Index).Char(i).CurWeight))
Call PutVar(FileName, "CHAR" & i, "MaxWeight", STR(Player(Index).Char(i).MaxWeight)
Find the Sub “LoadPlayer”
Add this in before the load spells code:
Code:
Player(Index).Char(i).CurWeight = Val(GetVar(FileName, "CHAR" & i, "CurWeight"))
Player(Index).Char(i).MaxWeight = Val(GetVar(FileName, "CHAR" & i, "MaxWeight"))
Now for
modServerTCPreplace the three subs “SendUpdateItemToAll”, “SendUpdateItemTo”, and “SendEditItemTo” with the following code:
Code:
Sub SendUpdateItemToAll(ByVal ItemNum As Long)
Dim Packet As String
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).Weight & END_CHAR
Call SendDataToAll(Packet)
End Sub
Sub SendUpdateItemTo(ByVal Index As Long, ByVal ItemNum As Long)
Dim Packet As String
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).Weight & END_CHAR
Call SendDataTo(Index, Packet)
End Sub
Sub SendEditItemTo(ByVal Index As Long, ByVal ItemNum As Long)
Dim Packet As String
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).Weight & END_CHAR
Call SendDataTo(Index, Packet)
End Sub
Lastly, if you want your players to be able to carry more weight when they use their stat points...
Go under [b]modHandleData/b] and in the “Use stats packet” add this code after the End Select:
Code:
Call SetPlayerMaxWeight(Index, 4 * (GetPlayerSTR(Index) + GetPlayerDEF(Index)))
Of course, change the formula to fit your needs.
I hope that you learned something from this because it took me awhile to put together all the code. And I ruined two source codes before getting it right ^_^ I will probably add in some comments later to explain what is happening. But, until then, figure it out. Any question just leave a message here. I will also attach the source code for a blank MSE1 build with this feature.
©2008 ~ This guide is my property.