25-07-2008, 01:30 PM
-Server-
modTypes:
modGameLogic:
Add to Sub PlayerUseKey:
Find:Call SavePlayer(index) in: Sub LeftGame.
Add under:
modGameLogic:
Add to InitServer:
Find: Call SavePlayer(i) in: PlayerSaveTimer
add:
modServerTCP:
modConstants:
modGlobals:
Sub HandleData:
Find: LoadPlayer in: Login packet
add:
Find: SavePlayer in: AddChar packet
add:
Add at bottom:
[code]' :::::::::::::::::::::
' :: bank item packet ::
' :::::::::::::::::::::
If LCase(Parse(0)) = "bankitem" Then
InvNum = Val(Parse(1))
CharNum = Player(index).CharNum
' Prevent hacking
If InvNum < 1 Or InvNum > MAX_INV Then
Call HackingAttempt(index, "Invalid InvNum")
Exit Sub
End If
' Prevent hacking
If CharNum < 1 Or CharNum > MAX_CHARS Then
Call HackingAttempt(index, "Invalid CharNum")
Exit Sub
End If
If (GetPlayerInvItemNum(index, InvNum) > 0) And (GetPlayerInvItemNum(index, InvNum) MAX_CHARS Then
Call HackingAttempt(index, "Invalid CharNum")
Exit Sub
End If
If (GetPlayerbankItemNum(index, BankNum) > 0) And (GetPlayerbankItemNum(index, BankNum)
modTypes:
Code:
Type BankRec
Item(1 To MAX_BANK_SLOTS) As PlayerInvRec
End TypemodGameLogic:
Code:
Function FindOpenBankSlot(ByVal index As Long, ByVal ItemNum As Long) As Long
Dim i As Long
FindOpenBankSlot = 0
' Check for subscript out of range
If IsPlaying(index) = False Or ItemNum MAX_ITEMS Then
Exit Function
End If
If Item(ItemNum).Type = ITEM_TYPE_CURRENCY Then
' If currency then check to see if they already have an instance of the item and add it to that
For i = 1 To MAX_BANK_SLOTS
If GetPlayerbankItemNum(index, i) = ItemNum Then
FindOpenBankSlot = i
Exit Function
End If
Next i
End If
For i = 1 To MAX_BANK_SLOTS
' Try to find an open free slot
If GetPlayerbankItemNum(index, i) = 0 Then
FindOpenBankSlot = i
Exit Function
End If
Next i
End FunctionCode:
Sub TakeBank(ByVal index As Long, _
ByVal ItemNum As Long, _
ByVal ItemVal As Long, _
ByVal BankNum As Long)
Dim i As Long
' Check for subscript out of range
If IsPlaying(index) = False Or ItemNum MAX_ITEMS Then
Exit Sub
End If
i = FindOpenInvSlot(index, ItemNum)
' Check to see if inventory is full
If i 0 Then
Call GiveItem(index, Bank(index).Item(BankNum).Num, 0)
Call SetPlayerbankItemNum(index, BankNum, 0)
Call SetPlayerbankItemValue(index, BankNum, 0)
Call SetPlayerbankItemDur(index, BankNum, 0)
Call SendInventoryUpdate(index, i)
Call SendBankUpdate(index, BankNum)
Else
Call PlayerMsg(index, "Your inventory is full.", BrightRed)
End If
End SubCode:
Sub GiveBank(ByVal index As Long, ByVal ItemNum As Long, ByVal ItemVal As Long)
Dim i As Long
' Check for subscript out of range
If IsPlaying(index) = False Or ItemNum MAX_ITEMS Then
Exit Sub
End If
i = FindOpenBankSlot(index, ItemNum)
' Check to see if bank is full
If i 0 Then
Call SetPlayerbankItemNum(index, i, ItemNum)
Call SetPlayerbankItemValue(index, i, GetPlayerbankItemValue(index, i) + ItemVal)
If (Item(ItemNum).Type = ITEM_TYPE_ARMOR) Or (Item(ItemNum).Type = ITEM_TYPE_WEAPON) Or (Item(ItemNum).Type = ITEM_TYPE_HELMET) Or (Item(ItemNum).Type = ITEM_TYPE_SHIELD) Then
Call SetPlayerbankItemDur(index, i, Item(ItemNum).Data1)
End If
'Call SendInventoryUpdate(index, i)
Call SendBankUpdate(index, i)
Else
Call PlayerMsg(index, "Your bank is full.", BrightRed)
End If
End SubAdd to Sub PlayerUseKey:
Code:
' bank check
If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).Type = TILE_TYPE_BANK Then
Call SendPlayerBank(index)
Exit Sub
End IfFind:Call SavePlayer(index) in: Sub LeftGame.
Add under:
Code:
Call SaveBank(index)modGameLogic:
Code:
Sub ClearBank(ByVal index As Long)
Dim i As Byte
For i = 1 To MAX_BANK_SLOTS
Bank(index).Item(i).Num = 0
Bank(index).Item(i).Dur = 0
Bank(index).Item(i).Value = 0
Next
End SubCode:
Sub Clearbanks()
Dim i As Long
For i = 1 To MAX_PLAYERS
Call ClearBank(i)
Next i
End SubCode:
Function GetPlayerbankItemNum(ByVal index As Long, ByVal bankSlot As Long) As Long
GetPlayerbankItemNum = Bank(index).Item(bankSlot).Num
End Function
Sub SetPlayerbankItemNum(ByVal index As Long, _
ByVal bankSlot As Long, _
ByVal ItemNum As Long)
Bank(index).Item(bankSlot).Num = ItemNum
End Sub
Function GetPlayerbankItemValue(ByVal index As Long, ByVal bankSlot As Long) As Long
GetPlayerbankItemValue = Bank(index).Item(bankSlot).Value
End Function
Sub SetPlayerbankItemValue(ByVal index As Long, _
ByVal bankSlot As Long, _
ByVal ItemValue As Long)
Bank(index).Item(bankSlot).Value = ItemValue
End Sub
Function GetPlayerbankItemDur(ByVal index As Long, ByVal bankSlot As Long) As Long
GetPlayerbankItemDur = Bank(index).Item(bankSlot).Dur
End Function
Sub SetPlayerbankItemDur(ByVal index As Long, _
ByVal bankSlot As Long, _
ByVal ItemDur As Long)
Bank(index).Item(bankSlot).Dur = ItemDur
End SubAdd to InitServer:
Code:
Call SetStatus("Clearing banks...")
Call ClearbanksFind: Call SavePlayer(i) in: PlayerSaveTimer
add:
Code:
Call SaveBank(i)modServerTCP:
Code:
Sub SendBankUpdate(ByVal index As Long, ByVal InvSlot As Long)
Dim Packet As String
Packet = "PLAYERBANKUPDATE" & SEP_CHAR & InvSlot & SEP_CHAR & GetPlayerbankItemNum(index, InvSlot) & SEP_CHAR & GetPlayerbankItemValue(index, InvSlot) & SEP_CHAR & GetPlayerbankItemDur(index, InvSlot) & SEP_CHAR & END_CHAR
Call SendDataTo(index, Packet)
End SubCode:
Sub SendPlayerBank(ByVal index As Long)
Dim Packet As String
Dim i As Long
Packet = "bank" & SEP_CHAR
For i = 1 To MAX_BANK_SLOTS
Packet = Packet & Bank(index).Item(i).Num & SEP_CHAR
Packet = Packet & Bank(index).Item(i).Value & SEP_CHAR
Packet = Packet & Bank(index).Item(i).Dur & SEP_CHAR
Next
Packet = Packet & END_CHAR
Call SendDataTo(index, Packet)
End SubmodConstants:
Code:
Public Const MAX_BANK_SLOTS = 50Code:
Public Const TILE_TYPE_BANK = 12modGlobals:
Code:
Public Bank(1 To MAX_PLAYERS) As BankRecSub HandleData:
Code:
Dim BankNum As LongFind: LoadPlayer in: Login packet
add:
Code:
Call LoadBank(index, Name)Find: SavePlayer in: AddChar packet
add:
Code:
Call SaveBank(index)Add at bottom:
[code]' :::::::::::::::::::::
' :: bank item packet ::
' :::::::::::::::::::::
If LCase(Parse(0)) = "bankitem" Then
InvNum = Val(Parse(1))
CharNum = Player(index).CharNum
' Prevent hacking
If InvNum < 1 Or InvNum > MAX_INV Then
Call HackingAttempt(index, "Invalid InvNum")
Exit Sub
End If
' Prevent hacking
If CharNum < 1 Or CharNum > MAX_CHARS Then
Call HackingAttempt(index, "Invalid CharNum")
Exit Sub
End If
If (GetPlayerInvItemNum(index, InvNum) > 0) And (GetPlayerInvItemNum(index, InvNum) MAX_CHARS Then
Call HackingAttempt(index, "Invalid CharNum")
Exit Sub
End If
If (GetPlayerbankItemNum(index, BankNum) > 0) And (GetPlayerbankItemNum(index, BankNum)
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?


