[ALL VERSIONS] Bounty System

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

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 :)

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 :)

Now add this at bottom of modHandleData:


' 



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

' 



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

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.

Thanx for tut ;]

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

Good work!

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. I did this in rush, but ok i will add it.

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

Search the entire project then.

In server I get error in modHandleData;

Call SendBountyList(index)

not defined

this acutaly looks useful. XD nice

Nice, Player Killers will suffer like hell for their transgressions with a bunch of greedy bastards looking to make a quick sack of gold off their heads XD.

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

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

After fixing that error

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

I reapeated and fixed this error

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

Now I got this error

If Item(ItemNum).Type = ItemCurrency Then

Varriable not defined

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

attacker variable not defined

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

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)

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

And everything in tutorial is now fixed (thx to Deathly for reporting bugs :) )

System without errors?

Strongly slows down the server?

System without errors?

Strongly slows down the server?

1. Yes

2. Not at all :)

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

Log in to reply