07-01-2009, 12:52 AM
Ok, so this is just a bounty system I made for the hell of it. Keep in mind I did this, after pulling an all nighter, and was completely exhausted when I wrote most if it, so if you find a mistake, please let me know and don't hold it against me. This feature, will allow users to put hits out on other people, as soon as the hit is put out, the money is subtracted from their inventory. Anyone who kills the person with the price on their head, will receive the money. I also went as far as to include a command which brings up a list of people with bounties, and the price of the bounty on their head (was extremely easy)
Credit goes to: William for his TakeGold function, and then the rest of the credit goes to you of MS4, for always answering my questions and helping.
Without further adieu:
Server Side
[spoiler]Find:
Under it add:
Then find:
Under it add:
And now for the code for the list:
Find:
Under it add:
Then find:
Under it add:
Then find:
Under it add:
Then find:
Under it add:[/spoiler]
Client Side
[spoiler]Find:
Under it add:
Then find:
Under it add:
Then find:
Under it add:
Then find:
Under it add:
Then find:
Under it add:
Then find:
Under it add:[/spoiler]
This feature gives you two different commands:
/bounty (playername) (price of bounty)
/bounties (Displays the list of people with prices on their head, and how much)
Also it allows you to use two new functions: GetPlayerBounty, and SetPlayerBounty. Have fun.
Also, remember to read the code. After all, it will require one or two tweaks, such as replacing the 1's with the number slot that your currency is, etc, etc. That's where the 2/5 comes into play
Credit goes to: William for his TakeGold function, and then the rest of the credit goes to you of MS4, for always answering my questions and helping.

