Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[ALL VERSIONS] Bounty System


tslusny
 Share

Recommended Posts

**For Miracle Classic users**: Use this tutorial instead, it is optimized to work with MC - http://eatenbrain.com/forums/showthread.php?tid=16&pid=38#pid38

Now search for this in modCombat:This tut was originally for Mirage Source 4, but i converted it to work with Eclipse and engines based on it (Miracle Classic, Eclipse Reborn).

Here is link to original tutorial: [http://web.miragesou…hp?f=183&t=4961](http://web.miragesource.net/forums/viewtopic.php?f=183&t=4961)

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.

So… Let´s begin ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png)

**Client side:**

Search for in modEnumerations:

```

CMSG_COUNT

```

And add this ABOVE:

```

CSetBounty

CBountyList

```

Then search for this in modInput:

```

Case "/help"

Call AddText("Social Commands:", HelpColor)

Call AddText("'msghere = Broadcast Message", HelpColor)

Call AddText("-msghere = Emote Message", HelpColor)

Call AddText("!namehere msghere = Player Message", HelpColor)

Call AddText("Available Commands: /stats, /who, /fps, /fpslock, /emotes", HelpColor)

```

And add this under it:

```

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 "/bounties"

SendBountyList

```

Now add this 2 subs at bottom of modCientTCP:

```

Public Sub SendBountyList()

Dim buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo ErrorHandler

Set buffer = New clsBuffer

buffer.WriteLong CBountyList

SendData buffer.ToArray()

Set buffer = Nothing

' Error handler

Exit Sub

ErrorHandler:

HandleError "SendBountyList", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

Public Sub SendSetBounty(ByVal Name As String, ByVal Bounty As Long)

Dim buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo ErrorHandler

Set buffer = New clsBuffer

buffer.WriteLong CSetBounty

buffer.WriteString Name

buffer.WriteLong Bounty

SendData buffer.ToArray()

Set buffer = Nothing

' Error handler

Exit Sub

ErrorHandler:

HandleError "SendSetBounty", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

**Server side:**

Search for in modEnumerations:

```

CMSG_COUNT

```

And add this ABOVE:

```

CSetBounty

CBountyList

```

Now add this at bottom of Sub InitMessages in modHandleData:

```

HandleDataSub(CSetBounty) = GetAddress(AddressOf HandleSetBounty)

HandleDataSub(CBountyList) = GetAddress(AddressOf HandleBountyList)

```

Almost done ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png)

Now add this at bottom of modHandleData:

```

' :::::::::::::::::::::::

' :: Set access packet ::

' :::::::::::::::::::::::

