Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bounty System (2/5) C & P
#1
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. Smile


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
[/spoiler]

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
[/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 Wink
Reply
#2
I once worked on a bounty system.

And then I reformatted my computer.

And then I stopped coding.
Reply
#3
this looks very interesting =]. thanks. this could help with making a law system. where if your in an npc range and you steal or something bad you get a bounty put on your head =].
Reply
#4
Nice work Nean. I haven't tested it, but it seems like a solid tutorial. I might even use it if I ever get around to reinstalling Visual Studio Tongue
Reply
#5
@Rory: I know the feeling, I've had to reinstall VB6 multiple times, it's a pain.

@Genusis: Tell me how that works out dude, sounds awesome.

@Rian: Sweet, if/when you do so, tell me how it works for you, I have it full implemented and I haven't found any problems, so I hope it's the same for you. Smile
Reply
#6
well for the law system all you do is set the npc to have a tile range to where they can see. then you code in a new frm where you can set stuff like the skill theifing or something you want to be considered breaking a rule.

then once you set that you then make a npc that is a guard npc

ok for example

the rule attacking players in town. place guard npc there and if the code attack player is called send another code doing a search to see if npcs are close enough if not nothing happens to them if so they set a bounty and guard npcs will start to attack them. and if players like kill a bounties player out of the npcs range they get the bounty
Reply
#7
It might also be a good idea to set another variable in the bounty system, to check to see if the bounty was player created, or created by the guards, and if it was created by the guards and the guard kills the player, the bounty goes away.
Reply
#8
to me i think a player shouldn't be able to set a bounty on another player unless that player breaks a rule in the game. to make it more fair for the other players, because then there probably be bounties on everyone if they where allowed to freely do that.
Reply
#9
genusis Wrote:to me i think a player shouldn't be able to set a bounty on another player unless that player breaks a rule in the game. to make it more fair for the other players, because then there probably be bounties on everyone if they where allowed to freely do that.

Take this into consideration. A lower level player is going around farming, chilling, generally having a good time. Bam. A higher level comes out of nowhere, and pwns the shit out of them. Tough luck, doubtful any higher level will have any incentive to go kill them as revenge for the other player. With the bounty system implemented, this n00b can exact his/her revenge by using money as the incentive for the more bored players.
Reply
#10
I haven't read the code so this may be an uninformed comment, but I think a nice implementation of this idea would be to restrict the ability to place bounties.

The way I would do it, is allow people to place bounties if the person has killed them, or has killed someone in their guild who is the same rank or lower. Also, perhaps a new npc type that brings up a noticeboard of all current bounties would be a nice expansion.

Oh, I'm not requesting this btw, just pooling my thoughts :3
Reply
#11
A good idea would be to only be able to put a bounty as high as you can offer. So if you only have 12gold you can only put a 12gold bounty on the player. Allowing normal players to put bounty on other player's heads. Once they use the command, their money is automatically deducted.
Reply
#12
Fox Wrote:I haven't read the code so this may be an uninformed comment, but I think a nice implementation of this idea would be to restrict the ability to place bounties.

The way I would do it, is allow people to place bounties if the person has killed them, or has killed someone in their guild who is the same rank or lower. Also, perhaps a new npc type that brings up a noticeboard of all current bounties would be a nice expansion.

Oh, I'm not requesting this btw, just pooling my thoughts :3

That's a great idea, however would be a little difficult to do. I suppose I could just make a variable when someone kills another person, or something. Yeah, I like the idea of the noticeboard, I don't think it would be too difficult to add either. Thanks for the suggestions, I think I'll try some of them out!

Rory Wrote:A good idea would be to only be able to put a bounty as high as you can offer. So if you only have 12gold you can only put a 12gold bounty on the player. Allowing normal players to put bounty on other player's heads. Once they use the command, their money is automatically deducted.

As it stands now, they can only set a bounty if they have the right money, but I like your idea. However instead of taking all of their money, I was thinking of calculating the price based on the players level. Big Grin
Reply
#13
I like that idea, having it calculated based on the players level, but I think it would be fun to make that a minimum. Also it would be interesing to add in 2 more commands, a cancel bounty command (get your gold back minus a certain percent I.e. bounty of 100 gold, you cancel get 90 back). And an add on to bounty command, so that if no one wants to kill that person for that money, you can increase it to create a better incentive, or someone else can add their money to the bounty to create more of an incentive.
Reply
#14
OMG! Thank you! Very nice tut!
Reply
#15
Well, I tried it out and GetPlayerBounty is int defined.
Reply
#16
timster0 Wrote:Well, I tried it out and GetPlayerBounty is int defined.

Find:
Code:
Sub SetPlayerName(ByVal index As Long, _
                  ByVal Name As String)
    Player(index).Char(TempPlayer(index).CharNum).Name = Name
End Sub

Under it add:
Code:
Function GetPlayerBounty(ByVal index As Long) As String
    GetPlayerBounty = Val(Player(index).Char(TempPlayer(index).CharNum).Bounty)
End Function

Sub SetPlayerBounty(ByVal index As Long, _
                    ByVal Bounty As Long)
    Player(index).Char(TempPlayer(index).CharNum).Bounty = Bounty
End Sub
Reply
#17
Works perfectly now, thanks.
Reply
#18
timster0 Wrote:Works perfectly now, thanks.

You're welcome. Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)