Without further adieu:
Server Side
[spoiler]Find:
Code:
Function HasItem(ByVal index As Long, ByVal ItemNum As Long) As Long
Dim i As Long
HasItem = 0
' Check for subscript out of range
If IsPlaying(index) = False Or ItemNum MAX_ITEMS Then
Exit Function
End If
For i = 1 To MAX_INV
' Check to see if the player has the item
If GetPlayerInvItemNum(index, i) = ItemNum Then
If Item(ItemNum).Type = ITEM_TYPE_CURRENCY Then
HasItem = GetPlayerInvItemValue(index, i)
Else
HasItem = 1
End If
Exit Function
End If
Next i
End Function
Under it add:
Code:
Function TakeGold(ByVal index As Long, ByVal ItemNum As Long, ByVal ItemVal As Long) As Boolean
Dim i As Long, N As Long
TakeGold = False
' Check for subscript out of range
If IsPlaying(index) = False Or ItemNum MAX_ITEMS Then
Exit Function
End If
For i = 1 To MAX_INV
' Check to see if the player has the item
If GetPlayerInvItemNum(index, i) = ItemNum Then
If Item(ItemNum).Type = ITEM_TYPE_CURRENCY Then
' Is what we are trying to take away more then what they have? If so just set it to zero
If ItemVal 0 Then
If GetPlayerAccess(N) 0 Then
If N index Then
If GetPlayerLevel(N) >= 10 Then
If GetPlayerBounty(N) = 0 Then
If TakeGold(index, 1, i) Then
Call GlobalMsg(GetPlayerName(index) & " has just had a " & i & " dollar bounty put on " & GetPlayerName(N) & "!", BrightBlue)
Call SetPlayerBounty(N, i)
Call SendPlayerData(N)
Call AddLog(GetPlayerName(index) & " has put a " & i & " bounty on " & GetPlayerName(N), ADMIN_LOG)
Else
Call PlayerMsg(index, "You don't have sufficient funds for this action!", BrightRed)
End If
Else
Call PlayerMsg(index, GetPlayerName(N) & " already has a price on their head!", BrightRed)
End If
Else
Call PlayerMsg(index, "Player must be level 10 or higher!", BrightRed)
End If
Else
Call PlayerMsg(index, "You cant set a hit out on yourself!", BrightRed)
End If
Else
Call PlayerMsg(index, "Player isn't online!", BrightRed)
End If
End Sub
Then find:
Code:
' Player is dead
Call GlobalMsg(GetPlayerName(Victim) & " has been killed by " & GetPlayerName(Attacker), BrightRed)
Under it add:
Code:
If GetPlayerBounty(Victim) > 0 Then
'Give the reward
Call GiveItem(Attacker, 1, GetPlayerBounty(Victim))
'Send the messages
Call PlayerMsg(Attacker, "You have received: " & GetPlayerBounty(Victim) & " dollars for killing " & GetPlayerName(Victim), BrightGreen)
Call GlobalMsg(GetPlayerName(Victim) & " has been slain by " & GetPlayerName(Attacker) & " and has collected the " & GetPlayerBounty(Victim) & " dollar bounty on his/her head", BrightGreen)
'Set the bounty to 0
Call SetPlayerBounty(Victim, 0)
End If
And now for the code for the list:
Find:
Code:
Case CWhosOnline
HandleWhosOnline index
Under it add:
Code:
Case CBountyList
HandleBountyList index
Then find:
Code:
' :::::::::::::::::::::::
' :: Who online packet ::
' :::::::::::::::::::::::
Sub HandleWhosOnline(ByVal index As Long)
Call SendWhosOnline(index)
End Sub
Under it add:
Code:
' ::::::::::::::::::::::::
' :: Bounty list packet ::
' ::::::::::::::::::::::::
Sub HandleBountyList(ByVal index As Long)
Call SendBountyList(index)
End Sub
Then find:
Code:
Sub SendWhosOnline(ByVal index As Long)
Dim s As String
Dim N As Long, i As Long
For i = 1 To MAX_PLAYERS
If IsPlaying(i) Then
If i index Then
s = s & GetPlayerName(i) & ", "
N = N + 1
End If
End If
Next i
If N = 0 Then
s = "There are no other players online."
Else
s = Mid$(s, 1, Len(s) - 2)
s = "There are " & N & " other players online: " & s & "."
End If
Call PlayerMsg(index, s, WhoColor)
End Sub
Under it add:
Code:
Sub SendBountyList(ByVal index As Long)
Dim s As String
Dim N As Long, i As Long
For i = 1 To MAX_PLAYERS
If IsPlaying(i) Then
If i index Then
If GetPlayerBounty(i) > 0 Then
s = s & GetPlayerName(i) & "(" & GetPlayerBounty(i) & ")" & ", "
N = N + 1
End If
End If
End If
Next i
If N = 0 Then
s = "No one has a bounty!"
Else
s = Mid$(s, 1, Len(s) - 2)
s = "There are " & N & " players with bounties: " & s & "."
End If
Call PlayerMsg(index, s, WhoColor)
End Sub
Then find:
Code:
CSetBounty
Under it add:
Code:
CBountyList
Client Side
[spoiler]Find:
Code:
CQuit
Under it add:
Code:
CSetBounty
Then find:
Code:
Case "/setaccess"
If GetPlayerAccess(MyIndex) < ADMIN_CREATOR Then
AddText "You need to be a high enough staff member to do this!", AlertColor
GoTo Continue
End If
If UBound(Command) < 2 Then
AddText "Usage: /setaccess (name) (access)", AlertColor
GoTo Continue
End If
If IsNumeric(Command(1)) = True Or IsNumeric(Command(2)) = False Then
AddText "Usage: /setaccess (name) (access)", AlertColor
GoTo Continue
End If
SendSetAccess Command(1), CLng(Command(2))
Case "/setlevel"
Under it add:
Code:
Case "/bounty"
If UBound(Command) < 2 Then
AddText "Usage: /bounty (name) (price)", AlertColor
GoTo Continue
End If
If IsNumeric(Command(1)) = True Or IsNumeric(Command(2)) = False Then
AddText "Usage: /setname (name) (price)", AlertColor
GoTo Continue
End If
SendSetBounty Command(1), (Command(2))
Case "/warn"
Then find:
Code:
Sub SendSetAccess(ByVal Name As String, ByVal Access As Byte)
Dim Packet As String
Packet = CSetAccess & SEP_CHAR & Name & SEP_CHAR & Access & END_CHAR
Call SendData(Packet)
End Sub
Under it add:
Code:
Sub SendSetBounty(ByVal Name As String, _
ByVal Bounty As Long)
Dim Packet As String
Packet = CSetBounty & SEP_CHAR & Name & SEP_CHAR & Bounty & END_CHAR
Call SendData(Packet)
End Sub
Then find:
Code:
Sub SendWhosOnline()
Dim Packet As String
Packet = CWhosOnline & END_CHAR
Call SendData(Packet)
End Sub
Under it add:
Code:
Sub SendBountyList()
Dim Packet As String
Packet = CBountyList & END_CHAR
Call SendData(Packet)
End Sub
Then find:
Code:
CSetBounty
Under it add:
Code:
CBountyList
Then find:
Code:
' Whos Online
Case "/who"
SendWhosOnline
Under it add:
Code:
' Bounty List
Case "/bounties"
SendBountyList
This feature gives you two different commands:
/bounty (playername) (price of bounty)
/bounties (Displays the list of people with prices on their head, and how much)
Also it allows you to use two new functions: GetPlayerBounty, and SetPlayerBounty. Have fun.
Also, remember to read the code. After all, it will require one or two tweaks, such as replacing the 1's with the number slot that your currency is, etc, etc. That's where the 2/5 comes into play