Sub HandleSetBounty(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

Dim N As Long

Dim i As Long

Dim buffer As clsBuffer

On Error GoTo ErrorHandler

Set buffer = New clsBuffer

buffer.WriteBytes Data()

' The index

N = FindPlayer(buffer.ReadString) 'Parse(1))

' The access

i = buffer.ReadLong 'CLng(Parse(2))

Set buffer = Nothing

' Check if player is on

If 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

' Error handler

Exit Sub

ErrorHandler:

HandleError "HandleSetAccess", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

' :::::::::::::::::::::::

' :: Who online packet ::

' :::::::::::::::::::::::

Sub HandleBountyList(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

On Error GoTo ErrorHandler

Call SendBountyList(index)

' Error handler

Exit Sub

ErrorHandler:

HandleError "HandleWhosOnline", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

Now add this to bottom of Type PlayerRec in modTypes (or Type CharRec if you are using Miracle Classic with multiple chars per account)

```

Bounty As Long

```

Now add this at bottom of modPlayer:

```

Function GetPlayerBounty(ByVal index As Long) As Long

On Error GoTo ErrorHandler

If index > MAX_PLAYERS Then Exit Function

GetPlayerBounty = Player(index).Bounty

' Error handler

Exit Function

ErrorHandler:

HandleError "GetPlayerPK", "modPlayer", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Function

End Function

Sub SetPlayerBounty(ByVal index As Long, ByVal Bounty As Long)

On Error GoTo ErrorHandler

Player(index).Bounty = Bounty

' Error handler

Exit Sub

ErrorHandler:

HandleError "SetPlayerPK", "modPlayer", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

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 <= 0 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 <= GetPlayerInvItemValue(index, i) Then

Call SetPlayerInvItemValue(index, i, GetPlayerInvItemValue(index, i) - ItemVal)

Call SendInventoryUpdate(index, i)

TakeGold = True

Exit Function

End If

End If

End If

Next i

End Function

```

Now add this to bottom of modServerTCP:

```

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)

' Error handler

Exit Sub

ErrorHandler:

HandleError "SendBountyList", "modServerTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub
```

Now search for this in modCombat:

```

' Player is dead

Call GlobalMsg(GetPlayerName(victim) & " has been killed by " & GetPlayerName(attacker), BrightRed)

```

IN! Sub PlayerAttackPlayer (there is similar thing in NPCAttackPlayer so..)

And add this under it:

```

If GetPlayerBounty(victim) > 0 Then

'Give the reward

Call GiveInvItem(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

```
Link to comment
Share on other sites

Looks pretty legit, and not too long. Good job, your pretty efficient as far as coding goes. The system seems to work nice. I'll test it later when my VB6 is available.
Link to comment
Share on other sites

> When you say "Search for:" you don't tell us which module your telling us to search in. Can you please say each module where you search in. Even tho i'm guessing it's in modEnum

Yea, it is in modEnums.

I do not added to search in what module, becouse you can just search entire project with CTRL+F ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png). I did this in rush, but ok i will add it.
Link to comment
Share on other sites

> In server I get error in modHandleData;
>
> Call SendBountyList(index)
>
> not defined

Yea, i forgot add that sub to tut. Updated.

Here is that sub (add it to bottom of modServerTCP)

```

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)

' Error handler

Exit Sub

ErrorHandler:

HandleError "SendBountyList", "modServerTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```
Link to comment
Share on other sites

Now I get this error.

```
Function GetPlayerBounty(ByVal index As Long) As Long

On Error GoTo ErrorHandler

If index > MAX_PLAYERS Or TempPlayer(index).CurChar = 0 Then Exit Function

GetPlayerBounty = Player(index).Char(TempPlayer(index).CurChar).Bounty

' Error handler

Exit Function

ErrorHandler:

HandleError "GetPlayerPK", "modPlayer", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Function

End Function
```

Highlighting on this line

```
If index > MAX_PLAYERS Or TempPlayer(index).CurChar = 0 Then Exit Function
```

Only the

```
.CurChar
```

Part
Link to comment
Share on other sites

```
If GetPlayerBounty(victim) > 0 Then

'Give the reward

Call GiveInvItem(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
```

```
Call GiveInvItem(attacker, 1, GetPlayerBounty(victim))
```

attacker variable not defined
Link to comment
Share on other sites

> If i understand that corrects does it set an price of you for killing you ?
>
> So if i would type /bounty MortalAngels 1000
>
> Would the one which kill me get 1000 ?
>
> I cant test it so i ask xD (Not at home)

Yea, put you can´t set bounty on yourself ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png)

And everything in tutorial is now fixed (thx to Deathly for reporting bugs ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) )
Link to comment
Share on other sites

> Could you make so it if you kill some1 that has a bounty on them you don't become a player killer?

But…. When you kill player, you ARE player killer ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png) ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png)
Link to comment
Share on other sites

> ```
> If GetPlayerBounty(victim) > 0 Then
>
> 'Give the reward
>
> Call GiveInvItem(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
> ```
>
> ```
> Call GiveInvItem(attacker, 1, GetPlayerBounty(victim))
> ```
>
> attacker variable not defined

Still not defined…
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...